Skip to content

Conversation

@cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Jan 2, 2026

Summary

Fixes MCP tools (like mcp-server-fetch) failing with OpenAI providers due to strict mode schema validation.

Problem

OpenAI defaults to strict=true for function tools, which enforces:

  1. No JSON Schema format fields (e.g., "format": "uri" is rejected)
  2. All properties must be in the required array

MCP tools use standard JSON Schema conventions where optional parameters with defaults are NOT in required. This caused errors like:

openai.BadRequestError: Invalid schema for function 'fetch':
In context=('properties', 'url'), 'uri' is not a valid format.

Solution

Set strict=false for MCP tools, which bypasses OpenAI's strict mode validation and allows standard JSON Schema conventions.

This is the minimal fix - we intentionally don't strip format fields from schemas because strict=false makes OpenAI accept them as-is.

Changes

  • Add strict parameter to Tool class constructor
  • Set strict=false for MCP tools in Tool.from_mcp()
  • Make rm_param_titles() properly recursive (fixes latent bug with nested schemas)
  • Update VCR cassettes for MCP client tests

Testing

  • Tested with ChatOpenAI, ChatOpenAICompletions, and ChatAnthropic
  • All existing tests pass
  • Manual verification with mcp-server-fetch

Related

@cpsievert cpsievert force-pushed the feat/mcp-tool-compat branch 3 times, most recently from 82c0059 to 119ca37 Compare January 3, 2026 00:45
OpenAI defaults to strict=true for tools, which:
1. Rejects JSON Schema `format` fields (e.g., "format": "uri")
2. Requires all properties to be in the `required` array

MCP tools use standard JSON Schema conventions where optional parameters
(with defaults) are NOT in `required`. Setting strict=false bypasses
OpenAI's strict mode validation, allowing MCP tool schemas to work as-is.

Changes:
- Add `strict` parameter to Tool class constructor
- Set strict=false for MCP tools in Tool.from_mcp()
- Make rm_param_titles() properly recursive with isinstance check
- Update VCR cassettes for MCP client tests

Note: This does NOT strip the `format` field from schemas because
strict=false makes OpenAI accept it. This is a simpler fix that
avoids unnecessary schema mutation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@cpsievert cpsievert force-pushed the feat/mcp-tool-compat branch from 119ca37 to d780a44 Compare January 3, 2026 01:14
@cpsievert cpsievert changed the title Improve MCP tool compatibility and documentation Fix MCP tool compatibility with OpenAI strict mode Jan 3, 2026
@cpsievert cpsievert changed the title Fix MCP tool compatibility with OpenAI strict mode fix: MCP tool compatibility with OpenAI strict mode Jan 3, 2026
@cpsievert cpsievert merged commit 77c3fde into main Jan 3, 2026
9 checks passed
@cpsievert cpsievert deleted the feat/mcp-tool-compat branch January 3, 2026 01:26
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.

2 participants