Skip to content

fix(adapters): ignore extra fields in MCP tool args schema to allow security_context#4890

Open
NIK-TIGER-BILL wants to merge 1 commit intocrewAIInc:mainfrom
NIK-TIGER-BILL:fix/mcp-adapter-security-context
Open

fix(adapters): ignore extra fields in MCP tool args schema to allow security_context#4890
NIK-TIGER-BILL wants to merge 1 commit intocrewAIInc:mainfrom
NIK-TIGER-BILL:fix/mcp-adapter-security-context

Conversation

@NIK-TIGER-BILL
Copy link

@NIK-TIGER-BILL NIK-TIGER-BILL commented Mar 15, 2026

Problem

When using MCPServerAdapter, CrewAI injects a security_context parameter into every tool call. However, MCP tools' inputSchema is defined by external servers and cannot include this internal field. The MCP adapter creates Pydantic models with the default extra="forbid" config, causing Pydantic validation to fail:

ValidationError: Extra inputs are not permitted
  security_context: extra forbidden

Fix

Pass ConfigDict(extra="ignore") when creating the args_schema for MCP tools so that CrewAI-injected fields are silently discarded before the tool receives its arguments.

# Before
args_model = create_model_from_schema(mcp_tool.inputSchema)

# After
args_model = create_model_from_schema(
    mcp_tool.inputSchema,
    __config__=ConfigDict(extra="ignore"),
)

This is scoped to the MCP adapter only — other tool types are unaffected.

Fixes #4796


Note

Low Risk
Low risk: scoped to MCP adapter schema creation and only relaxes validation for unexpected fields, with minimal behavioral impact on normal tool inputs.

Overview
Fixes MCP tool invocation failures when CrewAI injects internal fields like security_context by creating the MCP args_schema with ConfigDict(extra="ignore"), so unknown fields are dropped instead of raising Pydantic validation errors.

This change is limited to mcp_adapter.py and only affects argument validation for MCP-adapted tools.

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

…ecurity_context

CrewAI's tool execution framework injects a security_context parameter
(containing agent_fingerprint and metadata) into every tool call.
However, MCP tools' inputSchema is defined by external servers and
cannot include this internal field.

The MCP adapter was creating Pydantic models with the default
extra='forbid' config (from create_model_from_schema), causing an
'Extra inputs are not permitted' validation error whenever a MCP tool
was called.

Fix by passing ConfigDict(extra='ignore') when creating the args_schema
for MCP tools so that CrewAI-injected fields are silently discarded
before the tool receives its arguments.

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