fix: add required field to empty object schemas for OpenAI strict mode#1719
Open
guoyangzhen wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
fix: add required field to empty object schemas for OpenAI strict mode#1719guoyangzhen wants to merge 2 commits intomodelcontextprotocol:mainfrom
guoyangzhen wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
🦋 Changeset detectedLatest 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 |
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.