- Notifications
You must be signed in to change notification settings - Fork920
Python: Preserve MCP array items schema in Pydantic field generation#2382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
markwallace-microsoft commentedNov 21, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Python Test Coverage Report •
Python Unit Test Overview
| ||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Pull request overview
This PR fixes an issue where MCP tools with complex array parameters were losing theiritems schema during the MCP → Pydantic → JSON Schema conversion pipeline. The fix preserves array item schemas by storing them in Pydantic'sjson_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 viajson_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 |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
bcbf1b3Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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