Skip to content

Tolerate a non JSON-RPC response body for notifications - #153

Draft
orthodoX wants to merge 1 commit into
patvice:mainfrom
orthodoX:tolerate-notification-response-bodies
Draft

Tolerate a non JSON-RPC response body for notifications#153
orthodoX wants to merge 1 commit into
patvice:mainfrom
orthodoX:tolerate-notification-response-bodies

Conversation

@orthodoX

Copy link
Copy Markdown
Contributor

Problem

The MCP spec says a server answers a notification (a message with no id) with 202 Accepted and no body, which the transport handles. Some servers (e.g. https://mcp.trainual.com) instead return 200 with body: { ok: true } that is not a JSON-RPC envelope.

handle_success_response validates every 200 JSON body as an envelope, so the notifications/initialized step raises TransportError: Invalid JSON response: Invalid JSON-RPC envelope, killing the handshake right after a successful initialize.

Fix

When the message was a notification (request_id is nil), skip the JSON body entirely, nothing waits on it. Requests keep the strict envelope validation. The session id header is still captured, since that happens in handle_response before the body is read.

One existing spec asserted a Result was returned for a notification response; updated it to expect nil while confirming the session id is still captured.

@orthodoX
orthodoX marked this pull request as draft July 30, 2026 19:16
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.

1 participant