mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
test(mcp): check the tool dict conversion without patching the MCP handler
This commit is contained in:
parent
e60e642290
commit
2fa9627261
1 changed files with 4 additions and 24 deletions
|
|
@ -2240,16 +2240,12 @@ async def test_semantic_filter_hook_narrows_only_references_the_gateway_serves()
|
|||
assert narrowed == [{**gateway_reference, "allowed_tools": ["srv-tool_1"]}, external_tool]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_expand_mcp_tools_returns_every_expanded_tool_as_a_dict():
|
||||
def test_tool_as_dict_returns_every_expanded_tool_shape_as_a_dict():
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from litellm.proxy._types import UserAPIKeyAuth
|
||||
from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook
|
||||
from litellm.proxy.mcp_server.semantic_tool_filter import SemanticMCPToolFilter
|
||||
from litellm.responses.mcp.litellm_proxy_mcp_handler import LiteLLM_Proxy_MCP_Handler
|
||||
from litellm.proxy.hooks.mcp_semantic_filter.hook import _tool_as_dict
|
||||
|
||||
class _FunctionTool(BaseModel):
|
||||
model_config = ConfigDict(frozen=True)
|
||||
|
|
@ -2268,32 +2264,16 @@ async def test_expand_mcp_tools_returns_every_expanded_tool_as_a_dict():
|
|||
|
||||
plain_tool = {"type": "function", "name": "plain_tool", "parameters": {"type": "object"}}
|
||||
unknown_tool = "opaque-tool"
|
||||
pipeline_output = [
|
||||
expanded_tools = (
|
||||
_FunctionTool(type="function", name="v2_tool"),
|
||||
_LegacyFunctionTool("legacy_tool"),
|
||||
plain_tool,
|
||||
unknown_tool,
|
||||
]
|
||||
auth = UserAPIKeyAuth(api_key="hashed-key")
|
||||
gateway_reference = {"type": "mcp", "server_url": "litellm_proxy", "require_approval": "never"}
|
||||
|
||||
hook = SemanticToolFilterHook(
|
||||
SemanticMCPToolFilter(embedding_model="text-embedding-3-small", litellm_router_instance=Mock())
|
||||
)
|
||||
with patch.object(
|
||||
LiteLLM_Proxy_MCP_Handler,
|
||||
"process_mcp_tools_to_openai_format",
|
||||
new=AsyncMock(return_value=(pipeline_output, {})),
|
||||
) as process_tools:
|
||||
expanded = await hook._expand_mcp_tools([gateway_reference], auth)
|
||||
|
||||
assert expanded == [
|
||||
assert [_tool_as_dict(tool) for tool in expanded_tools] == [
|
||||
{"type": "function", "name": "v2_tool"},
|
||||
{"type": "function", "name": "legacy_tool"},
|
||||
plain_tool,
|
||||
unknown_tool,
|
||||
]
|
||||
assert process_tools.await_args.kwargs == {
|
||||
"user_api_key_auth": auth,
|
||||
"mcp_tools_with_litellm_proxy": [gateway_reference],
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue