mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-15 23:31:29 +00:00
resolve
This commit is contained in:
parent
0d00c1df49
commit
4abbe8370f
2 changed files with 15 additions and 1 deletions
|
|
@ -472,8 +472,10 @@ async def handle_sampling_create_message(
|
|||
if openai_tool_choice is not None:
|
||||
completion_kwargs["tool_choice"] = openai_tool_choice
|
||||
# 5. Add metadata for tracking
|
||||
completion_kwargs["metadata"] = {}
|
||||
if params.metadata:
|
||||
completion_kwargs["metadata"] = params.metadata
|
||||
# We nest MCP metadata to avoid collisions with internal LiteLLM auth keys
|
||||
completion_kwargs["metadata"]["mcp_metadata"] = params.metadata
|
||||
|
||||
# 6. Inject auth context for cost tracking
|
||||
if user_api_key_auth:
|
||||
|
|
@ -536,10 +538,14 @@ async def handle_sampling_create_message(
|
|||
from litellm.exceptions import (
|
||||
AuthenticationError,
|
||||
BudgetExceededError,
|
||||
ContextWindowExceededError,
|
||||
PermissionDeniedError,
|
||||
RateLimitError,
|
||||
ServiceUnavailableError,
|
||||
)
|
||||
|
||||
# Re-raise known LiteLLM errors so they can be handled by the proxy's
|
||||
# global exception handlers or retry logic if applicable.
|
||||
if isinstance(
|
||||
e,
|
||||
(
|
||||
|
|
@ -547,6 +553,8 @@ async def handle_sampling_create_message(
|
|||
RateLimitError,
|
||||
AuthenticationError,
|
||||
PermissionDeniedError,
|
||||
ContextWindowExceededError,
|
||||
ServiceUnavailableError,
|
||||
),
|
||||
):
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -471,6 +471,11 @@ async def test_sse_mcp_handler_mock():
|
|||
mock_server.run = AsyncMock()
|
||||
mock_server.create_initialization_options = MagicMock()
|
||||
|
||||
# Mock the gateway request scope as an async context manager
|
||||
mock_scope_manager = MagicMock()
|
||||
mock_scope_manager.__aenter__ = AsyncMock()
|
||||
mock_scope_manager.__aexit__ = AsyncMock()
|
||||
|
||||
with (
|
||||
patch(
|
||||
"litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED",
|
||||
|
|
@ -490,6 +495,7 @@ async def test_sse_mcp_handler_mock():
|
|||
),
|
||||
patch(
|
||||
"litellm.proxy._experimental.mcp_server.server._gateway_initialize_instructions_request_scope",
|
||||
return_value=mock_scope_manager,
|
||||
),
|
||||
patch(
|
||||
"litellm.proxy._experimental.mcp_server.server.set_auth_context",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue