Skip to content

Conversation

@giles17
Copy link
Contributor

@giles17 giles17 commented Nov 21, 2025

Motivation and Context

Fixes an issue where MCP tools with complex array parameters (like browser_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 complex items schemas were being converted to simple list 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 the Contribution 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.

Copilot AI review requested due to automatic review settings November 21, 2025 17:34
@github-actions github-actions bot changed the title Preserve MCP array items schema in Pydantic field generation Python: Preserve MCP array items schema in Pydantic field generation Nov 21, 2025
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Nov 21, 2025

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

Tests Skipped Failures Errors Time
2219 127 💤 0 ❌ 0 🔥 56.934s ⏱️

Copilot finished reviewing on behalf of giles17 November 21, 2025 17:36
Copy link
Contributor

Copilot AI 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 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 using json_schema_extra
  • Refactored field definition creation logic to use a field_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.

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

@giles17 giles17 added this pull request to the merge queue Nov 24, 2025
Merged via the queue into microsoft:main with commit bcbf1b3 Nov 24, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Function tool description propagation

4 participants