Skip to content

Conversation

@mozmo15
Copy link

@mozmo15 mozmo15 commented Feb 9, 2026

By default, when a parse fails, the output message now prioritizes zod issues by formatting each issue as a line with its message and associated path. This is in line with zod's prettify and the current approach on main branch

Motivation and Context

Currently, when a parse against an input or output schema fails, the default value error.message that is used is unclear and bloated. In addition, with zod4, we cannot assume that error.message will have all the zod issues aggregated properly under it. Reference this for more details:
#1415

How Has This Been Tested?

I built the package and tested it in my mcp-based project by sending tool call requests that will fail, the output is a set of lines each representing a zod-issue, with custom messages appearing clearly. For example:

Invalid input: expected string, received undefined at path personalData.dateOfBirth
Invalid country of birth at path personalData.countryOfBirth  <--- custom error
Unrecognized key: "termAndConditions" at object root

Breaking Changes

There should not be any breaking changes. If some mcp-client implementations are making assumptions about error output for InvalidParams 32602 errors and running special logic based on that, they may run into issues. But I would not think that its the case since the error output format was previously also prone to vary.

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

@mozmo15 mozmo15 requested a review from a team as a code owner February 9, 2026 12:52
@changeset-bot
Copy link

changeset-bot bot commented Feb 9, 2026

⚠️ No Changeset found

Latest commit: 1ca5e84

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.

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 9, 2026

Open in StackBlitz

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

commit: 1ca5e84

@mozmo15 mozmo15 force-pushed the fix/custom-error-message branch from 81e4164 to 3dd2443 Compare February 9, 2026 13:00
@mozmo15 mozmo15 force-pushed the fix/custom-error-message branch from 3dd2443 to 1ca5e84 Compare February 9, 2026 13:00
@mozmo15
Copy link
Author

mozmo15 commented Feb 9, 2026

One thing to clarify in this PR is how strict and detailed do we want to be about path formatting? For issues with array schemas there will be an index (number) in the path array, and zod additionally handles symbols as well as somehow { key: string | number | symbol } types, which would do not seem common to me. But handling numbers is probably worthwhile using something like:

const dotPath = i.path.reduce((acc, seg, index) => {
  if (typeof seg === "number") return `${acc}[${seg}]`;
  index === 0 ? `${seg}` : `${acc}.${seg}`;
}, '');

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