Skip to content

fix: add required field to empty object schemas for OpenAI strict mode#1719

Open
guoyangzhen wants to merge 2 commits intomodelcontextprotocol:mainfrom
guoyangzhen:fix/openai-strict-required
Open

fix: add required field to empty object schemas for OpenAI strict mode#1719
guoyangzhen wants to merge 2 commits intomodelcontextprotocol:mainfrom
guoyangzhen:fix/openai-strict-required

Conversation

@guoyangzhen
Copy link

Problem

When registering a tool with an empty Zod object as inputSchema (e.g. ), the generated JSON schema omits the field. While this is valid JSON Schema, it is incompatible with OpenAI strict JSON schema mode which requires to always be present (even as an empty array ).

This causes tool registration failures when using MCP tools with OpenAI models in strict mode.

Root Cause

Zod omits the field for empty objects. The MCP SDK passes the result through without adjustment.

Fix

In , after calling , check if the result is an object type with defined but no array, and add . This ensures compatibility with OpenAI strict mode while remaining valid JSON Schema.

@guoyangzhen guoyangzhen requested a review from a team as a code owner March 20, 2026 07:21
@changeset-bot
Copy link

changeset-bot bot commented Mar 20, 2026

🦋 Changeset detected

Latest commit: 23c5598

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

pkg-pr-new bot commented Mar 20, 2026

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/server

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

@modelcontextprotocol/express

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 23c5598

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