Skip to main content
The Core API provides the fundamental building blocks for writing mcp-eval tests. These decorators and utilities make your tests clean, reusable, and powerful.

Quick reference

The @task decorator

The foundation of every mcp-eval test:

Basic usage

Task parameters

Task with custom configuration

The @with_agent decorator

Specify which agent configuration to use:

Using named agents

Multiple agent configurations

Inline agent configuration

Decorator order matters! Always apply @with_agent above @task to ensure the agent is properly configured when the task runs.

The @parametrize decorator

Run the same test with different inputs:

Basic parametrization

Multiple parameters

Named scenarios

Use @parametrize("name,url,expected", [...]) to model named cases.

Dynamic parametrization

Setup and teardown

Run code before and after your tests:

Simple setup/teardown

Async setup/teardown

Setup with validation

TestResult object

Understanding test execution results:

TestResult structure

Accessing TestResult in hooks

Aggregating results

Advanced patterns

Conditional test execution

Prefer selecting tests with your runner and environment rather than custom decorators.
Using pytest marks for conditions (when running under pytest):
Then select by mark:

Test dependencies

Prefer independent tests; if ordering is required, orchestrate via your runner.

Custom test context

Best practices

Name your tests clearly: Use descriptive names that explain what the test validates. This helps when reviewing test reports.
Avoid test interdependence: Each test should be independent and not rely on side effects from other tests, unless explicitly using depends_on.
Use parametrize wisely: While parametrization is powerful, too many parameter combinations can make tests slow. Consider grouping related parameters.

Common patterns

Testing error handling

Testing multi-step workflows

See also

Expect API

Available assertions for your tests

Session API

Managing test sessions and agents

Best Practices

Writing maintainable tests

Examples

Complete test examples