Repository navigation
Classify a server's subscribe/unsubscribe rejection as server_error (#3095) - #3109
Merged
Merged
Conversation
…3095) InspectorClient wrapped every resources/subscribe and resources/unsubscribe failure in a plain Error, hiding the SDK's ProtocolError from classifyError, which reads one only at the top level. A server that refused a subscription therefore exited 1 (usage) with {"code":"error"}. The wrap now goes through subscriptionFailure(): a ProtocolError is rebuilt as a ProtocolError (same code and data, via fromError so branded subclasses survive) carrying the same "Failed to subscribe to resource: …" message and the original as cause. Every other failure keeps the plain wrapper, so a buried ConnectionClosed still does not read as a server exit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the subscription error-handling changes.
No open issues 🎉
What changed in this PR
Fixes #3095 by preserving server JSON-RPC errors through InspectorClient’s subscription failure handling, allowing CLI classification as server_error with exit code 5.
Changes:
- Adds a shared error wrapper that preserves protocol error codes, data, subclasses, and causes while retaining user-facing message prefixes.
- Uses the wrapper for both subscribe and unsubscribe failures.
- Adds unit coverage and real-server regression tests for subscription rejections.
| File | Description |
|---|---|
core/mcp/subscriptionAck.ts |
Adds protocol-aware subscription failure wrapping. |
core/mcp/inspectorClient.ts |
Applies the wrapper to subscribe and unsubscribe failures. |
clients/web/src/test/core/mcp/subscriptionAck.test.ts |
Tests protocol error preservation and ordinary error wrapping. |
clients/cli/__tests__/failure-classes.test.ts |
Verifies server subscription rejections classify as server_error, exit 5. |
Review effort: Balanced
Member
Author
|
Copilot review closed: round 1 was clean (no inline comments, no headline findings, no suppressed comments), so no further rounds. |
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.
Closes #3095
Problem
InspectorClient.subscribeToResource()/unsubscribeFromResource()wrapped every failure in a plainError("Failed to subscribe to resource: …", { cause }). The CLI'sclassifyErrorreads aProtocolErroronly at the top level (deliberately, per #3086), so a server's JSON-RPC rejection ofresources/subscribeorresources/unsubscribefell to the usage catch-all:{"code":"error"}, exit 1.Fix
Both catch sites now throw through a new
subscriptionFailure(prefix, error)incore/mcp/subscriptionAck.ts:ProtocolErroris rebuilt as aProtocolError: samecodeanddata, built throughProtocolError.fromErrorso a branded subclass (ResourceNotFoundError, …) survives. It keeps the sameFailed to subscribe to resource: …message, with the original ascause.ConnectionClosedfrom reading as a server exit (the Classify server JSON-RPC errors, failed stdio starts and bad URL schemes (#3070) #3086 shape).I rebuilt the error rather than rethrowing it unwrapped (the other option the issue names). That way the TUI, the web toast and the CLI envelope keep the
Failed to subscribe…wording users already see. Only the classification changes.-32601/-32602toresources/subscribecodeerrorserver_errorjsonRpcCode/jsonRpcDataTests
clients/cli/__tests__/failure-classes.test.ts: the regression test the issue asks for. A real in-process server declares subscriptions and answersresources/subscribewith-32601and with-32602. The test drivesInspectorClient.subscribeToResource()against it, then runs the rejection throughclassifyError, and getsserver_error, exit 5, with the server'sjsonRpcCode/jsonRpcData. The one-shot CLI has noresources/subscribemethod (it is a stream method, which mcpdo serves), so the test drives the client call mcpdo makes. It fails onv2/main(exit 1) and passes here.clients/web/src/test/core/mcp/subscriptionAck.test.ts: unit tests forsubscriptionFailure. AProtocolErrorstays one, with its code, data, prefixed message and cause; a branded subclass stays branded; a non-protocol failure (incl.ConnectionClosed) stays a plain wrapper.inspectorClient-coverage-backfill.test.tspass unchanged.npm run local:gategreen.🤖 Generated with Claude Code