Brettapps commited on
Commit
fe893f9
·
verified ·
1 Parent(s): e47861c

Upload folder using huggingface_hub

Browse files
Files changed (8) hide show
  1. Dockerfile +10 -0
  2. README.md +17 -5
  3. __init__.py +0 -0
  4. openai_module.py +21 -0
  5. pyproject.toml +19 -0
  6. server.py +54 -0
  7. tech_kb.py +56 -0
  8. tools.py +63 -0
Dockerfile ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY pyproject.toml .
6
+ RUN pip install .
7
+
8
+ COPY . .
9
+
10
+ CMD ["python", "server.py"]
README.md CHANGED
@@ -1,10 +1,22 @@
1
  ---
2
- title: Tech Wizard Mcp
3
- emoji: 📚
4
- colorFrom: red
5
- colorTo: yellow
6
  sdk: docker
7
  pinned: false
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Tech-Wizard-MCP
3
+ emoji: 🧙‍♂️
4
+ colorFrom: blue
5
+ colorTo: gray
6
  sdk: docker
7
  pinned: false
8
+ app_port: 8000
9
  ---
10
 
11
+ # Tech Wizard MCP Server
12
+
13
+ This is the comprehensive 'Tech Wizard' agent, capable of acting as a Software Architect, Senior Engineer, API/Webhooks Specialist, and App Builder.
14
+
15
+ ## Features
16
+ - **System Architecture**: High-level designs and Mermaid diagrams.
17
+ - **API/Webhook Design**: Secure, idiomatic, and reliable patterns.
18
+ - **DNS & Routing**: Strategic domain and SSL orchestration.
19
+ - **Grand Tech Wizard AI**: Powered by OpenAI gpt-4o.
20
+
21
+ ## Deployment
22
+ This Space is configured to run the MCP server.
__init__.py ADDED
File without changes
openai_module.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from openai import OpenAI
3
+ from typing import Optional
4
+
5
+ class OpenAIClient:
6
+ def __init__(self, api_key: Optional[str] = None):
7
+ self.client = OpenAI(api_key=api_key or os.getenv("OPENAI_API_KEY"))
8
+ self.default_model = "gpt-4o"
9
+
10
+ def chat(self, prompt: str, system_instruction: str = "You are the 'Grand Tech Wizard'. You are a master Software Architect, Senior Engineer, API/Webhooks Specialist, and App Builder. You design scalable, secure, and idiomatic technical systems.", model: Optional[str] = None) -> str:
11
+ try:
12
+ response = self.client.chat.completions.create(
13
+ model=model or self.default_model,
14
+ messages=[
15
+ {"role": "system", "content": system_instruction},
16
+ {"role": "user", "content": prompt}
17
+ ]
18
+ )
19
+ return response.choices[0].message.content
20
+ except Exception as e:
21
+ return f"Error calling OpenAI API: {str(e)}"
pyproject.toml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "tech-wizard"
3
+ version = "0.1.0"
4
+ description = "Comprehensive Tech Wizard MCP Server (Architect, Engineer, API, Webhooks, Domains, App Builder)"
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ dependencies = [
8
+ "mcp[cli]>=1.21.2",
9
+ "openai>=1.0.0",
10
+ "python-dotenv>=1.0.0",
11
+ "pydantic>=2.0.0",
12
+ ]
13
+
14
+ [build-system]
15
+ requires = ["setuptools>=61.0"]
16
+ build-backend = "setuptools.build_meta"
17
+
18
+ [project.scripts]
19
+ tech-wizard = "tech_wizard.server:main"
server.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+ from tech_wizard.tools import TechWizardTools
3
+ import os
4
+ from dotenv import load_dotenv
5
+
6
+ # Load environment variables
7
+ load_dotenv()
8
+
9
+ # Initialize FastMCP
10
+ mcp = FastMCP("Tech-Wizard")
11
+
12
+ # Initialize Tools
13
+ tech_tools = TechWizardTools()
14
+
15
+ @mcp.tool()
16
+ def architect_system(requirements: str) -> str:
17
+ """
18
+ Design a technical architecture plan (Mermaid diagram, stack, patterns).
19
+ """
20
+ return tech_tools.architect_system(requirements)
21
+
22
+ @mcp.tool()
23
+ def design_api(features: str) -> str:
24
+ """
25
+ Design a comprehensive API surface (endpoints, schemas, security).
26
+ """
27
+ return tech_tools.design_api(features)
28
+
29
+ @mcp.tool()
30
+ def setup_webhooks(source_platform: str) -> str:
31
+ """
32
+ Generate secure and reliable webhook handler code.
33
+ """
34
+ return tech_tools.setup_webhooks(source_platform)
35
+
36
+ @mcp.tool()
37
+ def configure_dns_routing(domain: str, app_details: str) -> str:
38
+ """
39
+ Get a DNS configuration and SSL/TLS routing plan.
40
+ """
41
+ return tech_tools.configure_routing(domain, app_details)
42
+
43
+ @mcp.tool()
44
+ def engineering_consultant(query: str) -> str:
45
+ """
46
+ Consult the Grand Tech Wizard for high-level engineering advice.
47
+ """
48
+ return tech_tools.llm.chat(query)
49
+
50
+ def main():
51
+ mcp.run()
52
+
53
+ if __name__ == "__main__":
54
+ main()
tech_kb.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, Any, List
2
+
3
+ class TechKnowledgeBase:
4
+ def __init__(self):
5
+ self.architect_patterns = {
6
+ "microservices": "Decoupled services communicating via API/Events. Pros: Scalability. Cons: Complexity.",
7
+ "serverless": "Event-driven, scale-to-zero logic. Best for intermittent workloads.",
8
+ "layered_architecture": "Separation of concerns (UI, Domain, Data). Standard for enterprise apps."
9
+ }
10
+
11
+ self.api_best_practices = {
12
+ "versioning": "Use URL versioning (e.g., /v1/) or Header versioning.",
13
+ "security": "Implement OAuth2/OIDC. Use rate limiting and input validation.",
14
+ "documentation": "OAS3 (Swagger) is the industry standard for REST APIs."
15
+ }
16
+
17
+ self.webhook_wizardry = {
18
+ "security": "Verify signatures using HMAC SHA256. Use secret rotation.",
19
+ "reliability": "Implement exponential backoff retries. Use an idempotency key to prevent double processing.",
20
+ "payloads": "Keep payloads small; use 'thin' webhooks that prompt a GET request for full data."
21
+ }
22
+
23
+ self.domain_routing = {
24
+ "dns_types": {
25
+ "A": "Points domain to IPv4.",
26
+ "CNAME": "Alias for another domain (good for CDNs/PaaS).",
27
+ "TXT": "Used for SPF/DKIM/DMARC and site verification.",
28
+ "MX": "Mail Exchange records."
29
+ },
30
+ "ssl_tls": "Always use Let's Encrypt for automated certificates. Force HTTPS redirection."
31
+ }
32
+
33
+ self.app_builder_templates = {
34
+ "fastapi_mcp": "Python-based high performance API with built-in MCP support.",
35
+ "nextjs_tailwind": "Modern React frontend with utility-first CSS and server-side rendering.",
36
+ "docker_slim": "Multi-stage builds to keep image size small and secure."
37
+ }
38
+
39
+ def get_info(self, module: str) -> Dict[str, Any]:
40
+ data = {
41
+ "architecture": self.architect_patterns,
42
+ "api": self.api_best_practices,
43
+ "webhooks": self.webhook_wizardry,
44
+ "domains": self.domain_routing,
45
+ "apps": self.app_builder_templates
46
+ }
47
+ return data.get(module, {"error": "Module knowledge not found."})
48
+
49
+ def get_all(self) -> Dict[str, Any]:
50
+ return {
51
+ "architecture": self.architect_patterns,
52
+ "api": self.api_best_practices,
53
+ "webhooks": self.webhook_wizardry,
54
+ "domains": self.domain_routing,
55
+ "apps": self.app_builder_templates
56
+ }
tools.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from tech_wizard.tech_kb import TechKnowledgeBase
2
+ from tech_wizard.openai_module import OpenAIClient
3
+ import os
4
+ import json
5
+
6
+ class TechWizardTools:
7
+ def __init__(self, openai_api_key=None):
8
+ self.kb = TechKnowledgeBase()
9
+ self.llm = OpenAIClient(api_key=openai_api_key or os.getenv("OPENAI_API_KEY"))
10
+
11
+ def architect_system(self, requirements: str) -> str:
12
+ """Design a technical system architecture."""
13
+ kb_context = self.kb.get_info("architecture")
14
+ prompt = f"""
15
+ Requirements: {requirements}
16
+ Architecture Patterns Knowledge: {json.dumps(kb_context, indent=2)}
17
+
18
+ Please design a technical architecture. Include:
19
+ 1. Recommended Pattern (e.g., Microservices vs Monolith).
20
+ 2. Technology Stack (Frontend, Backend, DB, Cache).
21
+ 3. A Mermaid.js diagram representing the system.
22
+ 4. Scalability and Security considerations.
23
+ """
24
+ return self.llm.chat(prompt)
25
+
26
+ def design_api(self, features: str) -> str:
27
+ """Design a secure and versioned API surface."""
28
+ kb_context = self.kb.get_info("api")
29
+ prompt = f"""
30
+ Feature Requirements: {features}
31
+ API Best Practices: {json.dumps(kb_context, indent=2)}
32
+
33
+ Design a REST or GraphQL API surface. Include:
34
+ 1. Endpoint paths and methods.
35
+ 2. Request/Response schemas (JSON).
36
+ 3. Authentication/Authorization strategy.
37
+ 4. Error handling logic.
38
+ """
39
+ return self.llm.chat(prompt)
40
+
41
+ def setup_webhooks(self, source_platform: str) -> str:
42
+ """Generate secure webhook handler logic."""
43
+ kb_context = self.kb.get_info("webhooks")
44
+ prompt = f"""
45
+ Source Platform (e.g., Stripe, GitHub, Shopify): {source_platform}
46
+ Webhook Knowledge: {json.dumps(kb_context, indent=2)}
47
+
48
+ Generate a secure webhook handler (Python/FastAPI or Node.js).
49
+ Must include signature verification, idempotency, and asynchronous processing.
50
+ """
51
+ return self.llm.chat(prompt)
52
+
53
+ def configure_routing(self, domain: str, app_details: str) -> str:
54
+ """Design DNS and routing configuration."""
55
+ kb_context = self.kb.get_info("domains")
56
+ prompt = f"""
57
+ Domain: {domain}
58
+ App/Infrastructure Details: {app_details}
59
+ Routing Knowledge: {json.dumps(kb_context, indent=2)}
60
+
61
+ Provide a DNS configuration plan (A, CNAME, TXT records) and SSL/TLS strategy.
62
+ """
63
+ return self.llm.chat(prompt)