mirror of
https://github.com/tadata-org/fastapi_mcp.git
synced 2025-04-13 23:32:11 +03:00
add example
This commit is contained in:
28
examples/mount_specific_router_example.py
Normal file
28
examples/mount_specific_router_example.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from examples.shared.apps import items
|
||||
from examples.shared.setup import setup_logging
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi_mcp import FastApiMCP
|
||||
|
||||
setup_logging()
|
||||
|
||||
|
||||
router = APIRouter(prefix="/other/route")
|
||||
items.app.include_router(router)
|
||||
|
||||
mcp = FastApiMCP(
|
||||
items.app,
|
||||
name="Item API MCP",
|
||||
description="MCP server for the Item API",
|
||||
base_url="http://localhost:8000",
|
||||
)
|
||||
|
||||
# Mount the MCP server to a specific router.
|
||||
# It will now only be available at `/other/route/mcp`
|
||||
mcp.mount(router)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run(items.app, host="0.0.0.0", port=8000)
|
||||
Reference in New Issue
Block a user