fix(mcp-bridge): only accept messages for an established session#13550
Closed
shreemaan-abhishek wants to merge 1 commit into
Closed
fix(mcp-bridge): only accept messages for an established session#13550shreemaan-abhishek wants to merge 1 commit into
shreemaan-abhishek wants to merge 1 commit into
Conversation
The message endpoint trusted the supplied sessionId and pushed into a queue for any value, creating a queue for sessions that were never established. Track established SSE sessions with a refreshed liveness marker in the shared dict and return 404 from the message endpoint when the sessionId is missing or does not match a live session.
Contributor
Author
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.
Description
The
mcp-bridgemessage endpoint (POST <base_uri>/message?sessionId=<id>) trusted the suppliedsessionIdunconditionally: it constructed a server for whatever value was passed and pushed the body into that session's shared-dict queue, returning202. This happened even when no SSE session was ever established for that id (including a missingsessionId), leaving orphaned entries in themcp-sessionshared dict that nothing drains. This also removes the long-standingTODO: check ctx.var.arg_sessionIdin the access path.This PR makes the message endpoint only accept messages for a session that is actually established:
mcp-sessionshared dict. The marker is refreshed by the existing keepalive loop and self-expires (TTL) if the worker holding the session goes away without running teardown; it is cleared on normal teardown.404when thesessionIdis missing or does not correspond to a live session, instead of creating a new queue.Which issue(s) this PR fixes:
Fixes #
Checklist