mirror of
https://github.com/tadata-org/fastapi_mcp.git
synced 2025-04-13 23:32:11 +03:00
improve examples
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
"""
|
||||
Simple example of using FastAPI-MCP to add an MCP server to a FastAPI app.
|
||||
"""
|
||||
|
||||
from examples.shared.apps import items
|
||||
from examples.shared.setup import setup_logging
|
||||
|
||||
|
||||
35
examples/reregister_tools_example.py
Normal file
35
examples/reregister_tools_example.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from examples.shared.apps import items
|
||||
from examples.shared.setup import setup_logging
|
||||
|
||||
from fastapi_mcp import FastApiMCP
|
||||
|
||||
setup_logging()
|
||||
|
||||
|
||||
# Add MCP server to the FastAPI app
|
||||
mcp = FastApiMCP(
|
||||
items.app,
|
||||
name="Item API MCP",
|
||||
description="MCP server for the Item API",
|
||||
base_url="http://localhost:8000",
|
||||
)
|
||||
|
||||
|
||||
# MCP server
|
||||
mcp.mount()
|
||||
|
||||
|
||||
# This endpoint will not be registered as a tool, since it was added after the MCP instance was created
|
||||
@items.app.get("/new/endpoint/", operation_id="new_endpoint", response_model=dict[str, str])
|
||||
async def new_endpoint():
|
||||
return {"message": "Hello, world!"}
|
||||
|
||||
|
||||
# But if you re-run the setup, the new endpoints will now be exposed.
|
||||
mcp.setup_server()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run(items.app, host="0.0.0.0", port=8000)
|
||||
@@ -1,7 +1,3 @@
|
||||
"""
|
||||
Simple example of using FastAPI-MCP to add an MCP server to a FastAPI app.
|
||||
"""
|
||||
|
||||
from fastapi import FastAPI
|
||||
import asyncio
|
||||
import uvicorn
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
"""
|
||||
Simple example of using FastAPI-MCP to add an MCP server to a FastAPI app.
|
||||
"""
|
||||
|
||||
from examples.shared.apps import items
|
||||
from examples.shared.setup import setup_logging
|
||||
|
||||
|
||||
Reference in New Issue
Block a user