FastAPI-Backend-Models / routes /mcp_routes.py
malek-messaoudii
update mcp part
83c5f9d
raw
history blame
755 Bytes
"""Routes pour exposer MCP via FastAPI"""
from fastapi import APIRouter
from starlette.routing import Mount
from services.mcp_service import mcp_server # Importe l'instance
router = APIRouter(prefix="/mcp", tags=["MCP"])
# Monter l'app FastMCP entière comme sub-app (gère /tools, /call, etc. automatiquement)
from starlette.applications import Starlette
mcp_starlette = Starlette(routes=[Mount("/", app=mcp_server.streamable_http_app())])
# Inclure le Starlette comme route FastAPI (via sub-app mounting)
@router.get("/health")
async def mcp_health():
return {"status": "MCP ready", "tools": [t.name for t in mcp_server.tools]}
# Le mounting principal se fait dans main.py via app.include_router
# Mais pour compat, on peut exposer directement