Skip to content

fix: ignore extra inputs on MCP tool args schema#4871

Open
gambletan wants to merge 1 commit intocrewAIInc:mainfrom
gambletan:fix/mcp-security-context-extra-inputs
Open

fix: ignore extra inputs on MCP tool args schema#4871
gambletan wants to merge 1 commit intocrewAIInc:mainfrom
gambletan:fix/mcp-security-context-extra-inputs

Conversation

@gambletan
Copy link

@gambletan gambletan commented Mar 14, 2026

Summary

Fixes #4796

MCP tools fail with Extra inputs are not permitted because CrewAI's tool execution framework injects a security_context parameter into tool call arguments, but the dynamically created Pydantic args model uses extra='forbid' (the default from create_model_from_schema), causing validation to reject the unknown field.

Changes

  • lib/crewai-tools/src/crewai_tools/adapters/mcp_adapter.py: Pass __config__=ConfigDict(extra='ignore') to create_model_from_schema() so that internally-added fields like security_context are silently discarded instead of raising a validation error.
  • Added ConfigDict to the pydantic import.

Root cause

create_model_from_schema() defaults to ConfigDict(extra="forbid"). When CrewAI injects security_context (containing agent_fingerprint and metadata) during parameter validation — before _run is called — the strict schema rejects it.

Test plan

  • Verified that create_model_from_schema accepts __config__ as an override parameter
  • MCP tool calls with security_context injection no longer raise extra_forbidden validation errors
  • MCP tools still correctly validate their declared input parameters

🤖 Generated with Claude Code


Note

Medium Risk
Loosens Pydantic validation for MCP-adapted tool inputs by ignoring unknown fields, which could mask unexpected/typoed parameters but is scoped to the MCP adapter path.

Overview
Prevents MCP tool calls from failing validation when CrewAI injects internal arguments by creating the MCP tool args_schema with ConfigDict(extra="ignore").

This updates mcp_adapter.py to pass a custom Pydantic config into create_model_from_schema (and imports ConfigDict), so extra fields like security_context are silently dropped instead of raising extra_forbidden errors.

Written by Cursor Bugbot for commit 7c7ab51. This will update automatically on new commits. Configure here.

…ontext rejection

The dynamically created Pydantic args model for MCP tools used
extra='forbid' (the default from create_model_from_schema), which caused
validation to fail with 'Extra inputs are not permitted' when CrewAI
injected security_context into tool call arguments.

Set extra='ignore' on the args model so that internally-added fields
like security_context are silently discarded instead of raising.

Fixes crewAIInc#4796
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Pydantic Validation Error with security_context in MCP Tools

1 participant