return {"jsonrpc": "2.0", "result": "pong", "id": req_id} # JSON-RPC Tool Discovery if method in ("tools/list", "mcp.list_tools"): return { "jsonrpc": "2.0", "result": { "tools": [ {"name": "generate_api", "description": "Generate backend API endpoints"}, {"name": "modify_code", "description": "Modify code files in workspace"}, {"name": "backend_run_tests", "description": "Run pytest test suite"} ] }, "id": req_id } # JSON-RPC Tool Execution if method == "tools/call": tool_name = params.get("name") args = params.get("arguments", {}) if tool_name == "generate_api": return { "jsonrpc": "2.0", "result": { "status": "success", "content": [{"type": "text", "text": "API code generated successfully"}] }, "id": req_id } elif tool_name == "modify_code": filepath = args.get("filepath") search_text = args.get("search_text") replace_text = args.get("replace_text") if filepath and search_text and replace_text: builder.apply_patch(filepath, search_text, replace_text) return { "jsonrpc": "2.0", "result": { "status": "success", "content": [{"type": "text", "text": "Code modified successfully"}] }, "id": req_id } elif tool_name == "backend_run_tests": test_path = args.get("test_path", "tests") try: proc = await asyncio.create_subprocess_exec( "python3", "-m", "pytest", test_path, "-v", stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) stdout, stderr = await proc.communicate() out_str = stdout.decode(errors="replace") err_str = stderr.decode(errors="replace") return { "jsonrpc": "2.0", "result": { "exit_code": proc.returncode,