Files
tadata-org--fastapi_mcp/examples/06_custom_mcp_router_example.py
wehub-resource-sync 8f1970542a
CI / Ruff (push) Waiting to run
CI / MyPy (push) Waiting to run
CI / Test Python 3.10 (push) Waiting to run
CI / Test Python 3.11 (push) Waiting to run
CI / Test Python 3.12 (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 12:49:13 +08:00

27 lines
633 B
Python

"""
This example shows how to mount the MCP server to a specific APIRouter, giving a custom mount path.
"""
from examples.shared.apps.items import app # The FastAPI app
from examples.shared.setup import setup_logging
from fastapi import APIRouter
from fastapi_mcp import FastApiMCP
setup_logging()
other_router = APIRouter(prefix="/other/route")
app.include_router(other_router)
mcp = FastApiMCP(app)
# Mount the MCP server to a specific router.
# It will now only be available at `/other/route/mcp`
mcp.mount_http(other_router)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)