arcade-mcp/libs/arcade-evals/arcade_evals/_evalsuite/_comparative.py
jottakka 98fad93d21
Adding MCP Servers supports to Arcade Evals (#689)
# 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>
2026-01-07 20:26:23 -03:00

132 lines
3.9 KiB
Python

"""Comparative case builder for multi-track evaluations.
Provides a fluent API for defining evaluation cases that run against
multiple tool tracks with track-specific expected results and critics.
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from arcade_evals._evalsuite._types import (
ComparativeCase,
EvalRubric,
ExpectedMCPToolCall,
ExpectedToolCall,
)
if TYPE_CHECKING:
from arcade_evals.critic import Critic
class ComparativeCaseBuilder:
"""Fluent builder for creating comparative cases.
Example:
builder = ComparativeCaseBuilder(
suite=suite,
name="weather_query",
user_message="What's the weather?",
)
builder.for_track(
"Google Weather",
expected_tool_calls=[...],
critics=[...],
).for_track(
"OpenWeather",
expected_tool_calls=[...],
critics=[...],
)
"""
def __init__(
self,
suite: Any, # EvalSuite - avoid circular import
name: str,
user_message: str,
system_message: str = "",
additional_messages: list[dict[str, str]] | None = None,
rubric: EvalRubric | None = None,
) -> None:
"""Initialize the builder.
Args:
suite: The parent EvalSuite.
name: Unique case name.
user_message: User message (shared across tracks).
system_message: System message (shared across tracks).
additional_messages: Additional context (shared).
rubric: Default rubric (shared, can be overridden).
"""
self._suite = suite
self._case = ComparativeCase(
name=name,
user_message=user_message,
system_message=system_message,
additional_messages=additional_messages or [],
rubric=rubric,
)
def for_track(
self,
track_name: str,
expected_tool_calls: list[ExpectedToolCall | ExpectedMCPToolCall],
critics: list[Critic] | None = None,
) -> ComparativeCaseBuilder:
"""Add track-specific configuration.
Args:
track_name: The track name (must be registered via add_*_tools).
expected_tool_calls: Expected tool calls for this track.
critics: Critics for this track.
Returns:
Self for method chaining.
Raises:
ValueError: If track doesn't exist.
"""
# Validate track exists
if not self._suite._track_manager.has_track(track_name):
available = self._suite._track_manager.get_track_names()
raise ValueError(
f"Track '{track_name}' not found. "
f"Available tracks: {available}. "
f"Register tracks first using add_*_tools(track=...)."
)
self._case.add_track_config(
track_name=track_name,
expected_tool_calls=expected_tool_calls,
critics=critics,
)
return self
def build(self) -> ComparativeCase:
"""Build and return the comparative case.
Returns:
The configured ComparativeCase.
Raises:
ValueError: If no tracks configured.
"""
if not self._case.track_configs:
raise ValueError(
f"No tracks configured for comparative case '{self._case.name}'. "
f"Use .for_track() to add at least one track configuration."
)
return self._case
@property
def case(self) -> ComparativeCase:
"""Access the underlying case for inspection.
Note: This is primarily for testing. The case may be incomplete
if tracks haven't been configured yet. Use build() to validate
and finalize the case.
Returns:
The ComparativeCase (may be incomplete).
"""
return self._case