mcp: tolerate 404 on subscriptions/listen in stateless mode - #1193
Merged
Conversation
Comment on lines
+1113
to
+1114
| } | ||
| return nil, jsonrpc2.ErrMethodNotFound |
Contributor
There was a problem hiding this comment.
this test was never broken. returning a JSON-RPC decodable error now would wrap the error with ErrRejecting preventing the connection to close. We should return a plain text error
Contributor
Author
There was a problem hiding this comment.
Ah yes, thanks. The plain text error is covered in TestStreamableClient_StatelessSubscriptionsListen404, so removing this test.
Comment on lines
+1119
to
+1120
|
|
||
| ct, st := NewInMemoryTransports() |
Contributor
There was a problem hiding this comment.
you should use a Streamable connection to verify the actual fix
Contributor
Author
There was a problem hiding this comment.
I removed this test since the case is covered in the other test.
When connecting to remote stateless servers (such as GitHub's MCP server), optional streams like subscriptions/listen may be rejected by middleware with a plain-text HTTP 404 before reaching a JSON-RPC handler. Previously, checkResponse misclassified these 404s as lost stateful sessions (ErrSessionMissing) and tore down the transport connection because the error didn't wrap jsonrpc2.ErrRejected. This change aligns with the MCP 2026-07-28 Streamable HTTP specification: 1. Conditionally check for an active session ID before returning ErrSessionMissing, since a 404 on a stateless connection cannot mean a session was lost. 2. Wrap subscriptions/listen failures with ErrRejected (matching server/discover) so the jsonrpc2 layer doesn't permanently break the transport when encountering non-compliant plain-text 404s.
Contributor
Author
|
Thanks for the review, I pushed changes that:
|
guglielmo-san
approved these changes
Aug 25, 2026
Contributor
|
@smlx thank you for the contribution! |
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.
When connecting to remote stateless servers (such as GitHub's MCP server), optional streams like subscriptions/listen may be rejected by middleware with a plain-text HTTP 404 before reaching a JSON-RPC handler.
Previously, checkResponse misclassified these 404s as lost stateful sessions (ErrSessionMissing) and tore down the transport connection because the error didn't wrap jsonrpc2.ErrRejected.
This change aligns with the MCP 2026-07-28 Streamable HTTP specification:
Conditionally check for an active session ID before returning ErrSessionMissing, since a 404 on a stateless connection cannot mean a session was lost.
Wrap subscriptions/listen failures with ErrRejected (matching server/discover) so the jsonrpc2 layer doesn't permanently break the transport when encountering non-compliant plain-text 404s.
I have manually tested this change against GitHub's hosted MCP server and confirmed that it fixes github/github-mcp-server#3129