Skip to content

Conversation

@ibetitsmike
Copy link
Contributor

Problem

OpenAI chats were unable to use MCP tools because OpenAI's Responses API has stricter JSON Schema validation than other providers. MCP servers may define tool schemas with properties like minLength, maximum, default, etc. which are valid JSON Schema but cause 400 errors with OpenAI:

Invalid schema for function 'addResource': In context=('properties', 'content'), 'minLength' is not permitted.

Solution

Added a schema sanitizer that strips unsupported JSON Schema properties from MCP tool schemas when using OpenAI models. The sanitization is only applied to:

  • MCP tools (not built-in tools)
  • OpenAI provider models

Properties stripped:

  • String validation: minLength, maxLength, pattern, format
  • Number validation: minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf
  • Array validation: minItems, maxItems, uniqueItems
  • Object validation: minProperties, maxProperties
  • General: default, examples, deprecated, readOnly, writeOnly

The sanitization preserves the core schema structure (type, properties, required, etc.) and handles nested schemas including items, oneOf, anyOf, allOf, and definitions.

Testing

  • Added comprehensive unit tests for the schema sanitizer
  • All 1890 tests pass
  • Lint and typecheck pass

Generated with mux • Model: anthropic:claude-opus-4-5 • Thinking: high

OpenAI's Responses API has stricter JSON Schema validation than other
providers like Anthropic. Certain schema properties that are valid JSON
Schema but not supported by OpenAI cause 400 errors when MCP tools are used.

This change adds a schema sanitizer that strips unsupported properties from
MCP tool schemas when using OpenAI models:
- String validation: minLength, maxLength, pattern, format
- Number validation: minimum, maximum, exclusiveMinimum, exclusiveMaximum
- Array validation: minItems, maxItems, uniqueItems
- Object validation: minProperties, maxProperties
- General: default, examples, deprecated, readOnly, writeOnly

The sanitization is applied only to MCP tools and only for OpenAI models,
preserving the full schema for other providers.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

MCP tools from @ai-sdk/mcp use inputSchema with a jsonSchema getter,
not parameters like regular AI SDK tools. The sanitizer now handles
both cases to properly strip unsupported properties for OpenAI.
@ibetitsmike ibetitsmike added this pull request to the merge queue Dec 18, 2025
Merged via the queue into main with commit 6dea256 Dec 18, 2025
19 checks passed
@ibetitsmike ibetitsmike deleted the openai-mcp-fsrt branch December 18, 2025 12:59
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