Answer -32602 Invalid params for schema-invalid spec-method requests#2492
Open
earfman wants to merge 6 commits into
Open
Answer -32602 Invalid params for schema-invalid spec-method requests#2492earfman wants to merge 6 commits into
earfman wants to merge 6 commits into
Conversation
Updated error handling to throw ProtocolError for invalid parameters instead of a generic Error.
With spec-method schema failures now answered as -32602 Invalid params, the logging:set-level:invalid-level e2e scenarios pass; the knownFailures block encoded the old -32603 surface.
Pins the fix for modelcontextprotocol#2284: logging/setLevel with a schema-invalid level answers -32602 Invalid params (not -32603 Internal error) through packages/server.
Update spec-method error responses to return -32602 for invalid parameters instead of -32603. This aligns with JSON-RPC 2.0 specifications.
🦋 Changeset detectedLatest commit: a1899fd The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
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 #2284.
Motivation and Context
When a spec-defined method (e.g.
logging/setLevel) received params that fail the method's wire schema, the server answered-32603Internal error. Per JSON-RPC 2.0, invalid method parameters are the caller's error and should be-32602Invalid params. The old surface told callers the server broke when in fact their request was malformed.Before the function-only
WireCodeccontract, the Zod parse threw out of the handler and the funnel mapped it to-32603. Custom handlers registered with a params schema already answered-32602; this change makes spec methods match that surface.Root cause is a single throw in the spec-method dispatch closure in
protocol.ts— it re-threw the schema failure as a bareError(funnelled to-32603) instead of aProtocolError(InvalidParams).How Has This Been Tested?
packages/server/test/server/specMethodInvalidParams.test.ts: aServerwith the logging capability + alogging/setLevelhandler; after the initialize handshake, sendinglogging/setLevel { level: 'not-a-level' }now yieldserror.code === -32602and a message containingInvalid params for logging/setLevel.invalid-spec-params.jsonis updated to pin-32602.knownFailuresblock forlogging:set-level:invalid-levelencoding the old-32603behavior; with the fix those e2e scenarios pass, so the staleknownFailuresentry is removed (otherwise the "expected to fail" scenarios error out).pnpm lint:allandpnpm test:allpass locally.Breaking Changes
Wire-visible: peers that matched on
-32603for schema-invalid spec-method params will now observe-32602. This is intentional and brings spec methods in line with the custom-handler path. A changeset (patchto core-internal, client, core, server) is included.Types of changes
Checklist
pnpm changeset)