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
Open
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
MCPServerAdapter, CrewAI injects asecurity_contextparameter into every tool call. However, MCP tools'inputSchemais defined by external servers and cannot include this internal field. The MCP adapter creates Pydantic models with the defaultextra="forbid"config, causing Pydantic validation to fail:Fix
Pass
ConfigDict(extra="ignore")when creating theargs_schemafor MCP tools so that CrewAI-injected fields are silently discarded before the tool receives its arguments.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_contextby creating the MCPargs_schemawithConfigDict(extra="ignore"), so unknown fields are dropped instead of raising Pydantic validation errors.This change is limited to
mcp_adapter.pyand only affects argument validation for MCP-adapted tools.Written by Cursor Bugbot for commit 9a37dec. This will update automatically on new commits. Configure here.