Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
giles17 merged 2 commits intomicrosoft:mainfromgiles17:mcp_tool_parameter_fix
Nov 24, 2025

Conversation

@giles17
Copy link
Contributor

@giles17giles17 commentedNov 21, 2025
edited
Loading

Motivation and Context

Fixes an issue where MCP tools with complex array parameters (likebrowser_fill_form from 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 complexitems schemas were being converted to simplelist types 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

  • The code builds clean without any errors or warnings
  • The PR follows theContribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

CopilotAI review requested due to automatic review settingsNovember 21, 2025 17:34
@github-actionsgithub-actionsbot changed the titlePreserve MCP array items schema in Pydantic field generationPython: Preserve MCP array items schema in Pydantic field generationNov 21, 2025
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commentedNov 21, 2025
edited
Loading

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _mcp.py3795884%184,194–195,216,241,256,262,266,302,371,398,432–433,435–443,445–447,450–451,497,512,530,571,584,587–588,592,602,626,629–630,634,644,675,694,696,703–704,723,725,731–734,751–755,883
TOTAL15473235284% 

Python Unit Test Overview

TestsSkippedFailuresErrorsTime
2219127 💤0 ❌0 🔥56.934s ⏱️

Copy link
Contributor

CopilotAI left a 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 afield_kwargs dictionary 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.

FileDescription
python/packages/core/agent_framework/_mcp.pyModified 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.pyAdded test case for simple array types to verify items schema is preserved in generated JSON schema

@giles17giles17 added this pull request to themerge queueNov 24, 2025
Merged via the queue intomicrosoft:main with commitbcbf1b3Nov 24, 2025
23 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@dmytrostrukdmytrostrukdmytrostruk approved these changes

@moonbox3moonbox3moonbox3 approved these changes

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Python: Function tool description propagation

4 participants

@giles17@markwallace-microsoft@dmytrostruk@moonbox3

[8]ページ先頭

©2009-2025 Movatter.jp