Skip to content

Commit 7d369f8

Browse files
committed
change docs for streamable HTTP and add changelog
1 parent 25d016c commit 7d369f8

20 files changed

+251
-148
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ repos:
33
rev: v5.0.0
44
hooks:
55
- id: trailing-whitespace
6-
exclude: \.md$
6+
exclude: \.(md|mdx)$
77
- id: check-yaml
88
- id: check-added-large-files
99

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
🚀 **FastAPI-MCP now supports Streamable HTTP transport.**
11+
12+
HTTP transport is now the recommended approach, following the specification that positions HTTP as the standard while maintaining SSE for backwards compatibility.
13+
14+
### ⚠️ Breaking Changes
15+
- **`mount()` method is deprecated** and will be removed in a future version. Use `mount_http()` for HTTP transport (recommended) or `mount_sse()` for SSE transport.
16+
17+
### Added
18+
- 🎉 **Streamable HTTP Transport Support** - New `mount_http()` method implementing the MCP Streamable HTTP specification
19+
- 🎉 **Stateful Session Management** - For both HTTP and SSE transports
20+
821
## [0.3.7]
922

1023
### Fixed

docs/advanced/asgi.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: Transport
3+
description: How to communicate with the FastAPI app
4+
icon: microchip
5+
---
6+
7+
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.
8+
9+
It's not even necessary that the FastAPI server will run.
10+
11+
If you need to specify a custom base URL or use a different transport method, you can provide your own `httpx.AsyncClient`:
12+
13+
```python {7-10, 14}
14+
import httpx
15+
from fastapi import FastAPI
16+
from fastapi_mcp import FastApiMCP
17+
18+
app = FastAPI()
19+
20+
custom_client = httpx.AsyncClient(
21+
base_url="https://api.example.com",
22+
timeout=30.0
23+
)
24+
25+
mcp = FastApiMCP(
26+
app,
27+
http_client=custom_client
28+
)
29+
30+
mcp.mount()
31+
```

docs/advanced/auth.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ mcp = FastApiMCP(
4949
dependencies=[Depends(verify_auth)],
5050
),
5151
)
52-
mcp.mount()
52+
mcp.mount_http()
5353
```
5454

5555
For a complete working example of authorization header, check out the [Token Passthrough Example](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py) in the examples folder.
@@ -79,7 +79,7 @@ mcp = FastApiMCP(
7979
),
8080
)
8181

82-
mcp.mount()
82+
mcp.mount_http()
8383
```
8484

8585
And you can call it like:
@@ -131,7 +131,7 @@ mcp = FastApiMCP(
131131
),
132132
)
133133

134-
mcp.mount()
134+
mcp.mount_http()
135135
```
136136

137137
This approach gives you complete control over the OAuth metadata and is useful when:
@@ -195,8 +195,8 @@ You also need to make sure to configure callback URLs properly in your OAuth pro
195195
Proxies solve several problems:
196196

197197
1. **Missing registration endpoints**:
198-
The MCP spec expects OAuth providers to support [dynamic client registration (RFC 7591)](https://datatracker.ietf.org/doc/html/rfc7591), but many don't.
199-
Furthermore, dynamic client registration is probably overkill for most use cases.
198+
The MCP spec expects OAuth providers to support [dynamic client registration (RFC 7591)](https://datatracker.ietf.org/doc/html/rfc7591), but many don't.
199+
Furthermore, dynamic client registration is probably overkill for most use cases.
200200
The `setup_fake_dynamic_registration` option (True by default) creates a compatible endpoint that just returns a static client ID and secret.
201201

202202
2. **Scope handling**:

docs/advanced/deploy.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mcp_app = FastAPI()
2424
mcp = FastApiMCP(api_app)
2525

2626
# Mount the MCP server to the separate app
27-
mcp.mount(mcp_app)
27+
mcp.mount_http(mcp_app)
2828
```
2929

3030
Then, you can run both apps separately:

docs/advanced/refresh.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ from fastapi_mcp import FastApiMCP
1313
app = FastAPI()
1414

1515
mcp = FastApiMCP(app)
16-
mcp.mount()
16+
mcp.mount_http()
1717

1818
# Add new endpoints after MCP server creation
1919
@app.get("/new/endpoint/", operation_id="new_endpoint")

docs/advanced/transport.mdx

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,91 @@
11
---
2-
title: Transport
3-
description: How to communicate with the FastAPI app
2+
title: MCP Transport
3+
description: Understanding MCP transport methods and how to choose between them
44
icon: car
55
---
66

7-
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.
7+
FastAPI-MCP supports two MCP transport methods for client-server communication: **HTTP transport** (recommended) and **SSE transport** (backwards compatibility).
88

9-
It's not even necessary that the FastAPI server will run.
9+
## HTTP Transport (Recommended)
1010

11-
If you need to specify a custom base URL or use a different transport method, you can provide your own `httpx.AsyncClient`:
11+
HTTP transport is the **recommended** transport method as it implements the latest MCP Streamable HTTP specification. It provides better session management, more robust connection handling, and aligns with standard HTTP practices.
1212

13-
```python {7-10, 14}
14-
import httpx
13+
### Using HTTP Transport
14+
15+
```python {7}
16+
from fastapi import FastAPI
17+
from fastapi_mcp import FastApiMCP
18+
19+
app = FastAPI()
20+
mcp = FastApiMCP(app)
21+
22+
# Mount using HTTP transport (recommended)
23+
mcp.mount_http()
24+
```
25+
26+
## SSE Transport (Backwards Compatibility)
27+
28+
SSE (Server-Sent Events) transport is maintained for backwards compatibility with older MCP implementations.
29+
30+
### Using SSE Transport
31+
32+
```python {7}
1533
from fastapi import FastAPI
1634
from fastapi_mcp import FastApiMCP
1735

1836
app = FastAPI()
37+
mcp = FastApiMCP(app)
38+
39+
# Mount using SSE transport (backwards compatibility)
40+
mcp.mount_sse()
41+
```
42+
43+
## Advanced Configuration
44+
45+
Both transport methods support the same FastAPI integration features like custom routing and authentication:
46+
47+
```python
48+
from fastapi import FastAPI, APIRouter
49+
from fastapi_mcp import FastApiMCP
50+
51+
app = FastAPI()
52+
router = APIRouter(prefix="/api/v1")
53+
54+
mcp = FastApiMCP(app)
55+
56+
# Mount to custom path with HTTP transport
57+
mcp.mount_http(router, mount_path="/my-http")
58+
59+
# Or with SSE transport
60+
mcp.mount_sse(router, mount_path="/my-sse")
61+
```
62+
63+
## Client Connection Examples
64+
65+
### HTTP Transport Client Connection
66+
67+
For HTTP transport, MCP clients connect directly to the HTTP endpoint:
68+
69+
```json
70+
{
71+
"mcpServers": {
72+
"fastapi-mcp": {
73+
"url": "http://localhost:8000/mcp"
74+
}
75+
}
76+
}
77+
```
1978

20-
custom_client = httpx.AsyncClient(
21-
base_url="https://api.example.com",
22-
timeout=30.0
23-
)
79+
### SSE Transport Client Connection
2480

25-
mcp = FastApiMCP(
26-
app,
27-
http_client=custom_client
28-
)
81+
For SSE transport, MCP clients use the same URL but communicate via Server-Sent Events:
2982

30-
mcp.mount()
83+
```json
84+
{
85+
"mcpServers": {
86+
"fastapi-mcp": {
87+
"url": "http://localhost:8000/sse"
88+
}
89+
}
90+
}
3191
```

docs/configurations/customization.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mcp = FastApiMCP(
1818
name="My API MCP",
1919
description="Very cool MCP server",
2020
)
21-
mcp.mount()
21+
mcp.mount_http()
2222
```
2323

2424
## Tool and schema descriptions
@@ -39,7 +39,7 @@ mcp = FastApiMCP(
3939
describe_full_response_schema=True
4040
)
4141

42-
mcp.mount()
42+
mcp.mount_http()
4343
```
4444

4545
## Customizing Exposed Endpoints
@@ -66,7 +66,7 @@ The relevant arguments for these configurations are `include_operations`, `exclu
6666
app,
6767
include_operations=["get_user", "create_user"]
6868
)
69-
mcp.mount()
69+
mcp.mount_http()
7070
```
7171

7272
```python Exclude Operations {8}
@@ -79,7 +79,7 @@ The relevant arguments for these configurations are `include_operations`, `exclu
7979
app,
8080
exclude_operations=["delete_user"]
8181
)
82-
mcp.mount()
82+
mcp.mount_http()
8383
```
8484

8585
```python Include Tags {8}
@@ -92,7 +92,7 @@ The relevant arguments for these configurations are `include_operations`, `exclu
9292
app,
9393
include_tags=["users", "public"]
9494
)
95-
mcp.mount()
95+
mcp.mount_http()
9696
```
9797

9898
```python Exclude Tags {8}
@@ -105,7 +105,7 @@ The relevant arguments for these configurations are `include_operations`, `exclu
105105
app,
106106
exclude_tags=["admin", "internal"]
107107
)
108-
mcp.mount()
108+
mcp.mount_http()
109109
```
110110

111111
```python Combined (include mode) {8-9}
@@ -119,7 +119,7 @@ The relevant arguments for these configurations are `include_operations`, `exclu
119119
include_operations=["user_login"],
120120
include_tags=["public"]
121121
)
122-
mcp.mount()
122+
mcp.mount_http()
123123
```
124124
</CodeGroup>
125125

0 commit comments

Comments
 (0)