|
6 | 6 | from fastapi import FastAPI, HTTPException, Request |
7 | 7 | from mcp.server.fastmcp import FastMCP |
8 | 8 | from mcp.server.streamable_http_manager import StreamableHTTPSessionManager |
| 9 | +import contextlib |
| 10 | + |
| 11 | +from starlette.applications import Starlette |
| 12 | +from starlette.routing import Mount |
| 13 | + |
| 14 | +from mcp.server.fastmcp import FastMCP |
9 | 15 |
|
10 | 16 | # to start (after .venv setup): |
11 | 17 | # python spendee/spendee_mcp.py |
@@ -75,17 +81,20 @@ def get_wallets(): |
75 | 81 | # uvicorn.run(app, host="0.0.0.0", port=PORT) |
76 | 82 |
|
77 | 83 | def server_with_sse(): |
78 | | - app = FastAPI() |
79 | | - @app.get("/") |
80 | | - def read_root(): |
81 | | - return {"Hello": "World"} |
82 | | - #from app.sse import create_sse_server |
83 | | - app.mount("/", app.sse.create_sse_server(mcp)) |
| 84 | + |
| 85 | + # Create the Starlette app and mount the MCP servers |
| 86 | + app = Starlette( |
| 87 | + routes=[ |
| 88 | + Mount("/", mcp.sse_app()), |
| 89 | + ], |
| 90 | + ) |
| 91 | + uvicorn.run(app, host="0.0.0.0", port=PORT) |
| 92 | + |
84 | 93 |
|
85 | 94 | if __name__ == "__main__": |
86 | 95 | logger.info("Starting Spendee MCP Server as SSE without authentication") |
87 | | - mcp.run(transport="sse") # for n8n compatibility, authentication implemented on cloudflare level |
88 | | - #server_with_sse() |
| 96 | + # for n8n compatibility, authentication implemented on cloudflare level |
| 97 | + server_with_sse() |
89 | 98 |
|
90 | 99 | # if DISABLE_AUTH: |
91 | 100 | # logger.warning("Running without authentication! This is insecure and should only be used for local testing.") |
|
0 commit comments