Skip to content

Ensure FastMCP handles nested SSE and SHTTP apps properly in ASGI frameworks #390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 9, 2025

Conversation

jlowin
Copy link
Owner

@jlowin jlowin commented May 9, 2025

Closes #365
Closes #370
Closes #382
Closes #234
Closes #225
Closes #189

Addresses the following low-level / FastMCP 1.0 issues: modelcontextprotocol/python-sdk#673, modelcontextprotocol/python-sdk#563, modelcontextprotocol/python-sdk#507, modelcontextprotocol/python-sdk#464, modelcontextprotocol/python-sdk#412

Since it is unclear if the low-level SDK will merge modelcontextprotocol/python-sdk#659, we are adding a patched low-level SSEServerTransport to FastMCP (and can remove it if/when the bug is fixed). This should resolve issues with nested ASGI applications.

However, note that you must pass the MCP lifespan to the outer-most app, due to the current design of the StreamableHTTPSessionManager. We are looking at whether we can replace that implementation with a more self-contained one.

This also includes complete documentation for ASGI framework integration and tests for nested SSE and SHTTP starlette apps.

@Copilot Copilot AI review requested due to automatic review settings May 9, 2025 21:41
@jlowin jlowin added bug Something isn't working documentation Improvements or additions to documentation labels May 9, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures that FastMCP handles nested SSE and Streamable HTTP apps correctly when integrated into ASGI frameworks, while also patching low-level SSE transport issues and updating documentation accordingly.

  • Introduces nested server configurations in tests for both HTTP and SSE transports.
  • Refactors Starlette app creation in server code and patches the low-level SSE transport.
  • Updates project timeout configuration and enhances ASGI integration documentation.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/client/test_streamable_http.py Adds nested server test and corresponding helper function.
tests/client/test_sse.py Adds nested server test for SSE and corresponding helper function.
src/fastmcp/server/http.py Refactors base app creation and updates import for SSE transport.
src/fastmcp/low_level/sse_server_transport.py Introduces a patched low-level SSE transport implementation.
src/fastmcp/low_level/README.md Updates README with a brief note on patched low-level objects.
pyproject.toml Reduces the test timeout from 5 to 3.
docs/* Adds documentation for ASGI integration, custom routes, and nested mounts.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jlowin jlowin merged commit 5abdf7e into main May 9, 2025
4 checks passed
@jlowin jlowin deleted the mount branch May 9, 2025 21:45
jordicore pushed a commit to jordicore/fastmcp that referenced this pull request Jul 2, 2025
Ensure FastMCP handles nested SSE and SHTTP apps properly in ASGI frameworks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment