Skip to content

fix(server): check tool callback output schemas - #2800

Open
hngpt52 wants to merge 1 commit into
modelcontextprotocol:mainfrom
hngpt52:codex/fix-2754-output-schema-types
Open

fix(server): check tool callback output schemas#2800
hngpt52 wants to merge 1 commit into
modelcontextprotocol:mainfrom
hngpt52:codex/fix-2754-output-schema-types

Conversation

@hngpt52

@hngpt52 hngpt52 commented Sep 12, 2026

Copy link
Copy Markdown

Closes #2754.

A tool declaring outputSchema: z.object({ data: z.string() }) currently accepts a callback returning structuredContent: "pong". That compiles and only fails when the tool runs. This change makes the mismatch a TypeScript error; returning { data: "pong" } compiles.

The registration overloads now carry the inferred output schema into callback result types. Successful results require matching, defined structured content, including when the schema output is unknown. Error and input-required results remain valid, and registrations without an output schema keep their existing broad result type. The change covers Standard Schema providers and deprecated raw Zod shapes; runtime validation and serialization are unchanged.

Compiler regressions cover valid and invalid output, sync/async callbacks, input inference, exceptional branches, non-object roots, coercion, and ArkType/Valibot. The provider assertions run in the server package's CI typecheck. ESM/CJS consumer checks exercise the built declarations with skipLibCheck: false. Deliberately malformed runtime fixtures remain in place with explicit casts so runtime rejection is still tested.

The tool guide and API comments explain the output contract, including defaults/coercion and the fact that validation does not replace returned values with parsed data. A server patch changeset calls out the stricter compile-time behavior.

Validation

Local environment: macOS, Node 25.6.1, pnpm 10.26.1, clean worktree based on b6542615.

  • pnpm install --frozen-lockfile
  • pnpm run check:all — passes, including workspace typechecks, lint, TypeDoc, and VitePress.
  • pnpm run build:all
  • pnpm --filter @modelcontextprotocol/server exec tsc -p tsconfig.json --noEmit
  • node scripts/smoke-dist-types.mjs — ESM and CJS pass.
  • pnpm -r --filter '!@modelcontextprotocol/test-e2e' test — 4,233 tests pass.
  • git diff --check

The full e2e run finished with 2,640 passed, 147 expected failures, one failure in protocol:timeout:max-total [sse 2026-07-28] (ticks.length was 0), and two unhandled request timeouts. Running the unchanged SSE timeout cases on pristine upstream b6542615 also exits nonzero with the same two unhandled timeouts; the assertion failure did not recur in that focused baseline run. No protocol timing code is changed here. The hosted Node 20/22/24 test and e2e matrix subsequently passed; see the CI results below.

CI results

All 14 reported checks passed for commit d5669c47:

@hngpt52
hngpt52 requested a review from a team as a code owner September 12, 2026 22:18
@changeset-bot

changeset-bot Bot commented Sep 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d5669c4

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

This PR includes changesets to release 6 packages
Name Type
@modelcontextprotocol/server Patch
@modelcontextprotocol/client Patch
@modelcontextprotocol/codemod Patch
@modelcontextprotocol/core Patch
@modelcontextprotocol/server-legacy Patch
@modelcontextprotocol/core-internal Patch

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

pkg-pr-new Bot commented Sep 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@2800

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@2800

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@2800

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@2800

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@2800

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@2800

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@2800

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@2800

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@2800

commit: d5669c4

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.

[v2] Should raise error at build time if zod outputSchema is not consistent with the structuredContent type

1 participant