Skip to content

Commit 99a80f2

Browse files
committed
update README
1 parent 696c5b4 commit 99a80f2

File tree

1 file changed

+80
-30
lines changed

1 file changed

+80
-30
lines changed

README.md

Lines changed: 80 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
- **Automatic discovery** of all FastAPI endpoints and conversion to MCP tools
2323
- **Preserving schemas** of your request models and response models
2424
- **Preserve documentation** of all your endpoints, just as it is in Swagger
25-
- **Extend** - Add custom MCP tools alongside the auto-generated ones
25+
- **Flexible deployment** - Mount your MCP server to the same app, or deploy separately
2626

2727
## Installation
2828

@@ -44,45 +44,101 @@ The simplest way to use FastAPI-MCP is to add an MCP server directly to your Fas
4444

4545
```python
4646
from fastapi import FastAPI
47-
from fastapi_mcp import add_mcp_server
47+
from fastapi_mcp import FastApiMCP
4848

49-
# Your FastAPI app
5049
app = FastAPI()
5150

52-
# Mount the MCP server to your app
53-
add_mcp_server(
54-
app, # Your FastAPI app
55-
mount_path="/mcp", # Where to mount the MCP server
56-
name="My API MCP", # Name for the MCP server
51+
mcp = FastApiMCP(
52+
app,
53+
54+
# Optional parameters
55+
name="My API MCP",
56+
description="My API description",
57+
base_url="http://localhost:8000",
5758
)
59+
60+
# Mount the MCP server directly to your FastAPI app
61+
mcp.mount()
5862
```
5963

6064
That's it! Your auto-generated MCP server is now available at `https://app.base.url/mcp`.
6165

66+
> **Note on `base_url`**: While `base_url` is optional, it is highly recommended to provide it explicitly. The `base_url` tells the MCP server where to send API requests when tools are called. Without it, the library will attempt to determine the URL automatically, which may not work correctly in deployed environments where the internal and external URLs differ.
67+
6268
## Advanced Usage
6369

6470
FastAPI-MCP provides several ways to customize and control how your MCP server is created and configured. Here are some advanced usage patterns:
6571

72+
### Customizing Schema Description
73+
6674
```python
6775
from fastapi import FastAPI
68-
from fastapi_mcp import add_mcp_server
76+
from fastapi_mcp import FastApiMCP
6977

7078
app = FastAPI()
7179

72-
mcp_server = add_mcp_server(
73-
app, # Your FastAPI app
74-
mount_path="/mcp", # Where to mount the MCP server
75-
name="My API MCP", # Name for the MCP server
76-
describe_all_responses=True, # False by default. Include all possible response schemas in tool descriptions, instead of just the successful response.
77-
describe_full_response_schema=True # False by default. Include full JSON schema in tool descriptions, instead of just an LLM-friendly response example.
80+
mcp = FastApiMCP(
81+
app,
82+
name="My API MCP",
83+
base_url="http://localhost:8000",
84+
describe_all_responses=True, # Include all possible response schemas in tool descriptions
85+
describe_full_response_schema=True # Include full JSON schema in tool descriptions
86+
)
87+
88+
mcp.mount()
89+
```
90+
91+
### Mounting to a Separate FastAPI App
92+
93+
You can create an MCP server from one FastAPI app and mount it to a different app:
94+
95+
```python
96+
from fastapi import FastAPI
97+
from fastapi_mcp import FastApiMCP
98+
99+
# Your API app
100+
api_app = FastAPI()
101+
# ... define your API endpoints on api_app ...
102+
103+
# A separate app for the MCP server
104+
mcp_app = FastAPI()
105+
106+
# Create MCP server from the API app
107+
mcp = FastApiMCP(
108+
api_app,
109+
base_url="http://api-host:8001", # The URL where the API app will be running
78110
)
79111

80-
# Optionally add custom tools in addition to existing APIs.
81-
@mcp_server.tool()
82-
async def get_server_time() -> str:
83-
"""Get the current server time."""
84-
from datetime import datetime
85-
return datetime.now().isoformat()
112+
# Mount the MCP server to the separate app
113+
mcp.mount(mcp_app)
114+
115+
# Now you can run both apps separately:
116+
# uvicorn main:api_app --host api-host --port 8001
117+
# uvicorn main:mcp_app --host mcp-host --port 8000
118+
```
119+
120+
### Adding Endpoints After MCP Server Creation
121+
122+
If you add endpoints to your FastAPI app after creating the MCP server, you'll need to refresh the server to include them:
123+
124+
```python
125+
from fastapi import FastAPI
126+
from fastapi_mcp import FastApiMCP
127+
128+
app = FastAPI()
129+
# ... define initial endpoints ...
130+
131+
# Create MCP server
132+
mcp = FastApiMCP(app)
133+
mcp.mount()
134+
135+
# Add new endpoints after MCP server creation
136+
@app.get("/new/endpoint/", operation_id="new_endpoint")
137+
async def new_endpoint():
138+
return {"message": "Hello, world!"}
139+
140+
# Refresh the MCP server to include the new endpoint
141+
mcp.setup_server()
86142
```
87143

88144
## Examples
@@ -137,25 +193,19 @@ Find the path to mcp-proxy by running in Terminal: `which mcp-proxy`.
137193

138194
## Development and Contributing
139195

140-
**Notice:** We are currently refactoring our MCP auto-generation system. To avoid potential conflicts, we kindly request that you delay submitting contributions until this notice is removed from the README. Thank you for your understanding and patience.
196+
Thank you for considering contributing to FastAPI-MCP! We encourage the community to post Issues and Pull Requests.
141197

142-
Thank you for considering contributing to FastAPI-MCP open source projects! It's people like you that make it a reality for users in our community.
143-
144-
Before you get started, please see [CONTRIBUTING.md](CONTRIBUTING.md).
198+
Before you get started, please see our [Contribution Guide](CONTRIBUTING.md).
145199

146200
## Community
147201

148202
Join [MCParty Slack community](https://join.slack.com/t/themcparty/shared_invite/zt-30yxr1zdi-2FG~XjBA0xIgYSYuKe7~Xg) to connect with other MCP enthusiasts, ask questions, and share your experiences with FastAPI-MCP.
149203

150204
## Requirements
151205

152-
- Python 3.10+
206+
- Python 3.10+ (Recommended 3.12)
153207
- uv
154208

155209
## License
156210

157211
MIT License. Copyright (c) 2024 Tadata Inc.
158-
159-
## About
160-
161-
Developed and maintained by [Tadata Inc.](https://github.com/tadata-org)

0 commit comments

Comments
 (0)