Skip to content

Commit ebbd0e4

Browse files
committed
improve examples
1 parent 5e6544b commit ebbd0e4

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

examples/full_schema_description_example.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
"""
2-
Simple example of using FastAPI-MCP to add an MCP server to a FastAPI app.
3-
"""
4-
51
from examples.shared.apps import items
62
from examples.shared.setup import setup_logging
73

examples/reregister_tools_example.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from examples.shared.apps import items
2+
from examples.shared.setup import setup_logging
3+
4+
from fastapi_mcp import FastApiMCP
5+
6+
setup_logging()
7+
8+
9+
# Add MCP server to the FastAPI app
10+
mcp = FastApiMCP(
11+
items.app,
12+
name="Item API MCP",
13+
description="MCP server for the Item API",
14+
base_url="http://localhost:8000",
15+
)
16+
17+
18+
# MCP server
19+
mcp.mount()
20+
21+
22+
# This endpoint will not be registered as a tool, since it was added after the MCP instance was created
23+
@items.app.get("/new/endpoint/", operation_id="new_endpoint", response_model=dict[str, str])
24+
async def new_endpoint():
25+
return {"message": "Hello, world!"}
26+
27+
28+
# But if you re-run the setup, the new endpoints will now be exposed.
29+
mcp.setup_server()
30+
31+
32+
if __name__ == "__main__":
33+
import uvicorn
34+
35+
uvicorn.run(items.app, host="0.0.0.0", port=8000)

examples/separate_server_example.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
"""
2-
Simple example of using FastAPI-MCP to add an MCP server to a FastAPI app.
3-
"""
4-
51
from fastapi import FastAPI
62
import asyncio
73
import uvicorn

examples/simple_example.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
"""
2-
Simple example of using FastAPI-MCP to add an MCP server to a FastAPI app.
3-
"""
4-
51
from examples.shared.apps import items
62
from examples.shared.setup import setup_logging
73

0 commit comments

Comments
 (0)