Thanks to visit codestin.com
Credit goes to GitHub.com

Skip to content

Bug: Invalid parameters passed to pydantic Field() cause malformed schemas and deprecation warnings #79

@npkanaka

Description

@npkanaka

Summary

create_model_from_json_schema() in src/mcpadapt/utils/modeling.py passes invalid parameters (anyOf, items, enum, properties) directly to pydantic's Field() constructor. This causes:

  1. Malformed JSON schemas with empty/null values
  2. Deprecation warnings in Pydantic v2
  3. Will break in Pydantic v3 when **extra support is removed

Steps to Reproduce

  1. Create a simple JSON schema without anyOf, items, enum, or properties
  2. Observe deprecation warning:
PydanticDeprecatedSince20: Using extra keyword arguments on `Field` is deprecated 
and will be removed. Use `json_schema_extra` instead. (Extra keys: 'anyOf', 'items', 
'enum', 'properties'). Deprecated in Pydantic V2.0 to be removed in V3.0.
  1. Check generated schema - contains malformed properties

Expected Behavior

Generated schema should only contain relevant JSON schema properties:

Impact

  • Polluted JSON schemas with unnecessary empty/null properties
  • Deprecation warnings in Pydantic v2.0+
    ++
  • When using mcpadapt to wrap MCP tools for frameworks like CrewAI
  • Multi-integration scenarios where schemas are cached and regenerated
  • Type information gets lost in malformed schemas (anyOf: [] with no type)
  • Causes validation failures when boolean values are coerced to strings
    ++
  • Will break in Pydantic v3 when **extra parameter support is removed from Field()

Root Cause

Pydantic's Field() function does NOT accept:

  • anyOf - JSON schema construct, not a Field parameter
  • items - JSON schema construct for arrays
  • enum - JSON schema construct (should use Literal/Enum types instead)
  • properties - JSON schema construct for nested objects

Environment

  • mcpadapt version: v0.1.13 to v0.1.20
  • pydantic version: 2.x
  • Python version: 3.10+

Additional Context

This issue was discovered while debugging a validation failure where boolean parameters were being coerced to strings in a multi-integration setup. The malformed schemas with anyOf: [] lacked type information, causing downstream validation issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions