Skip to content

Commit 5985af8

Browse files
committed
improve README
1 parent 8b29e00 commit 5985af8

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,28 @@ That's it! Your auto-generated MCP server is now available at `https://app.base.
6565

6666
> **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.
6767
68+
## Tool Naming
69+
70+
FastAPI-MCP uses the `operation_id` from your FastAPI routes as the MCP tool names. When you don't specify an `operation_id`, FastAPI auto-generates one, but these can be cryptic.
71+
72+
Compare these two endpoint definitions:
73+
74+
```python
75+
# Auto-generated operation_id (something like "read_user_users__user_id__get")
76+
@app.get("/users/{user_id}")
77+
async def read_user(user_id: int):
78+
return {"user_id": user_id}
79+
80+
# Explicit operation_id (tool will be named "get_user_info")
81+
@app.get("/users/{user_id}", operation_id="get_user_info")
82+
async def read_user(user_id: int):
83+
return {"user_id": user_id}
84+
```
85+
86+
For clearer, more intuitive tool names, we recommend adding explicit `operation_id` parameters to your FastAPI route definitions.
87+
88+
To find out more, read FastAPI's official docs about [advanced config of path operations.](https://fastapi.tiangolo.com/advanced/path-operation-advanced-configuration/)
89+
6890
## Advanced Usage
6991

7092
FastAPI-MCP provides several ways to customize and control how your MCP server is created and configured. Here are some advanced usage patterns:
@@ -88,9 +110,11 @@ mcp = FastApiMCP(
88110
mcp.mount()
89111
```
90112

91-
### Mounting to a Separate FastAPI App
113+
### Deploying Separately from Original FastAPI App
114+
115+
You are not limited to serving the MCP on the same FastAPI app from which it was created.
92116

93-
You can create an MCP server from one FastAPI app and mount it to a different app:
117+
You can create an MCP server from one FastAPI app, and mount it to a different app:
94118

95119
```python
96120
from fastapi import FastAPI

0 commit comments

Comments
 (0)