Coverage for .venv/lib/python3.13/site-packages/litellm/proxy/guardrails/guardrail_hooks/mcp_end_user_permission/__init__.py: 50%
14 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 12:01 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 12:01 +0000
1from typing import TYPE_CHECKING, Any, Final, cast
3from litellm.types.guardrails import SupportedGuardrailIntegrations
5from .mcp_end_user_permission import MCPEndUserPermissionGuardrail
7if TYPE_CHECKING: 7 ↛ 8line 7 didn't jump to line 8 because the condition on line 7 was never true
8 from litellm.types.guardrails import Guardrail, LitellmParams
11def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail"):
12 import litellm
14 # Default to always-on. Only disable if the user explicitly sets default_on: false.
15 # We check the raw guardrail dict because LitellmParams normalizes None → False,
16 # making it impossible to distinguish "not set" from "explicitly false" via litellm_params.
17 _raw_default_on: Final = cast(dict[str, Any], guardrail).get("litellm_params", {}).get("default_on")
18 _default_on: Final = _raw_default_on is not False
20 _callback: Final = MCPEndUserPermissionGuardrail(
21 guardrail_name=guardrail.get("guardrail_name", ""),
22 event_hook=litellm_params.mode,
23 default_on=_default_on,
24 )
25 litellm.logging_callback_manager.add_litellm_callback(_callback)
26 return _callback
29guardrail_initializer_registry: Final = {
30 SupportedGuardrailIntegrations.MCP_END_USER_PERMISSION.value: initialize_guardrail,
31}
33guardrail_class_registry: Final = {
34 SupportedGuardrailIntegrations.MCP_END_USER_PERMISSION.value: MCPEndUserPermissionGuardrail,
35}