mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-02 02:11:58 +00:00
fix: make MCP list tools lenient
This commit is contained in:
parent
b9b919d1a1
commit
9b382e404c
2 changed files with 15 additions and 1 deletions
|
|
@ -43,6 +43,8 @@ from mcp.types import (
|
|||
ListResourceTemplatesResult,
|
||||
ListResourcesRequest,
|
||||
ListResourcesResult,
|
||||
ListToolsRequest,
|
||||
ListToolsResult,
|
||||
Prompt,
|
||||
ResourceTemplate,
|
||||
TextContent,
|
||||
|
|
@ -91,6 +93,10 @@ def _first_non_cancelled_cause(exc: BaseException) -> Optional[BaseException]:
|
|||
TSessionResult = TypeVar("TSessionResult")
|
||||
|
||||
|
||||
class _LenientListToolsResult(ListToolsResult):
|
||||
tools: List[MCPTool] = Field(default_factory=list)
|
||||
|
||||
|
||||
class _LenientListPromptsResult(ListPromptsResult):
|
||||
prompts: List[Prompt] = Field(default_factory=list)
|
||||
|
||||
|
|
@ -531,7 +537,10 @@ class MCPClient:
|
|||
)
|
||||
|
||||
async def _list_tools_operation(session: ClientSession):
|
||||
return await session.list_tools()
|
||||
return await session.send_request(
|
||||
ClientRequest(ListToolsRequest()),
|
||||
_LenientListToolsResult,
|
||||
)
|
||||
|
||||
try:
|
||||
result = await self.run_with_session(_list_tools_operation)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ from mcp.types import (
|
|||
ListPromptsRequest,
|
||||
ListResourceTemplatesRequest,
|
||||
ListResourcesRequest,
|
||||
ListToolsRequest,
|
||||
)
|
||||
from litellm.types.mcp import MCPAuth, MCPStdioConfig, MCPTransport
|
||||
|
||||
|
|
@ -30,6 +31,9 @@ class _MissingListResultSession:
|
|||
self.requests.append((request, result_type))
|
||||
return result_type.model_validate({})
|
||||
|
||||
async def list_tools(self):
|
||||
raise AssertionError("strict list_tools should not be used")
|
||||
|
||||
async def list_prompts(self):
|
||||
raise AssertionError("strict list_prompts should not be used")
|
||||
|
||||
|
|
@ -74,6 +78,7 @@ class TestMCPClient:
|
|||
@pytest.mark.parametrize(
|
||||
("client_method", "request_type"),
|
||||
[
|
||||
("list_tools", ListToolsRequest),
|
||||
("list_prompts", ListPromptsRequest),
|
||||
("list_resources", ListResourcesRequest),
|
||||
("list_resource_templates", ListResourceTemplatesRequest),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue