Python: Preserve MCP array items schema in Pydantic field generation#2382
Merged
giles17 merged 2 commits intomicrosoft:mainfrom Nov 24, 2025
Merged
Python: Preserve MCP array items schema in Pydantic field generation#2382giles17 merged 2 commits intomicrosoft:mainfrom
giles17 merged 2 commits intomicrosoft:mainfrom
Conversation
Member
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where MCP tools with complex array parameters were losing their items schema during the MCP → Pydantic → JSON Schema conversion pipeline. The fix preserves array item schemas by storing them in Pydantic's json_schema_extra field attribute.
Key Changes:
- Modified
_get_input_model_from_mcp_tool()to preserve array items schema usingjson_schema_extra - Refactored field definition creation logic to use a
field_kwargsdictionary approach - Added test for simple array types to verify items schema preservation
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
python/packages/core/agent_framework/_mcp.py |
Modified field definition logic to preserve array items schema via json_schema_extra and refactored field creation to use a kwargs-based approach |
python/packages/core/tests/core/test_mcp.py |
Added test case for simple array types to verify items schema is preserved in generated JSON schema |
dmytrostruk
approved these changes
Nov 21, 2025
moonbox3
approved these changes
Nov 24, 2025
arisng
pushed a commit
to arisng/agent-framework
that referenced
this pull request
Feb 2, 2026
…icrosoft#2382) * mcp tool parameter fix * small fixes
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.
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