sakasurya's picture
Release
6abd773 verified
Raw History Blame Contribute Delete
1.11 kB
"""OpenGovtData-MCP Space: FastAPI HTTP API + MCP streamable HTTP (/mcp) over the bundled demo store."""
import contextlib
import os
from ogd.mcp.core import OgdBackend
from ogd.mcp.server import make_api, make_mcp
STORE = os.environ.get("OGD_STORE", os.path.join(os.path.dirname(os.path.abspath(__file__)), "demo_store"))
backend = OgdBackend(STORE, None, threads=2)
mcp_server = make_mcp(backend)
mcp_app = mcp_server.streamable_http_app(streamable_http_path="/mcp", stateless_http=True, host="0.0.0.0")
app = make_api(backend)
@contextlib.asynccontextmanager
async def _lifespan(_app):
async with mcp_server.session_manager.run():
yield
app.router.lifespan_context = _lifespan
@app.get("/")
def root() -> dict:
return {"name": "OpenGovtData-MCP", "demo_tables": sum(1 for r in backend.catalog.values() if r.get("table_path")),
"http_api": ["/search?q=", "/describe/{uuid}", "/cite/{uuid}", "POST /query", "/health"],
"mcp": "/mcp (streamable HTTP)", "docs": "/docs"}
app.mount("/", mcp_app) # last: FastAPI routes above win, /mcp falls through to the MCP app