mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-10 08:28:25 +00:00
* refactor(mcp): drop the experimental label from the MCP server and client paths Move litellm/proxy/_experimental/mcp_server to litellm/proxy/mcp_server and litellm/experimental_mcp_client to litellm/mcp_client, with the mirrored tests moved under tests/unit/proxy/mcp_server and tests/unit/mcp_client. Both old packages stay as shims that warn with DeprecationWarning, re-export the new package's public names and alias every submodule in sys.modules so deep imports keep resolving to the same objects. The OpenAPI docs gate now puts the merge base's enterprise package on PYTHONPATH so its base counts do not mix the checked-out enterprise code with the base litellm tree Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * ci(mcp): keep tests/unit/proxy/_experimental as a sharded root for the shim tests Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(mcp): alias namespace subpackages and bind attributes in the deprecated MCP shims pkgutil.walk_packages skipped mcp_server/auth because it has no __init__.py, so old imports of litellm.proxy._experimental.mcp_server.auth.* failed, and sys.modules entries alone left litellm.experimental_mcp_client.tools unreachable as an attribute. Walk the package on disk and setattr each alias on its old parent. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
89 lines
2.4 KiB
Python
89 lines
2.4 KiB
Python
import json
|
|
|
|
import pytest
|
|
|
|
from litellm.proxy.mcp_server.tool_registry import MCPToolRegistry
|
|
|
|
|
|
# Test handler function
|
|
def example_handler(input_data):
|
|
return {"result": input_data}
|
|
|
|
|
|
def test_register_and_get_tool():
|
|
registry = MCPToolRegistry()
|
|
|
|
# Test registering a tool
|
|
registry.register_tool(
|
|
name="test_tool",
|
|
description="A test tool",
|
|
input_schema={"type": "object", "properties": {"test": {"type": "string"}}},
|
|
handler=example_handler,
|
|
)
|
|
|
|
# Test getting the registered tool
|
|
tool = registry.get_tool("test_tool")
|
|
assert tool is not None
|
|
assert tool.name == "test_tool"
|
|
assert tool.description == "A test tool"
|
|
assert callable(tool.handler)
|
|
|
|
# Test getting non-existent tool
|
|
assert registry.get_tool("non_existent") is None
|
|
|
|
|
|
def test_list_tools():
|
|
registry = MCPToolRegistry()
|
|
|
|
# Register multiple tools
|
|
registry.register_tool(
|
|
name="tool1", description="Tool 1", input_schema={}, handler=example_handler
|
|
)
|
|
registry.register_tool(
|
|
name="tool2", description="Tool 2", input_schema={}, handler=example_handler
|
|
)
|
|
|
|
# Test listing tools
|
|
tools = registry.list_tools()
|
|
assert len(tools) == 2
|
|
assert {tool.name for tool in tools} == {"tool1", "tool2"}
|
|
|
|
|
|
def test_load_tools_from_config():
|
|
registry = MCPToolRegistry()
|
|
|
|
# Test valid config
|
|
valid_config = [
|
|
{
|
|
"name": "config_tool",
|
|
"description": "A tool from config",
|
|
"input_schema": {"type": "object"},
|
|
"handler": "tests.unit.proxy.mcp_server.test_tool_registry.example_handler",
|
|
}
|
|
]
|
|
|
|
registry.load_tools_from_config(valid_config)
|
|
assert "config_tool" in registry.tools
|
|
assert registry.tools["config_tool"].name == "config_tool"
|
|
assert registry.tools["config_tool"].description == "A tool from config"
|
|
assert callable(registry.tools["config_tool"].handler)
|
|
|
|
|
|
def test_tool_execution():
|
|
registry = MCPToolRegistry()
|
|
|
|
# Register a tool
|
|
registry.register_tool(
|
|
name="echo",
|
|
description="Echo the input",
|
|
input_schema={"type": "object"},
|
|
handler=example_handler,
|
|
)
|
|
|
|
# Get and execute the tool
|
|
tool = registry.get_tool("echo")
|
|
assert tool is not None
|
|
|
|
test_input = {"message": "hello"}
|
|
result = tool.handler(test_input)
|
|
assert result == {"result": test_input}
|