fix: Lifespan pr cleanup/Extending ASGI lifespan examples#1534
Closed
FloorIsGround wants to merge 8 commits intomodelcontextprotocol:mainfrom
Closed
fix: Lifespan pr cleanup/Extending ASGI lifespan examples#1534FloorIsGround wants to merge 8 commits intomodelcontextprotocol:mainfrom
FloorIsGround wants to merge 8 commits intomodelcontextprotocol:mainfrom
Conversation
Fixes modelcontextprotocol#1484 - Add contextlib import and lifespan function to all mounting examples - Add stateless_http=True parameter to FastMCP constructors - Add lifespan=lifespan parameter to Starlette apps - Update README.md documentation with correct examples - Fixes RuntimeError: Task group is not initialized. Make sure to use run() Resolves the issue where mounting StreamableHTTP servers to existing ASGI applications would fail with RuntimeError due to missing session manager initialization.
Run scripts/update_readme_snippets.py to sync documentation with code changes.
…lifespan Extend Fix/streamable http mounting lifespan
Contributor
|
Thanks for working on this! The lifespan fixes were merged via #1669, so this PR is now superseded. Closing, but appreciate the contribution! |
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.
Removed the stateless http additions by @ranjitodedra as they weren't necessary for the issue and may add confusion as stateless_http isn't necessary for a streamable http mcp service.
Motivation and Context
Fixing #1494 and also added an example with more detailed explanation of attaching ASGI services through lifespan.
How Has This Been Tested?
I tested the new example with information from #1484. The main issue was attempting to run two separate ASGI services at the same time rather than mounting them to a main one to call other ASGI services.
Breaking Changes
No there are no breaking changes just documentation and examples.
Types of changes
Checklist
Additional context
As was said in Issue #1494 they found they could mount existing server routes onto an mcp server but were struggling on the configuration to run multiple services asynchronously. It is possible to do so with Starlette examples, the mcp service, as well as other asynchronous services can be started and stopped by a context manager lifespan function, on a Starlette app call.
The confusion with stateless_http is probably that a streamable_http mcp server requires stateless_http due to its name, unless you look deeper you won't find that it is only tied to if requests track sessions or carry persistence between requests. I removed the added stateless_http since it wasn't necessary for the examples in question.