fix(serve-mcp): concurrent stdio dispatch, real local session, notification delivery#68
Merged
Conversation
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.
Previously
stdioLoopprocessed one request at a time — each line was parsed, dispatched, and written before the next was read. Now each line is dispatched onto its own virtual thread. APhaserwaits for all in-flight dispatches before the loop exits. A singlemcp-stdio-writervirtual thread owns all writes to the output stream via aLinkedBlockingQueue, serializing responses without blocking dispatch and keepingPipedInputStream's writer-thread tracking pointed at one live thread.Previously
stdioLoopdispatched all requests under the session ID"local"but never created a correspondingSessionState, soresources/subscribeandresources/unsubscribesilently no-oped. ASessionStateis now created at loop entry and torn down on exit.stateFor(sessionId)centralises the lookup so dispatch, subscribe, and unsubscribe all reach it correctly.notifyResourceChangednow checksstdioOutputQueuealongside the existing SSE emitter loop, deliveringnotifications/resources/updatedto any stdio session subscribed to the changed URI. It is a no-op when the stdio loop is not running.