Repository navigation
fix(model_armor): scan MCP tool calls for pre_mcp_call / during_mcp_call modes - #32278
eugene-yao-zocdoc wants to merge 7 commits into
Conversation
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
…all modes ModelArmorGuardrail.async_pre_call_hook and async_moderation_hook hardcoded their inner should_run_guardrail event type to pre_call / during_call. The central dispatcher already remaps call_mcp_tool -> pre_mcp_call/during_mcp_call and passes the outer gate, but Model Armor's redundant inner gate then rejected MCP calls for a guardrail configured with mode pre_mcp_call/during_mcp_call, so tool-call content was silently skipped. Remap call_mcp_tool -> pre_mcp_call/during_mcp_call in both hooks, matching the existing behavior of the noma and cisco guardrails. Adds regression tests covering both hooks (scan runs on MCP calls, still skipped for chat traffic). Generated with AI Co-Authored-By: Claude Code
|
|
Greptile SummaryThis PR fixes
Confidence Score: 4/5The production change is a minimal, correct two-location fix — the pattern is established by several sibling guardrails and carries low regression risk. The only gate to merge is that the added regression tests have not been run. The fix itself is straightforward and matches patterns already present in noma, cisco, and unified guardrails. The new regression tests are structurally sound and mock-only, but the PR explicitly states they were never executed in the authoring environment, leaving the verification step incomplete before merge. The test file needs a CI/local run before merging — the author flagged it as unverified. The production file is clean.
|
| Filename | Overview |
|---|---|
| litellm/proxy/guardrails/guardrail_hooks/model_armor/model_armor.py | Adds call_mcp_tool → pre_mcp_call/during_mcp_call remapping in both async_pre_call_hook and async_moderation_hook, matching the pattern already used by noma, cisco, and unified guardrails. |
| tests/test_litellm/proxy/guardrails/guardrail_hooks/test_model_armor.py | Adds 4 regression tests for the MCP call-type remapping (scan/skip for both pre- and during- hooks). Tests are mock-only and correct structurally, but the PR author explicitly states they were not executed before submission. |
Reviews (1): Last reviewed commit: "fix(model_armor): scan MCP tool calls fo..." | Re-trigger Greptile
| "metadata": {"guardrails": ["model-armor-test"]}, | ||
| "mcp_tool_name": tool_name, | ||
| "mcp_arguments": arguments, | ||
| } |
There was a problem hiding this comment.
Tests not confirmed to pass before merge
The PR description explicitly notes: "
Rule Used: What: Ensure that any PR claiming to fix an issue ... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Tests pass and are now confirmed — I've updated the PR description to remove the "not run before merge" note.
Verified by reverting only the model_armor.py change and re-running: the two MCP-scan tests fail (AssertionError: Expected 'mock' to have been called); with the fix restored, the targeted tests pass and the full file is 72 passed, 3 skipped. ruff format --check reports the file already formatted.
The two "scans" tests are true regression tests for this bug; the two "skips" tests are scoping guards confirming the remap is MCP-only. The fix has also been validated in a live dev deployment, where MCP tool calls configured for pre_mcp_call / during_mcp_call are now scanned (previously silently skipped).
- eugene-yao-zocdoc via Claude
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 9374b40. Configure here.
Type
🐛 Bug Fix
Summary
A Model Armor guardrail configured with mode
pre_mcp_call(orduring_mcp_call) does not scan MCP tool calls — the tool name/arguments pass through completely unscanned.Root cause
ModelArmorGuardrail.async_pre_call_hookandasync_moderation_hookhardcode their innershould_run_guardrailevent type topre_call/during_call:The central dispatcher (
ProxyLogging._process_guardrail_callback/during_call_hookinlitellm/proxy/utils.py) already remapscall_mcp_tool→pre_mcp_call/during_mcp_calland passes the outer gate. But Model Armor's redundant inner gate then re-checks against the un-remappedpre_call/during_call, so a guardrail whose configured mode ispre_mcp_callfails its own inner check and the scan is skipped.Fix
Remap
call_mcp_tool→pre_mcp_call/during_mcp_callin both hooks, matching the behavior already present in thenomaandciscoguardrails:(and the analogous
during_call→during_mcp_callinasync_moderation_hook).Scope: this scans the MCP tool name/arguments on the
pre_mcp_call/during_mcp_callhooks. It does not scan MCP tool results — there is nopost_mcp_callevent and MCP output scanning is a separate, pre-existing framework gap (MCPGuardrailTranslationHandler.process_output_responseis a documented no-op), unchanged by this PR.Tests
Adds 4 tests in
tests/test_litellm/proxy/guardrails/guardrail_hooks/test_model_armor.py:pre_mcp_callguardrail scans an MCP tool call (call_type=call_mcp_tool), and the same for theduring_mcp_call/async_moderation_hookpath. Both fail without this fix.call_type=completion), proving the remap is scoped to MCP call types and not applied blanket.Test plan
The tests pass, and the two regression tests genuinely gate this bug — verified by reverting only the
model_armor.pychange and re-running: the two "scans" tests fail (AssertionError: Expected 'mock' to have been called); with the fix restored they pass.This fix has also been validated in a live dev deployment: with a Model Armor guardrail configured for
pre_mcp_call/during_mcp_call, MCP tool calls are now scanned (previously silently skipped).Note
Medium Risk
Changes guardrail enforcement on MCP tool calls (security-sensitive); scope is small and aligned with existing proxy/guardrail MCP handling, with regression tests.
Overview
Fixes a security gap where Model Armor guardrails configured for
pre_mcp_callorduring_mcp_calldid not run on MCP tool invocations becauseasync_pre_call_hookandasync_moderation_hookalways gated onpre_call/during_call, so the innershould_run_guardrailcheck failed and scans were skipped.model_armor.pynow mapscall_type == call_mcp_tooltopre_mcp_callin the pre-call hook andduring_mcp_callin the moderation hook (same pattern as other guardrails such as Cisco). MCP traffic is still represented as synthetic user messages for the existing text-scan path; ordinarycompletioncalls are unchanged.Adds four tests (MCP scans vs chat skipped) for both hook paths.
Reviewed by Cursor Bugbot for commit 9374b40. Bugbot is set up for automated code reviews on this repo. Configure here.