Spaces:
Running
Running
File size: 1,114 Bytes
6abd773 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | """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
|