Repository navigation
fix(server): leave tools with an untyped outputSchema unchecked - #3204
mattzcarey wants to merge 1 commit into
Conversation
|
| Name | Type |
|---|---|
| @modelcontextprotocol/server | Minor |
| @modelcontextprotocol/client | Minor |
| @modelcontextprotocol/codemod | Minor |
| @modelcontextprotocol/core | Minor |
| @modelcontextprotocol/server-legacy | Minor |
| @modelcontextprotocol/core-internal | Patch |
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
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
registerTool's output typing (#2449) made structuredContent a required key even when the schema's output type is unknown, such as an untyped fromJsonSchema(). The type check adds nothing there, and it rejected correct code: a proxy that mirrors an upstream tool returns a plain CallToolResult, with no structuredContent when the upstream tool has no outputSchema. ToolResultFor now resolves to CallToolResult when the schema output is unknown, as before #2449. Typed schemas are checked as before, and runtime validation is unchanged.
f7a36af to
2a62bf6
Compare
There was a problem hiding this comment.
I reviewed the updated push and found no bugs. Because it loosens a compile-time check on the exported ToolResultFor type, in code owned by the SDK team, a human look is still worthwhile.
What was reviewed:
ToolResultForinpackages/server/src/server/mcp.ts: the newunknown extends ToolStructuredContent<Output>branch fires for an untypedfromJsonSchema(...),z.unknown()andany-typed outputs, and not for typed schemas or raw shapes, whose content type is neverunknown.- The proxy case: the optional
outputSchemainfers asStandardSchemaWithJSON<unknown, unknown>, falls through the raw-shape overload gate, and accepts a plainCallToolResult. - The changeset,
docs/servers/tools.md, the upgrade skill reference and the JSDoc all describe the unknown-output exemption as the type now behaves; the latest push rewords the JSDoc and shortens the test comment I commented on earlier. - I did not run the typecheck. The tests in this file are type-level, so that run is what enforces them.
Extended reasoning...
The change is one conditional branch in the ToolResultFor type in packages/server/src/server/mcp.ts, plus matching JSDoc, an edited unreleased changeset, two doc files and the type-level test file. It touches no security-sensitive surface: runtime output validation is unchanged and only compile-time typing is relaxed for schemas with an unknown output type. Reading found the type behaviour, tests and documentation consistent, and the bug hunt reported nothing. I deferred rather than approved because .github/CODEOWNERS assigns every path to the SDK team and the change is a public-API typing decision that relaxes a check. The type-level tests were read, not run.
registerToolno longer type-checks the callback result when the tool'soutputSchemahas anunknownoutput type, such as an untypedfromJsonSchema(...). Those tools take anyCallToolResultagain, as they did before #2449. Typed schemas are checked exactly as before.#2449 made
structuredContenta required key for every tool with anoutputSchema. For an untyped schema that check adds nothing, and it rejects correct code:undefinedfrom an optionaloutputSchemawhen inferring, so the callback was checked as if a schema were always present.#2449 is not released yet, so this edits its changeset in place. Runtime validation is unchanged. Tests ran, including a compile test for the proxy case that fails without the fix.