mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-04 02:31:27 +00:00
resolve
This commit is contained in:
parent
869df308ef
commit
b0d0de00b1
2 changed files with 15 additions and 7 deletions
|
|
@ -1296,7 +1296,7 @@ class UpdateMCPServerRequest(LiteLLMPydanticObjectBase):
|
|||
base_command_no_ext = base_command
|
||||
for ext in [".exe", ".cmd", ".bat", ".com"]:
|
||||
if base_command.lower().endswith(ext):
|
||||
base_command_no_ext = base_command[: -len(ext)]
|
||||
base_command_no_ext = base_command[: -len(ext)].lower()
|
||||
break
|
||||
if (
|
||||
base_command not in MCP_STDIO_ALLOWED_COMMANDS
|
||||
|
|
|
|||
|
|
@ -30,24 +30,32 @@ async def test_auth_context_persistence():
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_or_extract_auth_context_fallback():
|
||||
"""Test get_or_extract_auth_context fallback to server object."""
|
||||
"""Test get_or_extract_auth_context fallback to session read_stream."""
|
||||
from litellm.proxy._experimental.mcp_server.server import (
|
||||
server,
|
||||
MCPAuthenticatedUser,
|
||||
auth_context_var,
|
||||
)
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
auth_data = UserAPIKeyAuth(api_key="fallback-key")
|
||||
auth_user = MCPAuthenticatedUser(user_api_key_auth=auth_data)
|
||||
|
||||
# Set on server object
|
||||
server._litellm_auth_context = auth_user
|
||||
# Mock request_ctx.get().session._read_stream._litellm_auth_context
|
||||
mock_session = MagicMock()
|
||||
mock_read_stream = MagicMock()
|
||||
mock_read_stream._litellm_auth_context = auth_user
|
||||
mock_session._read_stream = mock_read_stream
|
||||
|
||||
mock_request_ctx = MagicMock()
|
||||
mock_request_ctx.get.return_value.session = mock_session
|
||||
|
||||
# Ensure ContextVar is empty
|
||||
token = auth_context_var.set(None)
|
||||
try:
|
||||
result = await get_or_extract_auth_context()
|
||||
assert result[0].api_key == "fallback-key"
|
||||
with patch("mcp.server.lowlevel.server.request_ctx", mock_request_ctx):
|
||||
result = await get_or_extract_auth_context()
|
||||
assert result[0] is not None
|
||||
assert result[0].api_key == "fallback-key"
|
||||
finally:
|
||||
auth_context_var.reset(token)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue