Skip to content

fix: type registerTool output from outputSchema#2438

Draft
Grmiade wants to merge 1 commit into
modelcontextprotocol:mainfrom
Grmiade:grmiade-register-tool-output-schema-typing
Draft

fix: type registerTool output from outputSchema#2438
Grmiade wants to merge 1 commit into
modelcontextprotocol:mainfrom
Grmiade:grmiade-register-tool-output-schema-typing

Conversation

@Grmiade

@Grmiade Grmiade commented Jul 6, 2026

Copy link
Copy Markdown

Problem

McpServer.registerTool accepts outputSchema, but its callback type only used the input schema. That meant handlers could return structuredContent that did not match the advertised output schema without any TypeScript feedback.

McpServer already validates successful tool output at runtime, so invalid structuredContent is not returned as a successful result.

This typing change catches the same mistakes earlier, while authors are implementing tools, and lets editors and CI enforce the schema contract advertised to clients.

Changes

  • Infer callback structuredContent from outputSchema when one is provided.
  • Preserve existing behavior when outputSchema is omitted.
  • Preserve existing inputSchema inference for Standard Schema and raw Zod shape inputs.
  • Support Standard Schema output schemas and raw-shape output schemas.
  • Keep runtime behavior unchanged.
  • Add focused type tests for valid and invalid structured output payloads, including non-object and raw-shape output schemas.

Validation

  • pnpm --filter @modelcontextprotocol/server typecheck
  • pnpm --filter @modelcontextprotocol/server lint
  • pnpm --filter @modelcontextprotocol/server test -- test/server/mcp.compat.test.ts
  • pnpm --filter @modelcontextprotocol/test-e2e typecheck
  • Pre-push hook: build:all, typecheck:all, lint:all

@changeset-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b3cea15

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

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/server 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 Jul 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/codemod

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

@modelcontextprotocol/core

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

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: b3cea15

@Grmiade Grmiade force-pushed the grmiade-register-tool-output-schema-typing branch 8 times, most recently from 0739864 to 3e17b26 Compare July 6, 2026 16:11
@Grmiade Grmiade changed the title fix: type registerTool structured output fix: type registerTool output from outputSchema Jul 6, 2026
@Grmiade Grmiade force-pushed the grmiade-register-tool-output-schema-typing branch from 3e17b26 to dbefcb4 Compare July 6, 2026 16:26
@Grmiade Grmiade force-pushed the grmiade-register-tool-output-schema-typing branch from dbefcb4 to b3cea15 Compare July 6, 2026 16:41
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