You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use ASGI-transport httpx client by default, to enable easier connection between MCP server and FastAPI app, without requiring base_url and without requiring the FastAPI app to actually run.
Copy file name to clipboardExpand all lines: README.md
+2-15Lines changed: 2 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,23 +48,14 @@ from fastapi_mcp import FastApiMCP
48
48
49
49
app = FastAPI()
50
50
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",
58
-
)
51
+
mcp = FastApiMCP(app)
59
52
60
53
# Mount the MCP server directly to your FastAPI app
61
54
mcp.mount()
62
55
```
63
56
64
57
That's it! Your auto-generated MCP server is now available at `https://app.base.url/mcp`.
65
58
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
-
68
59
## Tool Naming
69
60
70
61
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.
@@ -102,7 +93,6 @@ app = FastAPI()
102
93
mcp = FastApiMCP(
103
94
app,
104
95
name="My API MCP",
105
-
base_url="http://localhost:8000",
106
96
describe_all_responses=True, # Include all possible response schemas in tool descriptions
107
97
describe_full_response_schema=True# Include full JSON schema in tool descriptions
108
98
)
@@ -178,10 +168,7 @@ api_app = FastAPI()
178
168
mcp_app = FastAPI()
179
169
180
170
# Create MCP server from the API app
181
-
mcp = FastApiMCP(
182
-
api_app,
183
-
base_url="http://api-host:8001", # The URL where the API app will be running
0 commit comments