Skip to content

fix(mcp): isolate strict schema conversion from non-strict fallback#3199

Merged
seratch merged 1 commit intoopenai:mainfrom
adityasingh2400:fix/mcp-util-isolate-strict-conversion
May 8, 2026
Merged

fix(mcp): isolate strict schema conversion from non-strict fallback#3199
seratch merged 1 commit intoopenai:mainfrom
adityasingh2400:fix/mcp-util-isolate-strict-conversion

Conversation

@adityasingh2400
Copy link
Copy Markdown
Contributor

Summary

ensure_strict_json_schema mutates the input schema in place and may raise partway through (e.g. when a nested object has additionalProperties: true). When that happens, MCPUtil.to_function_tool catches the exception and proceeds with is_strict=False — but the schema it serves to the model has already been partially mutated, leaking strict-mode artifacts like additionalProperties: false and required: [...] onto a tool we explicitly mark as non-strict.

Repro on main:

schema = {
    "type": "object",
    "properties": {"x": {"type": "object", "additionalProperties": True}},
}
tool = MCPTool(name="test_tool", inputSchema=schema)
ft = MCPUtil.to_function_tool(tool, FakeMCPServer(), convert_schemas_to_strict=True)
# ft.strict_json_schema == False  (correct: conversion failed)
# ft.params_json_schema now contains the mutations from the failed conversion:
#   {"type": "object", "properties": {...}, "additionalProperties": False, "required": ["x"]}

The fix passes a fresh copy.deepcopy(schema) to ensure_strict_json_schema, so a partial in-place mutation cannot leak into the non-strict fallback.

Test

tests/mcp/test_mcp_util.py::test_to_function_tool_failed_strict_conversion_keeps_original_schema — fails on main with the partially-mutated schema, passes after this change.

ensure_strict_json_schema mutates the schema in place and may raise
partway through, leaving strict-mode artifacts (e.g. required or
additionalProperties: false) on a schema that to_function_tool still
serves with strict_json_schema=False.

Convert a separate deepcopy so the original schema survives a failed
strict conversion.
@github-actions github-actions Bot added bug Something isn't working feature:mcp labels May 8, 2026
@seratch
Copy link
Copy Markdown
Member

seratch commented May 8, 2026

@codex review

@seratch seratch added this to the 0.17.x milestone May 8, 2026
@seratch seratch merged commit 730ee55 into openai:main May 8, 2026
10 checks passed
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:mcp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants