Spaces:
Runtime error
Runtime error
| import json | |
| import os | |
| from fastapi import FastAPI, HTTPException | |
| from fastapi.responses import HTMLResponse, JSONResponse | |
| from pydantic import BaseModel | |
| from typing import Dict, Any, Optional | |
| from tech_radar.mcp.tools import ( | |
| get_db_and_vector_store, | |
| tool_search_tech_jobs, | |
| tool_analyze_skill_gap, | |
| tool_generate_resume_patch, | |
| tool_get_market_insights, | |
| tool_generate_interview_prep_kit | |
| ) | |
| app = FastAPI(title="TechRadar MCP Web Server") | |
| class McpRequest(BaseModel): | |
| tool: str | |
| args: Dict[str, Any] | |
| def get_web_app(): | |
| html_path = os.path.join(os.path.dirname(__file__), "web_app.html") | |
| if not os.path.exists(html_path): | |
| raise HTTPException(status_code=404, detail="web_app.html not found") | |
| with open(html_path, "r", encoding="utf-8") as f: | |
| return f.read() | |
| def get_jobs(domain: Optional[str] = None, city: Optional[str] = None): | |
| db, _, _, _ = get_db_and_vector_store() | |
| jobs = [j.dict() for j in db.search_jobs(domain=domain, city=city, limit=200)] | |
| return {"count": len(jobs), "jobs": jobs} | |
| def get_insights(city: str = "All", domain: str = "All"): | |
| _, _, _, analyst = get_db_and_vector_store() | |
| report = analyst.generate_market_report(city=city, domain=domain) | |
| return report.dict() | |
| def execute_mcp_tool(req: McpRequest): | |
| tool_name = req.tool | |
| args = req.args | |
| if tool_name == "search_tech_jobs": | |
| res = tool_search_tech_jobs( | |
| domain=args.get("domain", "All"), | |
| city=args.get("city", "All"), | |
| query=args.get("query") | |
| ) | |
| elif tool_name == "analyze_skill_gap": | |
| res = tool_analyze_skill_gap( | |
| resume_text=args.get("resume_text", ""), | |
| target_job_id=args.get("target_job_id", "") | |
| ) | |
| elif tool_name == "generate_tailored_resume_patch": | |
| res = tool_generate_resume_patch( | |
| resume_text=args.get("resume_text", ""), | |
| target_job_id=args.get("target_job_id", "") | |
| ) | |
| elif tool_name == "get_market_insights": | |
| res = tool_get_market_insights( | |
| domain=args.get("domain", "All"), | |
| city=args.get("city", "All") | |
| ) | |
| elif tool_name == "generate_interview_prep_kit": | |
| res = tool_generate_interview_prep_kit( | |
| target_job_id=args.get("target_job_id", "") | |
| ) | |
| else: | |
| raise HTTPException(status_code=400, detail=f"Unknown tool: {tool_name}") | |
| return {"status": "success", "tool": tool_name, "result": res} | |