Option to mount SSE server to existing ASGI server#312
Merged
Kludex merged 5 commits intomodelcontextprotocol:mainfrom Mar 19, 2025
Merged
Option to mount SSE server to existing ASGI server#312Kludex merged 5 commits intomodelcontextprotocol:mainfrom
Kludex merged 5 commits intomodelcontextprotocol:mainfrom
Conversation
Fixes modelcontextprotocol#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).
Kludex
previously approved these changes
Mar 18, 2025
* 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
Kludex
previously approved these changes
Mar 18, 2025
| from fastapi import FastAPI | ||
| from mcp.server.fastmcp import FastMCP | ||
|
|
||
| app = FastAPI() |
Member
There was a problem hiding this comment.
Can you use starlette and link to the starlette docs about mounting instead?
Contributor
Author
There was a problem hiding this comment.
Sure. It seems more natural to use the Starlette example.
Kludex
previously approved these changes
Mar 18, 2025
Kludex
approved these changes
Mar 19, 2025
Member
|
Thanks @comfuture :) |
conorbranagan
pushed a commit
to conorbranagan/python-sdk
that referenced
this pull request
Mar 26, 2025
Small docs fix for modelcontextprotocol#312. The [actual code](https://github.com/comfuture/python-sdk/blob/d29e0e9ca33445285c04bc53bcebdda3b1986181/src/mcp/server/fastmcp/server.py#L22-L23) uses `starlette.routing` which is the correct package name.
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #311
Add option to mount SSE server to an existing ASGI server.
sse_appinsrc/mcp/server/fastmcp/server.pyto return an instance of the SSE server app.run_sse_asyncmethod insrc/mcp/server/fastmcp/server.pyto use the newsse_appmethod.README.mdto include instructions on how to mount the SSE server to an existing ASGI server.README.mdto useapp.mount('/', mcp.sse_app())instead.For more details, open the Copilot Workspace session.