Commit 738283f
fix: follow FastMCP + FastAPI pattern from python-sdk PR #1712
**Problem**: FastMCP doesn't have http_app() method, only streamable_http_app()
**Solution**: Follow official pattern from MCP Python SDK PR #1712:
modelcontextprotocol/python-sdk#1712
Key insights:
1. Use mcp.streamable_http_app() to get Starlette app
2. Create custom lifespan with mcp.session_manager.run()
3. FastAPI doesn't auto-trigger sub-app lifespans, must manage manually
4. Set streamable_http_path="/" in FastMCP constructor
Pattern:
```python
@contextlib.asynccontextmanager
async def lifespan(app: FastAPI):
async with mcp.session_manager.run():
yield
app = FastAPI(lifespan=lifespan)
mcp_app = mcp.streamable_http_app()
app.mount("/mcp", mcp_app)
```
**Changes**:
- tools/server.py: Add streamable_http_path="/" to FastMCP
- main.py: Use streamable_http_app() + custom lifespan
- main.py: Standard app.mount("/mcp", mcp_app)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>1 parent b7b3a9c commit 738283f
2 files changed
+25
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
21 | 25 | | |
22 | 26 | | |
| 27 | + | |
23 | 28 | | |
24 | 29 | | |
25 | | - | |
| 30 | + | |
| 31 | + | |
26 | 32 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
| |||
121 | 120 | | |
122 | 121 | | |
123 | 122 | | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
129 | 126 | | |
130 | 127 | | |
131 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
636 | 637 | | |
637 | 638 | | |
638 | 639 | | |
639 | | - | |
| 640 | + | |
640 | 641 | | |
641 | 642 | | |
642 | 643 | | |
643 | 644 | | |
644 | | - | |
| 645 | + | |
645 | 646 | | |
646 | | - | |
| 647 | + | |
647 | 648 | | |
648 | 649 | | |
649 | 650 | | |
| |||
0 commit comments