fix(mcp-bridge): only queue messages for sessions with a live connection#13551
Open
shreemaan-abhishek wants to merge 1 commit into
Open
Conversation
5 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.
Description
The
mcp-bridgeplugin exposes a message endpoint (POST /message?sessionId=...) that enqueues the request body into themcp-sessionshared dictionary, keyed by thesessionIdquery argument. Today that argument is taken as-is: a server is created for whateversessionIdis supplied and the body is pushed onto<sessionId>:queue, with a-- TODO: check ctx.var.arg_sessionIdmarking the missing validation. Because there is no check that the session has a live SSE connection, and the queue keys have no TTL or length bound, messages can be queued under session ids that no consumer will ever drain, and those queues stay in shared memory until the worker is reset.This PR makes the message endpoint accept only sessions that currently have a live SSE connection, and bounds the per-session queue:
<sessionId>:session) before its endpoint is advertised, and the ping loop refreshes it while the connection stays open. Teardown removes the marker and the queue.404whensessionIdis missing or has no live session, instead of creating a server and queueing for it.pushnow bounds the queue length per session and (re)arms a TTL on the queue key, so a single session cannot grow without limit and an abandoned queue does not linger.The session lookup is exposed as
mcp_server.session_exists()(delegating to the shared-dict broker) so the message endpoint can check it without standing up a server.Which issue(s) this PR fixes:
Fixes #
Checklist