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
Option to mount SSE server to existing ASGI server (#312)
* Option to mount SSE server to existing ASGI server
Fixes#311
Add option to mount SSE server to an existing ASGI server.
* Add a new method `sse_app` in `src/mcp/server/fastmcp/server.py` to return an instance of the SSE server app.
* Update the `run_sse_async` method in `src/mcp/server/fastmcp/server.py` to use the new `sse_app` method.
* Update the documentation in `README.md` to include instructions on how to mount the SSE server to an existing ASGI server.
* Fix the example in `README.md` to use `app.mount('/', mcp.sse_app())` instead.
---
For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/modelcontextprotocol/python-sdk/issues/311?shareId=XXXX-XXXX-XXXX-XXXX).
* Add `sse_app` method and update `run_sse_async` method in `server.py`
* Add `sse_app` method to return an instance of the SSE server app
* Update `run_sse_async` method to use the new `sse_app` method
Update `README.md` to include instructions for mounting SSE server
* Add section on mounting the SSE server to an existing ASGI server
* fix: Move import statements to the top of the file/
* docs: Update README to reflect changes in mounting SSE server with Starlette
* docs: Formatting of SSE server mounting example in README
-[Mounting to an Existing ASGI Server](#mounting-to-an-existing-asgi-server)
34
35
-[Examples](#examples)
35
36
-[Echo Server](#echo-server)
36
37
-[SQLite Explorer](#sqlite-explorer)
@@ -346,6 +347,31 @@ python server.py
346
347
mcp run server.py
347
348
```
348
349
350
+
### Mounting to an Existing ASGI Server
351
+
352
+
You can mount the SSE server to an existing ASGI server using the `sse_app` method. This allows you to integrate the SSE server with other ASGI applications.
353
+
354
+
```python
355
+
from starlette.applications import Starlette
356
+
from starlette.routes import Mount, Host
357
+
from mcp.server.fastmcp import FastMCP
358
+
359
+
360
+
mcp = FastMCP("My App")
361
+
362
+
# Mount the SSE server to the existing ASGI server
0 commit comments