mirror of
https://github.com/tiennm99/litellm.git
synced 2026-07-11 07:05:00 +00:00
fix(mypy): resolve type errors introduced by MCP user permissions (#21462)
- Cast `guardrail` to `Dict[str, Any]` in `mcp_end_user_permission/__init__.py`
to fix "No overload variant of 'get' matches argument type 'str'" — the
`Guardrail` TypedDict's `.get()` overloads resolve the key type to `Never`
when chained with a `{}` default, making further `.get()` calls fail.
- Cast `fn` to `Dict[str, Any]` in `transformation.py`
`transform_chat_completion_tool_params_to_responses_api_tools` to fix
'"object" has no attribute "get"' — `tool.get("function")` on
`Union[ChatCompletionFunctionToolParam, OpenAIMcpServerTool]` returns
`object` because `"function"` is not a key in `OpenAIMcpServerTool`.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Any, Dict, cast
|
||||
|
||||
from litellm.types.guardrails import SupportedGuardrailIntegrations
|
||||
|
||||
@@ -14,7 +14,7 @@ def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail"
|
||||
# Default to always-on. Only disable if the user explicitly sets default_on: false.
|
||||
# We check the raw guardrail dict because LitellmParams normalizes None → False,
|
||||
# making it impossible to distinguish "not set" from "explicitly false" via litellm_params.
|
||||
_raw_default_on = guardrail.get("litellm_params", {}).get("default_on")
|
||||
_raw_default_on = cast(Dict[str, Any], guardrail).get("litellm_params", {}).get("default_on")
|
||||
_default_on = False if _raw_default_on is False else True
|
||||
|
||||
_callback = MCPEndUserPermissionGuardrail(
|
||||
|
||||
@@ -1349,7 +1349,7 @@ class LiteLLMCompletionResponsesConfig:
|
||||
result.append(tool) # type: ignore
|
||||
continue
|
||||
if tool.get("type") == "function":
|
||||
fn = tool.get("function") or {}
|
||||
fn: Dict[str, Any] = cast(Dict[str, Any], tool.get("function") or {})
|
||||
parameters = dict(fn.get("parameters", {}) or {})
|
||||
if not parameters or "type" not in parameters:
|
||||
parameters["type"] = "object"
|
||||
|
||||
Reference in New Issue
Block a user