-
Notifications
You must be signed in to change notification settings - Fork 1.1k
server/sse: return response in handle_post_message #83
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
Conversation
Make SseServerTransport.handle_post_message return Response objects instead of sending them via ASGI, improving framework compatibility and separation of concerns.
@jspahrsummers hello! could you please review this PR? i found a workaround but it's kinda ugly:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We solved this internally by using a Mount
instead of a Route
—e.g.:
routes = [Mount("/message/", app=sse.handle_post_message)]
Would that work for your use case? It's nice for handle_post_message
to support the full ASGI application interface, as that generalizes beyond Starlette. Returning a Response
might make it harder to use in other contexts.
Closing this out since it seems we have a path forwrad that doesnt require a code change. |
@dsp-ant will you update the documentation and code samples, then? |
This change follows the recommended approach from MCP SDK (modelcontextprotocol/python-sdk#83) for handling SSE messages using Starlette's Mount instead of Route. - Replace Route with Mount for /messages/ endpoint - Update SseServerTransport path to include trailing slash
Changes
SseServerTransport.handle_post_message
to returnResponse
objects instead of sending them directly via ASGIMotivation and Context
The current implementation directly sends ASGI responses, which breaks when used with Starlette because Starlette expects route handlers to return response objects. After the request is handled, Starlette tries to call the response object which currently fails because the
handle_post_message
method returns None:How Has This Been Tested?
Tested the change with this code running locally:
Breaking Changes
Technically, the change is breaking because it removes on of the unused parameter but it didn't work anyway.
Types of changes
Checklist
Additional context