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
Copy file name to clipboardExpand all lines: README.md
+30Lines changed: 30 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,7 @@
23
23
-**Preserving schemas** of your request models and response models
24
24
-**Preserve documentation** of all your endpoints, just as it is in Swagger
25
25
-**Flexible deployment** - Mount your MCP server to the same app, or deploy separately
26
+
-**ASGI transport** - Uses FastAPI's ASGI interface directly by default for efficient communication
26
27
27
28
## Installation
28
29
@@ -202,6 +203,35 @@ async def new_endpoint():
202
203
mcp.setup_server()
203
204
```
204
205
206
+
### Communication with the FastAPI App
207
+
208
+
FastAPI-MCP uses ASGI transport by default, which means it communicates directly with your FastAPI app without making HTTP requests. This is more efficient and doesn't require a base URL.
209
+
210
+
It's not even necessary that the FastAPI server will run. See the examples folder for more.
211
+
212
+
If you need to specify a custom base URL or use a different transport method, you can provide your own `httpx.AsyncClient`:
213
+
214
+
```python
215
+
import httpx
216
+
from fastapi import FastAPI
217
+
from fastapi_mcp import FastApiMCP
218
+
219
+
app = FastAPI()
220
+
221
+
# Use a custom HTTP client with a specific base URL
222
+
custom_client = httpx.AsyncClient(
223
+
base_url="https://api.example.com",
224
+
timeout=30.0
225
+
)
226
+
227
+
mcp = FastApiMCP(
228
+
app,
229
+
http_client=custom_client
230
+
)
231
+
232
+
mcp.mount()
233
+
```
234
+
205
235
## Examples
206
236
207
237
See the [examples](examples) directory for complete examples.
0 commit comments