fix(tools): prevent Pydantic validation error with security_context in MCP tools#4807
Closed
mvanhorn wants to merge 1 commit into
Closed
fix(tools): prevent Pydantic validation error with security_context in MCP tools#4807mvanhorn wants to merge 1 commit into
mvanhorn wants to merge 1 commit into
Conversation
…n MCP tools _add_fingerprint_metadata injects security_context AFTER the acceptable_args filtering, so it bypasses the filter and causes Pydantic ValidationError on strict MCP tool schemas that don't declare security_context. Move the call to BEFORE the filter so security_context is naturally stripped for tools that don't include it in their schema. Fixes crewAIInc#4796 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
|
Closing in favor of @Ker102's approach. The |
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.
Summary
_add_fingerprint_metadatainjectssecurity_contextinto tool arguments after theacceptable_argsfiltering, so it bypasses the filter and causesPydantic ValidationErroron strict MCP tool schemas that don't declaresecurity_contextas a valid field._add_fingerprint_metadatacall to before theacceptable_argsfiltering in both the sync and async code paths. The existing filter naturally strips any keys not in the tool's schema, sosecurity_contextis only passed to tools that explicitly declare it.Test plan
security_context-- should no longer raiseValidationErrorsecurity_contextin its schema -- should still receive the fieldFixes #4796
🤖 Generated with Claude Code
Note
Low Risk
Small, localized change to tool argument preparation that mainly affects whether extra metadata keys are forwarded; minimal behavioral risk outside of tools that relied on previously unfiltered metadata.
Overview
Prevents strict-schema (e.g., MCP) tools from failing Pydantic validation by changing when fingerprint metadata is injected into tool call arguments.
In both sync and async tool execution paths,
_add_fingerprint_metadatanow runs before filtering againsttool.args_schemaproperties, so injected keys likesecurity_contextare stripped unless explicitly allowed; the exception fallback also copies arguments before enrichment to avoid mutating the original input.Written by Cursor Bugbot for commit 5ef8ac3. This will update automatically on new commits. Configure here.