Skip to content

MCP tools with complex input schema (array) #6991

@kkutrowski

Description

@kkutrowski

What happened?

Describe the bug
The _json_schema_to_model function in autogen_core.utils._json_to_pydantic does not properly handle array items that have object schemas with properties. When an array's items schema defines an object with specific properties, those properties are not processed, resulting in models
with additionalProperties=True instead of the defined fields.

Expected Behavior

Array items with object schemas should have their properties properly converted to Pydantic model fields.

Actual Behavior

Array items with object schemas fall back to generic objects with additionalProperties=True, losing the specific field definitions.

Root Cause

In _json_schema_to_model (line 275), the function only loops through schema.get("properties", {}).items(). For arrays, the _extract_field_type method processes the items schema but doesn't recursively call _json_schema_to_model when the item schema is an object with properties.

Example

Input Schema:

  {
    "type": "object",
    "properties": {
      "users": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "name": {"type": "string"},
            "email": {"type": "string"},
            "age": {"type": "integer"}
          },
          "required": ["name", "email"]
        }
      }
    }
  }

Expected Result:
A Pydantic model where users is List[UserModel] with UserModel having name, email, and age fields.

Actual Result:
A Pydantic model where users is List[dict] with additionalProperties=True, losing the specific field structure.

Code Location

File: autogen_core/utils/_json_to_pydantic.py
Function: _extract_field_type (around line 229)
Issue: When processing item_schema, it doesn't recursively handle object schemas with properties.

Environment

  • Python version: 3.13.1
  • autogen version: 0.7.2

Which packages was the bug in?

Python Core (autogen-core)

AutoGen library version.

Python 0.7.2

Other library version.

No response

Model used

gpt-4.1

Model provider

OpenAI

Other model provider

No response

Python version

3.13

.NET version

None

Operating system

None

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions