# 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>
293 lines
9.1 KiB
Python
293 lines
9.1 KiB
Python
import base64
|
|
import io
|
|
import subprocess
|
|
import tarfile
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from arcade_cli.deploy import (
|
|
create_package_archive,
|
|
get_required_secrets,
|
|
get_server_info,
|
|
start_server_process,
|
|
verify_server_and_get_metadata,
|
|
wait_for_health,
|
|
)
|
|
|
|
# Fixtures
|
|
|
|
|
|
@pytest.fixture
|
|
def test_dir() -> Path:
|
|
"""Return the path to the test directory."""
|
|
return Path(__file__).parent
|
|
|
|
|
|
@pytest.fixture
|
|
def valid_server_dir(test_dir: Path) -> Path:
|
|
"""Return the path to the valid server directory."""
|
|
return test_dir / "test_servers" / "valid_server"
|
|
|
|
|
|
@pytest.fixture
|
|
def valid_server_path(valid_server_dir: Path) -> str:
|
|
"""Return the path to the valid server entrypoint."""
|
|
return str(valid_server_dir / "server.py")
|
|
|
|
|
|
@pytest.fixture
|
|
def invalid_server_path(test_dir: Path) -> str:
|
|
"""Return the path to the invalid server entrypoint."""
|
|
return str(test_dir / "test_servers" / "invalid_server" / "server.py")
|
|
|
|
|
|
@pytest.fixture
|
|
def tmp_project_dir(tmp_path: Path) -> Path:
|
|
"""Create a temporary project directory with pyproject.toml."""
|
|
project_dir = tmp_path / "test_project"
|
|
project_dir.mkdir()
|
|
|
|
# Create a basic pyproject.toml
|
|
pyproject_content = """[build-system]
|
|
requires = ["setuptools>=61", "wheel"]
|
|
build-backend = "setuptools.build_meta"
|
|
|
|
[project]
|
|
name = "test_project"
|
|
version = "0.1.0"
|
|
description = "Test project"
|
|
requires-python = ">=3.10"
|
|
"""
|
|
(project_dir / "pyproject.toml").write_text(pyproject_content)
|
|
return project_dir
|
|
|
|
|
|
# Tests for create_package_archive
|
|
|
|
|
|
def test_create_package_archive_success(valid_server_dir: Path) -> None:
|
|
"""Test creating an archive from a valid directory."""
|
|
archive_base64 = create_package_archive(valid_server_dir)
|
|
|
|
# Verify it returns a base64-encoded string
|
|
assert isinstance(archive_base64, str)
|
|
assert len(archive_base64) > 0
|
|
|
|
# Decode and verify the archive can be extracted
|
|
archive_bytes = base64.b64decode(archive_base64)
|
|
byte_stream = io.BytesIO(archive_bytes)
|
|
|
|
with tarfile.open(fileobj=byte_stream, mode="r:gz") as tar:
|
|
members = tar.getmembers()
|
|
filenames = [m.name for m in members]
|
|
|
|
# Verify expected files are present
|
|
assert any("server.py" in name for name in filenames)
|
|
assert any("pyproject.toml" in name for name in filenames)
|
|
|
|
|
|
def test_create_package_archive_nonexistent_dir(tmp_path: Path) -> None:
|
|
"""Test that archiving a non-existent directory raises ValueError."""
|
|
nonexistent_dir = tmp_path / "does_not_exist"
|
|
|
|
with pytest.raises(ValueError, match="Package directory not found"):
|
|
create_package_archive(nonexistent_dir)
|
|
|
|
|
|
def test_create_package_archive_file_not_dir(tmp_path: Path) -> None:
|
|
"""Test that archiving a file instead of directory raises ValueError."""
|
|
test_file = tmp_path / "test_file.txt"
|
|
test_file.write_text("test content")
|
|
|
|
with pytest.raises(ValueError, match="Package path must be a directory"):
|
|
create_package_archive(test_file)
|
|
|
|
|
|
def test_create_package_archive_excludes_files(tmp_path: Path) -> None:
|
|
"""Test that certain files are excluded from the archive."""
|
|
test_dir = tmp_path / "test_project"
|
|
test_dir.mkdir()
|
|
|
|
# Create files that should be excluded
|
|
(test_dir / ".hidden").write_text("hidden")
|
|
(test_dir / "__pycache__").mkdir()
|
|
(test_dir / "__pycache__" / "cache.pyc").write_text("cache")
|
|
(test_dir / "requirements.lock").write_text("lock")
|
|
(test_dir / "dist").mkdir()
|
|
(test_dir / "dist" / "package.tar.gz").write_text("dist")
|
|
(test_dir / "build").mkdir()
|
|
(test_dir / "build" / "lib").write_text("build")
|
|
|
|
# Create files that should be included
|
|
(test_dir / "main.py").write_text("main")
|
|
(test_dir / "pyproject.toml").write_text("project")
|
|
|
|
archive_base64 = create_package_archive(test_dir)
|
|
archive_bytes = base64.b64decode(archive_base64)
|
|
byte_stream = io.BytesIO(archive_bytes)
|
|
|
|
with tarfile.open(fileobj=byte_stream, mode="r:gz") as tar:
|
|
members = tar.getmembers()
|
|
filenames = [m.name for m in members]
|
|
|
|
# Verify excluded files are not present
|
|
assert not any(".hidden" in name for name in filenames)
|
|
assert not any("__pycache__" in name for name in filenames)
|
|
assert not any(".lock" in name for name in filenames)
|
|
assert not any("dist" in name for name in filenames)
|
|
assert not any("build" in name for name in filenames)
|
|
|
|
# Verify included files are present
|
|
assert any("main.py" in name for name in filenames)
|
|
assert any("pyproject.toml" in name for name in filenames)
|
|
|
|
|
|
# Tests for wait_for_health
|
|
|
|
|
|
def test_wait_for_health_success(valid_server_path: str, capsys) -> None:
|
|
"""Test waiting for a healthy server."""
|
|
process, port = start_server_process(valid_server_path, debug=False)
|
|
base_url = f"http://127.0.0.1:{port}"
|
|
|
|
try:
|
|
wait_for_health(base_url, process, timeout=10)
|
|
finally:
|
|
# Clean up
|
|
process.terminate()
|
|
try:
|
|
process.wait(timeout=5)
|
|
except subprocess.TimeoutExpired:
|
|
process.kill()
|
|
process.wait()
|
|
|
|
|
|
def test_wait_for_health_process_dies(valid_server_path: str) -> None:
|
|
"""Test handling when process dies during health check."""
|
|
process, port = start_server_process(valid_server_path, debug=False)
|
|
base_url = f"http://127.0.0.1:{port}"
|
|
|
|
# Kill the process immediately
|
|
process.kill()
|
|
process.wait()
|
|
|
|
# Mock process object to pass to wait_for_health
|
|
with pytest.raises(ValueError):
|
|
wait_for_health(base_url, process, timeout=2)
|
|
|
|
|
|
# Tests for get_server_info
|
|
|
|
|
|
def test_get_server_info_success(valid_server_path: str, capsys) -> None:
|
|
"""Test extracting server info from a running server."""
|
|
process, port = start_server_process(valid_server_path, debug=False)
|
|
base_url = f"http://127.0.0.1:{port}"
|
|
|
|
try:
|
|
# Wait for server to be healthy first
|
|
wait_for_health(base_url, process, timeout=10)
|
|
|
|
server_name, server_version = get_server_info(base_url)
|
|
|
|
assert server_name == "simpleserver"
|
|
assert server_version == "1.0.0"
|
|
finally:
|
|
# Clean up
|
|
process.terminate()
|
|
try:
|
|
process.wait(timeout=5)
|
|
except subprocess.TimeoutExpired:
|
|
process.kill()
|
|
process.wait()
|
|
|
|
|
|
def test_get_server_info_invalid_url() -> None:
|
|
"""Test that invalid URL raises ValueError."""
|
|
invalid_url = "http://127.0.0.1:9999"
|
|
|
|
with pytest.raises(ValueError):
|
|
get_server_info(invalid_url)
|
|
|
|
|
|
# Tests for get_required_secrets
|
|
|
|
|
|
def test_get_required_secrets_with_secrets(valid_server_path: str, capsys) -> None:
|
|
"""Test extracting required secrets from server tools."""
|
|
process, port = start_server_process(valid_server_path, debug=False)
|
|
base_url = f"http://127.0.0.1:{port}"
|
|
|
|
try:
|
|
# Wait for server to be healthy first
|
|
wait_for_health(base_url, process, timeout=10)
|
|
|
|
secrets = get_required_secrets(base_url, "simpleserver", "1.0.0", debug=True)
|
|
assert "MY_SECRET_KEY" in secrets
|
|
finally:
|
|
# Clean up
|
|
process.terminate()
|
|
try:
|
|
process.wait(timeout=5)
|
|
except subprocess.TimeoutExpired:
|
|
process.kill()
|
|
process.wait()
|
|
|
|
|
|
def test_get_required_secrets_no_secrets(valid_server_path: str) -> None:
|
|
"""Test getting secrets returns set even when checking actual tools."""
|
|
process, port = start_server_process(valid_server_path, debug=False)
|
|
base_url = f"http://127.0.0.1:{port}"
|
|
|
|
try:
|
|
# Wait for server to be healthy first
|
|
wait_for_health(base_url, process, timeout=10)
|
|
|
|
secrets = get_required_secrets(base_url, "simpleserver", "1.0.0", debug=False)
|
|
|
|
assert len(secrets) == 1
|
|
finally:
|
|
# Clean up
|
|
process.terminate()
|
|
try:
|
|
process.wait(timeout=5)
|
|
except subprocess.TimeoutExpired:
|
|
process.kill()
|
|
process.wait()
|
|
|
|
|
|
def test_get_required_secrets_invalid_url() -> None:
|
|
"""Test that invalid URL raises ValueError."""
|
|
invalid_url = "http://127.0.0.1:9999"
|
|
|
|
with pytest.raises(
|
|
ValueError, match="Failed to extract tool secrets from /worker/tools endpoint"
|
|
):
|
|
get_required_secrets(invalid_url, "test", "1.0.0")
|
|
|
|
|
|
# Tests for verify_server_and_get_metadata (integration tests)
|
|
|
|
|
|
def test_verify_server_and_get_metadata_success(valid_server_path: str, capsys) -> None:
|
|
"""Test full server verification flow."""
|
|
server_name, server_version, required_secrets = verify_server_and_get_metadata(
|
|
valid_server_path, debug=False
|
|
)
|
|
|
|
# Verify returned values
|
|
assert server_name == "simpleserver"
|
|
assert server_version == "1.0.0"
|
|
assert "MY_SECRET_KEY" in required_secrets
|
|
|
|
|
|
def test_verify_server_and_get_metadata_with_debug(valid_server_path: str, capsys) -> None:
|
|
"""Test server verification with debug mode enabled."""
|
|
server_name, server_version, required_secrets = verify_server_and_get_metadata(
|
|
valid_server_path, debug=True
|
|
)
|
|
|
|
# Verify returned values
|
|
assert server_name == "simpleserver"
|
|
assert server_version == "1.0.0"
|
|
assert "MY_SECRET_KEY" in required_secrets
|