Python: Preserve MCP array items schema in Pydantic field generation #2382
+50
−8
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.
Motivation and Context
Fixes an issue where MCP tools with complex array parameters (like
browser_fill_formfrom Playwright MCP) were losing their array items schema during the MCP → Pydantic → JSON Schema conversion pipeline, causing LLMs to receive incomplete parameter information.When converting MCP tool schemas to Pydantic models, array parameters with complex
itemsschemas were being converted to simplelisttypes without preserving the detailed structure of array items. This resulted in LLMs receiving incomplete schemas and making wrong function calls.Before Fix:
{ "type": "function", "function": { "name": "browser_fill_form", "description": "Fill multiple form fields", "parameters": { "properties": { "fields": { "description": "Fields to fill in", "items": {}, "title": "Fields", "type": "array" } }, "required": [ "fields" ], "title": "browser_fill_form_input", "type": "object" } } }After Fix:
{ "type": "function", "function": { "name": "browser_fill_form", "description": "Fill multiple form fields", "parameters": { "properties": { "fields": { "description": "Fields to fill in", "items": { "additionalProperties": false, "properties": { "name": { "description": "Human-readable field name", "type": "string" }, "type": { "description": "Type of the field", "enum": [ "textbox", "checkbox", "radio", "combobox", "slider" ], "type": "string" }, "ref": { "description": "Exact target field reference from the page snapshot", "type": "string" }, "value": { "description": "Value to fill in the field. If the field is a checkbox, the value should be `true` or `false`. If the field is a combobox, the value should be the text of the option.", "type": "string" } }, "required": [ "name", "type", "ref", "value" ], "type": "object" }, "title": "Fields", "type": "array" } }, "required": [ "fields" ], "title": "browser_fill_form_input", "type": "object" } } }Resolves #1869
Description
Contribution Checklist