fix(mcp): use extra='ignore' in _json_schema_to_pydantic to allow CrewAI-injected security_context#4815
Closed
NIK-TIGER-BILL wants to merge 1 commit into
Closed
Conversation
…wAI-injected security_context
CrewAI's tool_usage.py injects a 'security_context' field into every tool
call's arguments before Pydantic validation. MCP tools build their args
schema from the MCP server's inputSchema via create_model_from_schema(),
which defaults to ConfigDict(extra='forbid').
Since the MCP server's schema never includes 'security_context', validation
raises:
pydantic_core.ValidationError: Extra inputs are not permitted (security_context)
Fix: pass ConfigDict(extra='ignore') explicitly when creating the schema
model for MCP tools, so framework-injected fields are silently dropped
before the model receives only the fields it declared.
Closes 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
CrewAI's
tool_usage.pyinjects asecurity_contextfield into every tool call's arguments before Pydantic validation (lines 1024-1045). MCP tools build their argument schema from the MCP server'sinputSchemaviacreate_model_from_schema(), which defaults toConfigDict(extra='forbid').Since the MCP server's schema never includes
security_context, validation raises (closes #4796):Root cause
MCPToolResolver._json_schema_to_pydantic()callscreate_model_from_schema()without overriding the defaultConfigDict(extra='forbid').Fix
Pass
ConfigDict(extra='ignore')explicitly when building the schema model for MCP tools:Framework-injected fields are silently dropped before the model sees only the fields it declared. The MCP tool's own validation is unaffected.
Closes #4796
Note
Medium Risk
Relaxes Pydantic validation for MCP tool arguments by ignoring unknown fields, which could mask unexpected/typoed inputs but is scoped to MCP-derived schemas and prevents runtime failures from framework-injected metadata.
Overview
Fixes MCP tool argument validation failures by generating Pydantic models with
extra="ignore"inMCPToolResolver._json_schema_to_pydantic, allowing CrewAI-injected fields likesecurity_contextto pass through without raisingextra_forbiddenerrors.This changes MCP tool schemas created via
create_model_from_schemato silently drop unknown keys instead of rejecting them.Written by Cursor Bugbot for commit 81037f4. This will update automatically on new commits. Configure here.