fix(mcp): re-nest flattened arguments for Realtime tool calls#3390
Closed
adityasingh2400 wants to merge 1 commit into
Closed
fix(mcp): re-nest flattened arguments for Realtime tool calls#3390adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
The Realtime API has no `strict` field on RealtimeFunctionTool, so models sometimes ignore an MCP tool's nested-object property and emit its inner fields at the top level (openai#1681). When the schema has exactly one missing object-typed property that can unambiguously absorb the extras, restore the nesting before forwarding to the MCP server. Ambiguous or structurally constrained schemas are left untouched.
Member
|
Thanks for sharing this idea, but this could affect any MCP server use cases and I don't think it is a right solution for the realtime agents as well. |
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.
When a RealtimeAgent calls an MCP tool whose input schema declares a nested-object property, the model frequently emits that property's fields at the top level rather than as a nested object, and the MCP server then rejects the call or silently misbehaves (#1681).
As noted in the earlier triage on the issue, this is because the OpenAI Realtime API's
RealtimeFunctionTooltype has nostrictfield — "the OpenAI Realtime API doesn't support thestrictparameter for function tools" (comment). The schema travels intact but the model is free to ignore the nesting. That part has to be fixed upstream, but the SDK can still recover the common case before forwarding to the MCP server.MCPUtil.invoke_mcp_toolnow applies a narrow re-nesting pass after JSON parsing. When the parsed arguments contain keys not declared at the top level oftool.inputSchemaand the schema has exactly one missing object-typed property that can unambiguously absorb them, the extras are moved into that property. Open-ended objects (no declaredproperties) are always eligible; typed objects are eligible only when every extra is a declared inner key; objects withadditionalProperties: falseand no inner properties are excluded. Ambiguous schemas (two or more candidate absorbers, or extras that don't match a closed inner schema) are left untouched so structured tools are not corrupted. On theSetPropertiesexample from the issue,{\"target\": \"MyTarget\", \"visible\": false}is forwarded as{\"target\": \"MyTarget\", \"keysAndValues\": {\"visible\": false}}and the call succeeds. Five tests intests/mcp/test_mcp_util.pycover the issue's case plus already-nested input, ambiguous siblings, closed inner schemas, and typed inner properties.Refs #1681