Files
docs/mcp_server.py
Vishesh 'ironeagle' Bangotra fced40af59 feat(standards): codify codegen, ship generic Tier-B infra, add get_app_template + prompts; fix docs:// regressions
P0: fix doc:// -> docs:// across standards src/server/registry and regenerate stale mongo-ops bundle. P1: build recipe + spec-first routing now document the openapi-first codegen fast path (models/routes with --inject-request/--package). P4: CRUD template documents the model-vs-document id rule (BaseDocument owns id). P5: authless guidance (omit security keys). P6: template gains generic infra (http_cache, keyed SSE bus, KV port+in-memory+Redis), interfaces/openapi.py + .dockerignore + generic build test registered as components, and a get_app_template tool; genericity matrix marks LLM pool + human-in-loop as reference-app patterns. P7: intake/build/start_app/trial prompts. P8: template ships tests/integration/test_openapi_app_builds.py. Rebuilt standards + openapi-first bundles and re-collected.
2026-10-13 03:26:51 +05:30

64 lines
2.0 KiB
Python

import json
from pathlib import Path
from typing import Any
from config import MCPBundle
from mcp.server.fastmcp import FastMCP
class MCPServer:
"""MCP server serving a pre-built documentation bundle."""
def __init__(self, bundle: MCPBundle) -> None:
self.mcp_root = bundle.root
self.app = FastMCP(
name=f"{bundle.name}-mcp",
host="0.0.0.0",
port=bundle.port,
)
self._register_resources()
self._register_tools()
# ------------------------------------------------------------------
# Helpers
# ------------------------------------------------------------------
def _read_json(self, path: Path) -> Any:
if not path.exists():
return {"error": "not_found", "path": str(path)}
return json.loads(path.read_text(encoding="utf-8"))
# ------------------------------------------------------------------
# MCP resources
# ------------------------------------------------------------------
def _register_resources(self) -> None:
@self.app.resource("docs://index")
def index():
return self._read_json(self.mcp_root / "index.json")
@self.app.resource("docs://nav")
def nav():
return self._read_json(self.mcp_root / "nav.json")
@self.app.resource("docs://modules/{module}")
def module(module: str):
return self._read_json(self.mcp_root / "modules" / f"{module}.json")
# ------------------------------------------------------------------
# MCP tools
# ------------------------------------------------------------------
def _register_tools(self) -> None:
@self.app.tool()
def ping() -> str:
return "pong"
# ------------------------------------------------------------------
# ASGI exposure
# ------------------------------------------------------------------
@property
def asgi(self):
return self.app