# MCP Server Tool Evaluation Support
## Overview
Add support for evaluating tools from remote MCP servers without
requiring Python callables. Enables direct evaluation of any
MCP-compatible tool server.
## What's New
### Core Features
- **`MCPToolRegistry`**: Evaluate tools from a single MCP server
- **`CompositeMCPRegistry`**: Evaluate tools from multiple MCP servers
simultaneously
- **Automatic loaders**: `load_from_stdio()` and `load_from_http()` to
fetch tools from running servers
- **Automatic namespacing**: Tools prefixed with server name (e.g.,
`server_tool_name`)
- **Smart name resolution**: Use short names if unique, full names if
ambiguous
- **OpenAI strict mode**: Automatic schema conversion prevents parameter
hallucinations
### Usage
**Automatic Loading:**
```python
from arcade_evals import load_from_stdio, MCPToolRegistry
# Load tools automatically from MCP server
tools = load_from_stdio(["npx", "-y", "@modelcontextprotocol/server-github"])
registry = MCPToolRegistry(tools)
```
**Single MCP Server:**
```python
from arcade_evals import MCPToolRegistry, ExpectedToolCall
registry = MCPToolRegistry(mcp_tools)
suite = EvalSuite(catalog=registry)
suite.add_case(
expected_tool_calls=[
ExpectedToolCall(tool_name="tool_name", args={...})
]
)
```
**Multiple MCP Servers:**
```python
from arcade_evals import CompositeMCPRegistry, load_from_stdio
# Load from multiple servers
github_tools = load_from_stdio(["npx", "-y", "@modelcontextprotocol/server-github"])
slack_tools = load_from_stdio(["npx", "-y", "@modelcontextprotocol/server-slack"])
composite = CompositeMCPRegistry(
tool_lists={
"github": github_tools,
"slack": slack_tools,
}
)
suite = EvalSuite(catalog=composite)
suite.add_case(
expected_tool_calls=[
ExpectedToolCall(tool_name="github_list_issues", args={...})
]
)
```
## Implementation
### Files Changed
- **`libs/arcade-evals/arcade_evals/registry.py`** (NEW): Registry
abstractions and implementations
- **`libs/arcade-evals/arcade_evals/loaders.py`** (NEW): Automatic tool
loading from MCP servers
- **`libs/arcade-evals/arcade_evals/eval.py`** (MODIFIED): Enhanced
`ExpectedToolCall` and evaluation logic
- **`libs/arcade-evals/arcade_evals/__init__.py`** (MODIFIED): Exported
new registries and loaders
### Key Technical Details
- Added `BaseToolRegistry` interface for abstraction
- `MCPToolRegistry` handles single server tools
- `CompositeMCPRegistry` manages multiple servers with collision
detection
- `load_from_stdio()` and `load_from_http()` for automatic tool
discovery
- Fixed name normalization bug: MCP tools use underscores (not dots)
- Optimized tool copying: 2.5x faster via shallow copy
## Testing
- ✅ 41 tests passing (25 new tests added)
- ✅ `test_eval_mcp_registry.py`: MCPToolRegistry functionality
- ✅ `test_eval_composite_mcp.py`: CompositeMCPRegistry with multiple
servers
- ✅ Verified backward compatibility with Python tools
## Backward Compatibility
✅ **100% backward compatible** - No breaking changes
## Breaking Changes
**None**
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Adds end-to-end eval UX: examples, a robust CLI runner, and rich
outputs.
>
> - **New examples**: `eval_arcade_gateway.py`,
`eval_stdio_mcp_server.py`, `eval_http_mcp_server.py`,
`eval_comprehensive_comparison.py` with timeouts, error handling, and
track-based comparisons; detailed `README.md`
> - **CLI runner**: `arcade_cli/evals_runner.py` to execute
evals/capture in parallel with progress, error isolation, failed-only
filtering, context inclusion, and multi-provider/model support
> - **Output formatters**: `arcade_cli/formatters/` (txt, md, html,
json) for evals and capture; comparative and multi-model HTML with tabs
and context rendering
> - **Display refactor**: `display.py` now supports writing multiple
formats, failed-only disclaimers, include-context, and improved console
summaries
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
ff8acf9c34a6b61462a019a1ee9df081006517d0. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Francisco Liberal <francisco@arcade.dev>
Co-authored-by: Mateo Torres <torresmateo@gmail.com>
262 lines
9.9 KiB
Python
262 lines
9.9 KiB
Python
"""Tests for EvalSuite convenience methods (TICKET-003)."""
|
|
|
|
from typing import Annotated, Any
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
from arcade_core import ToolCatalog
|
|
from arcade_evals import EvalSuite, ExpectedToolCall, MCPToolDefinition
|
|
from arcade_tdk import tool
|
|
|
|
# Mark all tests in this module as requiring evals dependencies
|
|
pytestmark = pytest.mark.evals
|
|
|
|
|
|
def sample_tool_def(name: str = "test_tool") -> dict[str, Any]:
|
|
return {
|
|
"name": name,
|
|
"description": "A test tool",
|
|
"inputSchema": {
|
|
"type": "object",
|
|
"properties": {"param": {"type": "string"}},
|
|
"required": ["param"],
|
|
},
|
|
}
|
|
|
|
|
|
@tool
|
|
def py_add(a: Annotated[int, "Left operand"], b: Annotated[int, "Right operand"] = 0) -> int:
|
|
"""Add two integers."""
|
|
return a + b
|
|
|
|
|
|
class TestAddToolDefinitions:
|
|
def test_add_single_tool(self) -> None:
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
suite.add_tool_definitions([sample_tool_def()])
|
|
assert suite.get_tool_count() == 1
|
|
assert "test_tool" in suite.list_tool_names()
|
|
|
|
def test_method_chaining(self) -> None:
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
assert suite.add_tool_definitions([sample_tool_def()]) is suite
|
|
|
|
def test_add_empty_list(self) -> None:
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
suite.add_tool_definitions([])
|
|
assert suite.get_tool_count() == 0
|
|
|
|
def test_invalid_tool_raises(self) -> None:
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
with pytest.raises(ValueError, match="name"):
|
|
suite.add_tool_definitions([{"description": "No name"}])
|
|
|
|
|
|
class TestAddMcpServer:
|
|
@pytest.mark.asyncio
|
|
async def test_calls_loader_with_correct_params(self) -> None:
|
|
with patch(
|
|
"arcade_evals._evalsuite._convenience.load_mcp_remote_async", new_callable=AsyncMock
|
|
) as mock_load:
|
|
mock_load.return_value = [sample_tool_def()]
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
await suite.add_mcp_server("http://localhost:8000", headers={"Auth": "t"}, timeout=30)
|
|
mock_load.assert_called_once_with(
|
|
"http://localhost:8000",
|
|
timeout=30,
|
|
headers={"Auth": "t"},
|
|
use_sse=False,
|
|
)
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_empty_response_warns(self) -> None:
|
|
with patch(
|
|
"arcade_evals._evalsuite._convenience.load_mcp_remote_async", new_callable=AsyncMock
|
|
) as mock_load:
|
|
mock_load.return_value = []
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
with pytest.warns(UserWarning, match="No tools loaded"):
|
|
await suite.add_mcp_server("http://localhost:8000")
|
|
|
|
|
|
class TestAddMcpStdioServer:
|
|
@pytest.mark.asyncio
|
|
async def test_calls_loader_with_correct_params(self) -> None:
|
|
with patch(
|
|
"arcade_evals._evalsuite._convenience.load_from_stdio_async", new_callable=AsyncMock
|
|
) as mock_load:
|
|
mock_load.return_value = [sample_tool_def()]
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
await suite.add_mcp_stdio_server(["python", "server.py"], env={"K": "V"}, timeout=20)
|
|
mock_load.assert_called_once_with(
|
|
["python", "server.py"],
|
|
timeout=20,
|
|
env={"K": "V"},
|
|
)
|
|
|
|
|
|
class TestAddArcadeGateway:
|
|
@pytest.mark.asyncio
|
|
async def test_calls_loader_with_correct_params(self) -> None:
|
|
with patch(
|
|
"arcade_evals._evalsuite._convenience.load_arcade_mcp_gateway_async",
|
|
new_callable=AsyncMock,
|
|
) as mock_load:
|
|
mock_load.return_value = [sample_tool_def()]
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
await suite.add_arcade_gateway(
|
|
"my-gateway",
|
|
arcade_api_key="k",
|
|
arcade_user_id="u",
|
|
timeout=15,
|
|
)
|
|
|
|
# base_url defaults to None, loader handles the default
|
|
mock_load.assert_called_once_with(
|
|
"my-gateway",
|
|
arcade_api_key="k",
|
|
arcade_user_id="u",
|
|
base_url=None,
|
|
timeout=15,
|
|
)
|
|
|
|
|
|
class TestAddToolCatalog:
|
|
def test_add_tool_catalog_registers_python_tool_and_allows_callable_in_case(self) -> None:
|
|
catalog = ToolCatalog()
|
|
catalog.add_tool(py_add, "sample_toolkit")
|
|
|
|
suite = EvalSuite(name="Test", system_message="Test").add_tool_catalog(catalog)
|
|
names = suite.list_tool_names()
|
|
assert suite.get_tool_count() == 1
|
|
assert len(names) == 1
|
|
|
|
suite.add_case(
|
|
name="Case",
|
|
user_message="Add 1 and 2",
|
|
expected_tool_calls=[ExpectedToolCall(func=py_add, args={"a": 1, "b": 2})],
|
|
)
|
|
assert suite.cases[0].expected_tool_calls[0].name in names
|
|
|
|
|
|
class TestMCPToolDefinition:
|
|
"""Tests for MCPToolDefinition TypedDict."""
|
|
|
|
def test_typedict_is_importable(self) -> None:
|
|
"""MCPToolDefinition should be importable from arcade_evals."""
|
|
from arcade_evals import MCPToolDefinition
|
|
|
|
assert MCPToolDefinition is not None
|
|
|
|
def test_typedict_has_expected_keys(self) -> None:
|
|
"""MCPToolDefinition should have name, description, and inputSchema keys."""
|
|
annotations = MCPToolDefinition.__annotations__
|
|
# Check all expected keys are present (from both base and child TypedDict)
|
|
all_keys = set(annotations.keys())
|
|
# The parent class _MCPToolDefinitionRequired adds 'name'
|
|
assert "description" in all_keys
|
|
assert "inputSchema" in all_keys
|
|
|
|
def test_tool_with_only_required_fields(self) -> None:
|
|
"""Tool definition with only 'name' should work (other fields default)."""
|
|
tool_def: MCPToolDefinition = {"name": "minimal_tool"}
|
|
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
suite.add_tool_definitions([tool_def])
|
|
|
|
assert suite.get_tool_count() == 1
|
|
assert "minimal_tool" in suite.list_tool_names()
|
|
|
|
def test_tool_with_all_fields(self) -> None:
|
|
"""Tool definition with all fields should work."""
|
|
tool_def: MCPToolDefinition = {
|
|
"name": "full_tool",
|
|
"description": "A fully specified tool",
|
|
"inputSchema": {
|
|
"type": "object",
|
|
"properties": {"x": {"type": "string"}},
|
|
"required": ["x"],
|
|
},
|
|
}
|
|
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
suite.add_tool_definitions([tool_def])
|
|
|
|
assert suite.get_tool_count() == 1
|
|
assert "full_tool" in suite.list_tool_names()
|
|
|
|
def test_multiple_tools_with_typed_list(self) -> None:
|
|
"""A list[MCPToolDefinition] should work with add_tool_definitions."""
|
|
tools: list[MCPToolDefinition] = [
|
|
{"name": "tool_a", "description": "Tool A"},
|
|
{"name": "tool_b"},
|
|
{"name": "tool_c", "inputSchema": {"type": "object", "properties": {}}},
|
|
]
|
|
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
suite.add_tool_definitions(tools)
|
|
|
|
assert suite.get_tool_count() == 3
|
|
assert set(suite.list_tool_names()) == {"tool_a", "tool_b", "tool_c"}
|
|
|
|
def test_duplicate_tool_name_raises_error(self) -> None:
|
|
"""Registering a tool with a duplicate name should raise ValueError."""
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
suite.add_tool_definitions([{"name": "my_tool"}])
|
|
|
|
with pytest.raises(ValueError, match="already registered"):
|
|
suite.add_tool_definitions([{"name": "my_tool"}])
|
|
|
|
|
|
class TestAddToolDefinitionsEdgeCases:
|
|
"""Additional edge case tests for add_tool_definitions."""
|
|
|
|
def test_invalid_type_raises_typeerror(self) -> None:
|
|
"""Non-dict tool definitions should raise TypeError."""
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
with pytest.raises(TypeError, match="must be dictionaries"):
|
|
suite.add_tool_definitions(["not_a_dict"]) # type: ignore
|
|
|
|
def test_does_not_mutate_input(self) -> None:
|
|
"""add_tool_definitions should not mutate the input dicts."""
|
|
original_tool = {"name": "my_tool"}
|
|
original_copy = dict(original_tool)
|
|
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
suite.add_tool_definitions([original_tool])
|
|
|
|
# Original dict should be unchanged (no defaults added)
|
|
assert original_tool == original_copy
|
|
assert "description" not in original_tool
|
|
assert "inputSchema" not in original_tool
|
|
|
|
|
|
class TestAddMcpStdioServerWarnings:
|
|
"""Tests for add_mcp_stdio_server warning paths."""
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_empty_response_warns(self) -> None:
|
|
"""Empty response from stdio server should warn."""
|
|
with patch(
|
|
"arcade_evals._evalsuite._convenience.load_from_stdio_async", new_callable=AsyncMock
|
|
) as mock_load:
|
|
mock_load.return_value = []
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
with pytest.warns(UserWarning, match="No tools loaded"):
|
|
await suite.add_mcp_stdio_server(["python", "server.py"])
|
|
|
|
|
|
class TestAddArcadeGatewayWarnings:
|
|
"""Tests for add_arcade_gateway warning paths."""
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_empty_response_warns(self) -> None:
|
|
"""Empty response from arcade gateway should warn."""
|
|
with patch(
|
|
"arcade_evals._evalsuite._convenience.load_arcade_mcp_gateway_async",
|
|
new_callable=AsyncMock,
|
|
) as mock_load:
|
|
mock_load.return_value = []
|
|
suite = EvalSuite(name="Test", system_message="Test")
|
|
with pytest.warns(UserWarning, match="No tools loaded"):
|
|
await suite.add_arcade_gateway("my-gateway")
|