Skip to main content
The HostRunner connects an LLM to your MCP tools, letting you test how models interact with your server. It handles the agentic loop (prompt → tool call → result → response) and gives you rich inspection capabilities.

Why Test with LLMs?

Unit tests verify your tools work correctly in isolation. But in production, an LLM decides which tool to call and what arguments to pass. Testing with real LLMs catches issues like:
  • Ambiguous tool descriptions that confuse the model
  • Missing or unclear parameter documentation
  • Tools that the model consistently misuses
  • Edge cases in natural language interpretation

Creating a HostRunner

Pass the same mcpClientManager instance when you use MCP App tools and upload evals to MCPJam: that enables getWidgetSnapshots() (HTML from readResource on ui.resourceUri) so traces can replay widgets offline. See the HostRunner reference.

Running Prompts

Send natural language prompts and inspect what happens:

The PromptResult Object

Every prompt returns a PromptResult with rich inspection methods:
HostRunner never throws exceptions. Errors are captured in the result, making it safe to run many tests without try/catch blocks.

Multi-Turn Conversations

Pass previous results as context to maintain conversation history:
This is essential for testing workflows that span multiple interactions.

Tuning Agent Behavior

System Prompt

Guide the model’s behavior:

Temperature

Control randomness (lower = more deterministic):

Max Steps

Limit the agentic loop iterations:

Control Multi-Step Loops with stopWhen

Use stopWhen when you want to stop the multi-step loop after a particular step completes:
stopWhen does not skip tool execution. It controls whether the prompt loop continues after the current step completes, and HostRunner also applies stepCountIs(maxSteps) as a safety guard.

Bound Prompt Runtime with timeout

Use timeout when you want to bound how long HostRunner.run() can run:
timeout accepts number, totalMs, stepMs, and chunkMs. In practice, number and totalMs cap the full prompt, stepMs caps each step, and chunkMs mainly matters in streaming flows. The runtime creates an internal abort signal, so tools can stop early if their implementation respects the provided abortSignal.

Writing Assertions

Use validators to assert tool call behavior:

Performance Insights

Understand where time is spent:

Next Steps

Running Evals

Run statistical evaluations

HostRunner Reference

Full API documentation

PromptResult Reference

All result methods

Validators Reference

Assertion functions