mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-13 18:23:20 +00:00
test logging tests + mcp server QA checks
This commit is contained in:
@@ -828,10 +828,13 @@ class MCPServerManager:
|
||||
return [], None
|
||||
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10.0, follow_redirects=True) as client:
|
||||
response = await client.get(resource_metadata_url)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
client = get_async_httpx_client(
|
||||
llm_provider=httpxSpecialProvider.MCP,
|
||||
params={"timeout": 10.0, "follow_redirects": True},
|
||||
)
|
||||
response = await client.get(resource_metadata_url)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
except Exception as exc: # pragma: no cover - network issues
|
||||
verbose_logger.debug(
|
||||
"Failed to fetch MCP OAuth metadata from %s: %s",
|
||||
@@ -921,12 +924,13 @@ class MCPServerManager:
|
||||
|
||||
for url in candidate_urls:
|
||||
try:
|
||||
async with httpx.AsyncClient(
|
||||
timeout=10.0, follow_redirects=True
|
||||
) as client:
|
||||
response = await client.get(url)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
client = get_async_httpx_client(
|
||||
llm_provider=httpxSpecialProvider.MCP,
|
||||
params={"timeout": 10.0, "follow_redirects": True},
|
||||
)
|
||||
response = await client.get(url)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
except Exception as exc: # pragma: no cover - network issues
|
||||
verbose_logger.debug(
|
||||
"Failed to fetch authorization metadata from %s: %s",
|
||||
|
||||
@@ -61,7 +61,8 @@
|
||||
"content": "hi",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
+4
-2
@@ -19,7 +19,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
@@ -99,7 +100,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"level": "DEFAULT",
|
||||
"id": "time-09-27-51-150898_chatcmpl-b783291c-dc76-4660-bfef-b79be9d54e57",
|
||||
|
||||
+4
-2
@@ -19,7 +19,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"tags": [
|
||||
"test_tag",
|
||||
@@ -67,7 +68,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"level": "DEFAULT",
|
||||
"id": "time-07-31-28-960749_chatcmpl-f06338f0-8c49-45d8-be35-2854a89723c1",
|
||||
|
||||
+4
-2
@@ -19,7 +19,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"tags": [
|
||||
"test_tag_stream",
|
||||
@@ -67,7 +68,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"level": "DEFAULT",
|
||||
"id": "time-08-38-25-665692_chatcmpl-8b67ffb8-4326-4e1b-bf4a-f70930c11c00",
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
@@ -74,7 +75,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"level": "DEFAULT",
|
||||
"id": "time-09-59-39-362554_chatcmpl-d20ba1d9-cda6-4773-822e-921ebcd426a0",
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
@@ -66,7 +67,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"level": "DEFAULT",
|
||||
"id": "time-10-06-50-957097_chatcmpl-62d4ad7c-291b-4fc7-a8a4-3ed0fc3912a5",
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
@@ -60,7 +61,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"level": "DEFAULT",
|
||||
"id": "time-09-59-32-878577_chatcmpl-1195f870-fd4d-4e38-8dc8-99dd3da5ab0b",
|
||||
|
||||
+4
-2
@@ -19,7 +19,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
@@ -60,7 +61,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"level": "DEFAULT",
|
||||
"id": "time-09-59-36-161090_chatcmpl-1ee988c9-9133-4655-bbe4-b97ffb6e3dc9",
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
@@ -60,7 +61,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"level": "DEFAULT",
|
||||
"id": "time-09-59-32-878577_chatcmpl-1195f870-fd4d-4e38-8dc8-99dd3da5ab0b",
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
@@ -66,7 +67,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"level": "DEFAULT",
|
||||
"id": "time-09-55-28-852503_chatcmpl-131cf0da-a47b-4cd1-850b-50fa077362ac",
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
@@ -66,7 +67,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"level": "DEFAULT",
|
||||
"id": "time-09-53-53-752422_chatcmpl-e99bc1d3-a393-493f-8afe-4507c0acff15",
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
@@ -70,7 +71,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"level": "DEFAULT",
|
||||
"id": "time-09-56-35-474752_chatcmpl-9b152610-3d1e-4731-a84e-d0341ea69a0f",
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
@@ -74,7 +75,8 @@
|
||||
"content": "Hello! How can I assist you today?",
|
||||
"role": "assistant",
|
||||
"tool_calls": null,
|
||||
"function_call": null
|
||||
"function_call": null,
|
||||
"provider_specific_fields": null
|
||||
},
|
||||
"level": "DEFAULT",
|
||||
"id": "time-09-56-38-784548_chatcmpl-438c8727-86b3-44d9-9b46-42330922cf50",
|
||||
|
||||
@@ -278,6 +278,7 @@ async def test_langsmith_key_based_logging(mocker):
|
||||
"role": "assistant",
|
||||
"tool_calls": None,
|
||||
"function_call": None,
|
||||
"provider_specific_fields": None,
|
||||
},
|
||||
}
|
||||
],
|
||||
|
||||
@@ -9,13 +9,14 @@ from fastapi import HTTPException
|
||||
sys.path.insert(0, "../../../../../")
|
||||
|
||||
import httpx
|
||||
|
||||
from litellm.proxy._experimental.mcp_server.mcp_server_manager import (
|
||||
MCPServerManager,
|
||||
_deserialize_json_dict,
|
||||
)
|
||||
from litellm.proxy._types import LiteLLM_MCPServerTable, MCPTransport
|
||||
from litellm.types.mcp import MCPAuth
|
||||
from litellm.types.mcp_server.mcp_server_manager import MCPServer, MCPOAuthMetadata
|
||||
from litellm.types.mcp_server.mcp_server_manager import MCPOAuthMetadata, MCPServer
|
||||
|
||||
|
||||
class TestMCPServerManager:
|
||||
@@ -237,13 +238,9 @@ class TestMCPServerManager:
|
||||
mock_client = MagicMock()
|
||||
mock_client.get = AsyncMock(return_value=mock_response)
|
||||
|
||||
async_client_context = MagicMock()
|
||||
async_client_context.__aenter__ = AsyncMock(return_value=mock_client)
|
||||
async_client_context.__aexit__ = AsyncMock(return_value=None)
|
||||
|
||||
with patch(
|
||||
"litellm.proxy._experimental.mcp_server.mcp_server_manager.httpx.AsyncClient",
|
||||
return_value=async_client_context,
|
||||
"litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client",
|
||||
return_value=mock_client,
|
||||
):
|
||||
servers, scopes = await manager._fetch_oauth_metadata_from_resource(
|
||||
"https://protected.example.com/.well-known/oauth"
|
||||
@@ -277,10 +274,6 @@ class TestMCPServerManager:
|
||||
mock_client = MagicMock()
|
||||
mock_client.get = AsyncMock(return_value=response_obj)
|
||||
|
||||
async_client_context = MagicMock()
|
||||
async_client_context.__aenter__ = AsyncMock(return_value=mock_client)
|
||||
async_client_context.__aexit__ = AsyncMock(return_value=None)
|
||||
|
||||
mock_metadata = MCPOAuthMetadata(
|
||||
scopes=None,
|
||||
authorization_url="https://example.com/auth",
|
||||
@@ -289,8 +282,8 @@ class TestMCPServerManager:
|
||||
)
|
||||
|
||||
with patch(
|
||||
"litellm.proxy._experimental.mcp_server.mcp_server_manager.httpx.AsyncClient",
|
||||
return_value=async_client_context,
|
||||
"litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client",
|
||||
return_value=mock_client,
|
||||
), patch.object(
|
||||
manager,
|
||||
"_fetch_oauth_metadata_from_resource",
|
||||
|
||||
Reference in New Issue
Block a user