Skip to content

Comments

fix: use unprefixed message for JSON-RPC wire serialization (-32042)#1578

Open
evalstate wants to merge 2 commits intomodelcontextprotocol:mainfrom
evalstate:fix/rpc-error-message-prefix
Open

fix: use unprefixed message for JSON-RPC wire serialization (-32042)#1578
evalstate wants to merge 2 commits intomodelcontextprotocol:mainfrom
evalstate:fix/rpc-error-message-prefix

Conversation

@evalstate
Copy link
Member

This fix allows the URL Elicitation details to be handled by the Client SDK in the case of a -32042 style error.

Adds integration test validating exact wire format for -32042 URLElicitationRequiredError including:

  • Clean (unprefixed) error.message on the wire
  • Correct error.data.elicitations structure
  • Single-prefix on client-side reconstructed Error.message

Motivation and Context

URL Elicitations via the -32042 error path can't be processed via the Client SDK.

How Has This Been Tested?

Tested with inspector branch.

Breaking Changes

No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

ProtocolError constructor sets Error.message to 'MCP error {code}: {message}'
for developer DX, but protocol.ts was using this prefixed string as the
JSON-RPC error.message on the wire. This caused:

1. Non-spec-conformant wire messages (spec examples show clean messages)
2. Double-prefixed messages on client reconstruction via ProtocolError.fromError()
   ('MCP error -32042: MCP error -32042: ...')

Fix: store the original unprefixed message as ProtocolError.rpcMessage and
use it in the protocol serialization path. Error.message retains the prefix
for developer-facing console/stack output.

Adds integration test validating exact wire format for -32042
URLElicitationRequiredError including:
- Clean (unprefixed) error.message on the wire
- Correct error.data.elicitations structure
- Single-prefix on client-side reconstructed Error.message
@evalstate evalstate requested a review from a team as a code owner February 24, 2026 13:15
@changeset-bot
Copy link

changeset-bot bot commented Feb 24, 2026

⚠️ No Changeset found

Latest commit: 411d929

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 24, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1578

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1578

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1578

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1578

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1578

commit: 411d929

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