litellm/tests/test_litellm/proxy/_experimental/mcp_server
Yassin Kortam 9832d6e4a6
fix(mcp): scan and mask MCP tool call arguments in unified guardrails (#35142)
* fix(mcp): scan and mask MCP tool call arguments in unified guardrails

A guardrail configured with mode pre_mcp_call was handed only a synthetic
tool definition (name plus an empty parameters schema), so it never saw the
argument values it was configured to inspect, and any rewrite it returned was
discarded. Detection could not fire and masking could not take effect, while
the applied-guardrails metadata still reported the guardrail as having run.

Pass every string leaf of the tool call arguments as texts, and fold the
guardrail's rewritten leaves back into modified_arguments, which is the channel
the MCP call path reads to decide what to send upstream. The leaf walk reuses
the json_string_leaves / with_json_string_leaves helpers the tool result path
already uses, so both directions share one bounded traversal.

Two guardrails running concurrently under run_in_parallel scan the same payload
snapshot, so each returns a full replacement derived from the original leaf.
Rewrites of the same leaf to different values are rejected rather than silently
losing one redaction; a leaf that already holds this guardrail's own replacement
is convergent and still masks, which is what the bundled content filter does
when it rewrites the arguments itself as well as through texts.

* fix(mcp): annotate guardrail argument rewrites

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(tests): isolate MCP guardrail callback state

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* chore: ratchet LIT010 budget after merge

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(tests): remove duplicate Bedrock hook parameter

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(mcp): fail closed when guardrail rewrites cannot be mapped to MCP arguments

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(tests): patch the guardrail translation mappings cache where staging now keeps it

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-05 20:51:25 +00:00
..
auth fix(mcp): scope allow-all servers to virtual keys (#39531) 2026-09-03 10:32:03 -07:00
faults ci: lint the test tree for undefined names and fix all 30 (#37671) 2026-08-20 13:30:34 -07:00
guardrail_translation fix(mcp): scan and mask MCP tool call arguments in unified guardrails (#35142) 2026-09-05 20:51:25 +00:00
outbound_credentials feat(mcp): renew the stored SSO identity assertion behind ID-JAG (#35401) 2026-09-05 12:43:02 -07:00
conftest.py test: trim mcp fixture docstring and reload comment 2026-09-01 11:06:08 +00:00
test_byok_oauth_endpoints.py feat(mcp): allow native MCP OAuth support for cursor (#28327) 2026-05-20 15:28:44 -07:00
test_callback_oauth_error_responses.py Litellm oss staging 250526 (#28770) 2026-05-26 11:57:39 -07:00
test_db_credentials.py fix(mcp): token refresh and M2M egress honor the admin-entered token URL 2026-08-26 15:31:45 -07:00
test_discoverable_endpoints.py fix(mcp): resolve OAuth broker endpoints by server_id with IP access checks (#39432) 2026-09-03 15:04:45 -07:00
test_gateway_dcr_flow.py fix(proxy): word database 503s by whether the fault is transient (#39256) 2026-09-02 15:05:55 -07:00
test_is_tool_name_prefixed.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_jwt_mcp_enforcement.py fix(mcp): resolve team.access_group_ids → MCP servers (#28997) 2026-05-27 12:36:50 -07:00
test_jwt_mcp_simple.py fix(mcp): resolve team.access_group_ids → MCP servers (#28997) 2026-05-27 12:36:50 -07:00
test_mcp_block_recording.py fix(guardrails): record MCP tool guardrail evaluations and blocks in usage monitor 2026-08-14 17:52:36 -04:00
test_mcp_cost_calculator.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
test_mcp_custom_fields.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
test_mcp_debug.py chore: litellm oss staging (#30968) 2026-06-23 07:31:44 -07:00
test_mcp_discovery.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
test_mcp_elicitation_handler.py Litellm oss staging 040626 (#29671) 2026-06-04 11:07:20 -07:00
test_mcp_env_vars.py fix(mcp): drop orphaned per-user credential rows when an MCP server is deleted (#30141) 2026-06-10 15:56:58 -07:00
test_mcp_guardrail_usage_monitor.py fix(guardrails): record MCP tool guardrail evaluations and blocks in usage monitor 2026-08-14 17:52:36 -04:00
test_mcp_header_alias_utils.py feat(mcp): use x-mcp-<access_group>-* headers as default upstream credentials for group members (#39717) 2026-09-04 12:45:24 -07:00
test_mcp_hook_extra_headers.py fix(mcp): keep upstream OAuth Authorization when jwt signer hook injects one on tools/call (#38555) 2026-08-27 12:44:36 -07:00
test_mcp_max_concurrent_requests.py feat(ui): expose MCP max_concurrent_requests in server create and edit forms (#32397) 2026-07-07 22:47:03 -07:00
test_mcp_metadata_preservation.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
test_mcp_oauth_passthrough.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
test_mcp_oauth_passthrough_cold_start.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
test_mcp_oauth_passthrough_tools.py fix: resolve Python 3.14 OCR annotations and remaining matrix failures 2026-09-02 14:35:38 -07:00
test_mcp_partial_update.py fix(mcp): never write discovery results to the row, heal rows a release already stamped, and retry failed discovery with backoff 2026-07-29 17:51:22 -07:00
test_mcp_sampling_completion_flow.py Litellm oss staging 040626 (#29671) 2026-06-04 11:07:20 -07:00
test_mcp_sampling_model_access.py Litellm oss staging 040626 (#29671) 2026-06-04 11:07:20 -07:00
test_mcp_sampling_model_resolution.py Litellm oss staging 040626 (#29671) 2026-06-04 11:07:20 -07:00
test_mcp_sampling_priority_selection.py Litellm oss staging 040626 (#29671) 2026-06-04 11:07:20 -07:00
test_mcp_sampling_request_builder.py Litellm oss staging 040626 (#29671) 2026-06-04 11:07:20 -07:00
test_mcp_sampling_response_conversion.py Litellm oss staging 040626 (#29671) 2026-06-04 11:07:20 -07:00
test_mcp_sampling_tool_conversion.py Litellm oss staging 040626 (#29671) 2026-06-04 11:07:20 -07:00
test_mcp_server.py feat(mcp): use x-mcp-<access_group>-* headers as default upstream credentials for group members (#39717) 2026-09-04 12:45:24 -07:00
test_mcp_server_identity_env.py test: trim mcp fixture docstring and reload comment 2026-09-01 11:06:08 +00:00
test_mcp_server_manager.py feat(mcp): warn when an oauth2_id_jag server outruns the SSO provider's assertion capture (#35394) 2026-09-05 12:43:09 -07:00
test_mcp_session_logging.py Add MCP semantic conventions to otelv2 (#29468) 2026-06-02 11:45:36 -07:00
test_mcp_sigv4_auth.py fix(mcp): persist config.yaml DCR clients in a server-scoped store 2026-07-17 19:42:32 -07:00
test_mcp_stale_session.py ci: lint the test tree for undefined names and fix all 30 (#37671) 2026-08-20 13:30:34 -07:00
test_mcp_tool_search.py feat(mcp): semantic tool search for the native MCP Gateway (#39404) 2026-09-02 15:09:44 -07:00
test_mcp_toolset_scope.py fix(mcp): use a toolset row's stored tool name as written 2026-07-24 17:06:08 -07:00
test_oauth2_flow_backfill.py feat(mcp): startup backfill stamping oauth2_flow on legacy null rows (#32290) 2026-07-06 18:42:08 -07:00
test_oauth2_token_cache.py feat(mcp): let a resolved OAuth token target a custom upstream header (#38456) 2026-08-27 14:32:01 -07:00
test_oauth_issuer_stamp_backfill.py fix(mcp): never write discovery results to the row, heal rows a release already stamped, and retry failed discovery with backoff 2026-07-29 17:51:22 -07:00
test_openapi_to_mcp_generator.py fix(mcp): stop reporting failed OpenAPI tool calls as successes (#37496) 2026-08-19 14:26:02 -07:00
test_openapi_tool_auth.py feat(mcp): let a resolved OAuth token target a custom upstream header (#38456) 2026-08-27 14:32:01 -07:00
test_proxy_api_credentials.py fix(proxy): refuse a teamless native-client grant for a user who has teams 2026-08-20 05:37:35 -07:00
test_rest_endpoints.py Merge pull request #39926 from BerriAI/litellm_lit6981_none_url_auth 2026-09-05 18:44:34 +00:00
test_semantic_tool_filter.py fix: resolve Python 3.14 OCR annotations and remaining matrix failures 2026-09-02 14:35:38 -07:00
test_short_mcp_tool_prefix.py test: require a match= on broad pytest.raises, and drop duplicate parametrize cases (#37769) 2026-08-20 20:24:49 -07:00
test_ui_session_utils.py fix(mcp): deny the interactive dcr_bridge authorize for a user without server access (#37865) 2026-08-21 12:27:00 -07:00
test_utils.py fix(mcp): drop caller host and configured upstream headers from logged metadata (#36901) 2026-08-14 17:21:07 -07:00