The Session API is the heart of mcp-eval testing. It manages your agent’s lifecycle, collects metrics, runs assertions, and produces comprehensive test results.
Quick start
The simplest way to create a test session:Core concepts
TestSession
The orchestrator that manages everything:- Lifecycle management: Starts/stops agents and MCP servers
- Tool discovery: Automatically finds and registers MCP tools
- Metrics collection: Tracks all interactions via OTEL
- Assertion execution: Runs evaluators at the right time
- Report generation: Produces test artifacts
TestAgent
A thin, friendly wrapper around your LLM agent:- Simple interface: Just
generate()andassert_that() - Automatic tracking: All interactions are recorded
- Context preservation: Maintains conversation state
Creating sessions
Basic session creation
Session with custom configuration
Agent interactions
Generating responses
Multi-turn conversations
Assertions in depth
Immediate vs. deferred assertions
Assertion timing control
Named assertions for better reporting
Metrics and results
Accessing metrics during tests
Getting test results
Duration tracking
OpenTelemetry traces
Accessing trace data
Custom span attributes
Artifacts and reporting
Session artifacts
Programmatic report generation
Advanced patterns
Custom session hooks
Session state management
Parallel session execution
Best practices
Monitor metrics: Check metrics during long-running tests to catch performance issues early.
Error handling
See also
Expect API Reference
All available assertions
Configuration
Session configuration options
Reports
Understanding test reports
Metrics & Tracing
Deep dive into metrics