-
Notifications
You must be signed in to change notification settings - Fork 559
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Sometimes, the FastAPI router itself doesn't know where it's going to be mounted. This makes it impossible to mount a FastApiMCP instance under a given path.
Example
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() # No prefix specified here
app.include_router(other_router, prefix="/other/route") # Prefix is specified in the include_router call
mcp = FastApiMCP(app)
mcp.mount(other_router) # This will expose the endpoint in the `other_router` at the root, not under `/other/route` as expected
mcp.mount(other_router, mount_path="/other/route") # This is not the expected usage of the mount_path parameter, and does not work
mcp.mount(other_router, mount_path="/other/route/mcp") # This is not the expected usage of the mount_path parameter, and does not work
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
Basically, unless the FastAPI router is instantiated with a prefix, it is impossible to mount a FastApiMCP in a subpath.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working