Skip to content

fix: skip client-side structuredContent validation when isError is true#1690

Closed
joaquinhuigomez wants to merge 2 commits intomodelcontextprotocol:mainfrom
joaquinhuigomez:fix/skip-output-validation-on-error
Closed

fix: skip client-side structuredContent validation when isError is true#1690
joaquinhuigomez wants to merge 2 commits intomodelcontextprotocol:mainfrom
joaquinhuigomez:fix/skip-output-validation-on-error

Conversation

@joaquinhuigomez
Copy link
Copy Markdown

@joaquinhuigomez joaquinhuigomez commented Mar 17, 2026

No description provided.

When a tool with outputSchema returns isError: true along with
structuredContent that doesn't match the schema, the client-side
validation was still running and throwing, preventing the error from
reaching the caller. Now both callTool() and callToolStream() skip
schema validation for error results, matching the server-side behavior.

Fixes modelcontextprotocol#654
@joaquinhuigomez joaquinhuigomez requested a review from a team as a code owner March 17, 2026 01:49
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 17, 2026

🦋 Changeset detected

Latest commit: 696b4bf

The changes in this PR will be included in the next version bump.

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 17, 2026

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/server

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

@modelcontextprotocol/express

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 696b4bf

Copy link
Copy Markdown

@travisbreaks travisbreaks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix is correct and the logic matches what the server already does (early return on isError at mcp.ts:284). The outputSchema defines the contract for successful tool output, so validating it against error responses is a category error. Good catch on the client-side inconsistency: the "missing structuredContent" guard already checked !result.isError, but the "validate structuredContent" block didn't.

One gap in test coverage: the callToolStream test only asserts on isError and content but doesn't verify that structuredContent is preserved in the result. The callTool test does verify this (expect(result.structuredContent).toEqual({ wrongField: 123 })). Worth adding the same assertion to the stream test for parity, since the whole point is that the content passes through unmodified.

Also: changeset bot flagged this needs a changeset before merge.

Add structuredContent assertion to callToolStream test for parity with
callTool test, and add changeset file for the patch.
@joaquinhuigomez
Copy link
Copy Markdown
Author

joaquinhuigomez commented Mar 18, 2026

Added — callToolStream now includes the matching structuredContent assertion for parity with callTool. See d0bd36a.

@joaquinhuigomez joaquinhuigomez force-pushed the fix/skip-output-validation-on-error branch from d0bd36a to 696b4bf Compare March 24, 2026 20:51
@felixweinberger
Copy link
Copy Markdown
Contributor

@claude review

Comment on lines +1 to +5
---
"@modelcontextprotocol/sdk": patch
---

Skip structuredContent validation when tool result has isError: true
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 The changeset targets @modelcontextprotocol/sdk (the private root package) instead of @modelcontextprotocol/client. Since @modelcontextprotocol/sdk has "private": true, this changeset will not trigger a version bump for the published @modelcontextprotocol/client package where the actual code changes live. Change line 2 to "@modelcontextprotocol/client": patch.

Extended reasoning...

The changeset file .changeset/skip-structured-content-validation-on-error.md references "@modelcontextprotocol/sdk": patch on line 2. However, @modelcontextprotocol/sdk is the root monorepo package, which is marked "private": true in the root package.json and is never published to npm.

All code changes in this PR are in packages/client/ — specifically packages/client/src/client/client.ts and packages/client/src/experimental/tasks/client.ts. The package at that path is @modelcontextprotocol/client, which is the package that consumers actually install.

Every other changeset in this repository correctly targets specific sub-packages. For example, existing changesets reference @modelcontextprotocol/client, @modelcontextprotocol/server, @modelcontextprotocol/core, or @modelcontextprotocol/node — none of them target the root @modelcontextprotocol/sdk.

When changeset version runs, it will see the target @modelcontextprotocol/sdk, find that it is private, and skip bumping it. Since @modelcontextprotocol/client does not depend on @modelcontextprotocol/sdk, the updateInternalDependencies setting will not cascade the bump either. The net result is that this bug fix will be merged but never released as a new version of @modelcontextprotocol/client.

The fix is straightforward: change line 2 of the changeset from "@modelcontextprotocol/sdk": patch to "@modelcontextprotocol/client": patch.

Copy link
Copy Markdown
Contributor

@felixweinberger felixweinberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[deleted]

@joaquinhuigomez
Copy link
Copy Markdown
Author

Closing — issue #654 was resolved server-side by PR #655, and the client-side validation now also correctly skips structuredContent validation when isError is true (lines 885 and 893 of packages/client/src/client/client.ts on main). This fix is no longer needed. Thanks for the review feedback @travisbreaks @felixweinberger.

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.

4 participants