Skip to main content
The EvalTest class runs a single test scenario multiple times and provides statistical metrics like accuracy, precision, and recall.

Import

Constructor

Parameters

EvalTestConfig
required
Configuration for the evaluation test.

EvalTestConfig

Changed in 3.0. expectedToolCalls used to be reporting metadata only: the local verdict came from your test function alone, while the dashboard recomputed the match — so the same run could show accuracy() === 1 locally and fail in MCPJam. It is now enforced during the run, which means a test whose expectations were never actually checked can start failing on upgrade.If that happens, the expectation was wrong or over-specified. Fix it, relax it with matchOptions (e.g. { argumentMatching: "ignore" }), or drop expectedToolCalls if it was only ever documentation. Tests that declare neither expectedToolCalls nor predicates behave exactly as before.

matchOptions

Layered suite → case, and validated when the test is constructed rather than mid-run.

predicates

Deterministic, state-based checks evaluated against the iteration transcript — same transcript, same verdict, which is what makes them usable as a CI gate. An iteration passes only if every predicate passes, independently of failOnToolError. Verdicts are reported under metadata.predicates, so the dashboard’s check chips work for code-first runs too. See eval reporting for the full list of predicate types.
The widget predicates (widgetRendered, widgetRenderLatencyUnder, widgetNoConsoleErrors) need render observations only a hosted run captures, so EvalTest rejects them at construction instead of failing every iteration.

TestFunction Type

The test function receives a HostExecutor (the interface implemented by both HostRunner and HostRuntime) and must return a boolean:
  • true = test passed
  • false = test failed
Both HostRunner, HostRuntime, and mock executors implement the HostExecutor interface, so you can use any of them for testing.

Example


Methods

run()

Executes the test multiple times and returns detailed results.

Parameters

EvalTestRunOptions

Results are automatically saved to MCPJam after the run completes when an API key is available via mcpjam.apiKey or the MCPJAM_API_KEY environment variable. Set mcpjam.enabled: false to disable.

ProgressCallback Type

Example


accuracy()

Returns the success rate (0.0 - 1.0).

Returns

number - Proportion of tests that passed.

Example


precision()

Returns the precision metric, micro-averaged over the run’s tool-call matches.

Returns

number — True positives / (True positives + False positives). Counted per iteration from the expected/actual tool calls: a matched expectation is a true positive, an unexpected call is a false positive, a missing one is a false negative, and an argument mismatch counts as both.
Changed in 3.0. precision(), recall() and truePositiveRate() all used to return this.accuracy() — three names for one number. They now compute real values, and throw when no test in the run declared expectedToolCalls, because there is nothing to compute them from. If you were reading precision() as a stand-in for accuracy, call accuracy() directly.

recall()

Returns the recall metric, micro-averaged over the run’s tool-call matches.

Returns

number — True positives / (True positives + False negatives). Throws when the run declared no expectedToolCalls.

truePositiveRate()

Returns the true positive rate (same as recall).

unexpectedToolCallRate()

The fraction of expectation-bearing iterations that made at least one tool call nobody asked for.

Returns

number — Iterations with an extra call / iterations that had expectations. 0 when the run declared no expectations.

falsePositiveRate()

Deprecated in 3.0 — use unexpectedToolCallRate(). The old implementation returned failures / iterations, which is the failure rate, not a false-positive rate. For runs with no expectedToolCalls it still returns that legacy value so existing dashboards do not change; for runs with expectations it now delegates to unexpectedToolCallRate().

averageTokenUse()

Returns the average tokens used per iteration.

Returns

number - Mean token count.

Example


getResults()

Returns the full run result from the last run.

Returns

EvalRunResult | null - The run result, or null if run() hasn’t been called.

EvalRunResult Type

IterationResult Type


getName()

Returns the test’s name.

getConfig()

Returns the test’s configuration.

getAllIterations()

Returns all iteration details from the last run.

getFailedIterations()

Returns only the failed iterations from the last run.

Example


getSuccessfulIterations()

Returns only the successful iterations from the last run.

getFailureReport()

Returns a formatted failure report with traces from all failed iterations. Useful for debugging.

Example


Properties

name

The test’s identifier (via getName()).

Test Function Patterns

Simple Tool Check

Argument Validation

Response Content

Multiple Conditions

Multi-Turn Conversation

With Validators


Complete Example