Skip to content

[Server] Answer a JSON POST with only its own responses - #508

Open
vbcherepanov wants to merge 1 commit into
modelcontextprotocol:mainfrom
vbcherepanov:fix/467-json-response-own-messages
Open

[Server] Answer a JSON POST with only its own responses#508
vbcherepanov wants to merge 1 commit into
modelcontextprotocol:mainfrom
vbcherepanov:fix/467-json-response-own-messages

Conversation

@vbcherepanov

Copy link
Copy Markdown

Fixes #467.

With PHP-FPM, requests of the same session run in parallel and put their responses into the same session queue. createJsonResponse() took the whole queue, so one request got all responses as a JSON array and the others got 202 with nothing.

Now the transport collects the ids from its own POST body and takes only those responses. The rest stays in the queue. Batches are still answered with an array, single messages with one object, and an invalid message without a usable id still gets its error.

Protocol::consumeOutgoingMessages() gets the ids as an optional second argument. Without it nothing changes, so the SSE path and StdioTransport work as before.

The reproducer is testConcurrentPostsSharingASessionEachReceiveTheirOwnResponse: the second POST is handled completely between the first one queueing its response and reading the queue. It fails on main.

Not part of this PR:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StreamableHttpTransport returns a JSON array in the response body when parallel POST requests arrive concurrently (PHP-FPM)

1 participant