> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.runtype.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.runtype.com/_mcp/server.

# Test against your real agent

> Relay a local agent or MCP server to Runtype and run baseline simulation scenarios against it.

A baseline simulation runs against a copy of your agent that Runtype builds from production traces (the copy). The copy never calls your real tools. To test your live code, prompt, model, and tools, relay your local agent or Model Context Protocol (MCP) server to Runtype.

Test against your real agent when any of the following applies:

* A report can't confirm that the copy matches production (`directional` confidence).
* Runtype opens a `verify_real_agent` pending action for the agent.
* You want to verify how your live code or local MCP server behaves before you ship a change.

The relay forwards requests only from your account to one loopback address on your computer, and stays open until you press Ctrl-C.

## Before you begin

Before you start, confirm that you have the following:

* A claimed Runtype organization. If you created the organization with `init --no-browser`, claim it with `npx @runtypelabs/connect claim` first. For steps, see [Claim an unclaimed organization](/connect/connect-a-repository#claim-an-unclaimed-organization).
* A prepared baseline simulation with scenarios. If you don't have one, follow [Run a baseline simulation](/simulate/run-a-baseline-simulation).
* Node.js 22.12 or later, signed in to Runtype Connect.
* Your local agent or MCP server ready to listen on a loopback address.

## Relay the agent

To connect a local agent through the relay and register it as a simulation test target, follow these steps:

1. Start your local agent on a loopback address (`127.0.0.1`, `localhost`, or `::1`), or configure auto-start in [Start the relay from a manifest](#start-the-relay-from-a-manifest).

2. In another terminal, start the relay, or copy the command from the agent's **Simulations** page in the dashboard:

   **`Relay the agent`**

   ```bash title="Relay the agent"
   npx @runtypelabs/connect relay --agent AGENT_ID --forward-to http://127.0.0.1:3000/a2a
   ```

   Replace `AGENT_ID` with the external agent's ID from `get_status`. Replace `http://127.0.0.1:3000/a2a` with your agent's `http` or `https` loopback address, with no credentials, query string, or fragment.

   When the relay connects, it prints the address it forwards to. Keep this terminal open while simulations run.

   By default, the relay speaks Agent2Agent (A2A) JSON-RPC. Add either of the following options to match your setup:

   * `--protocol chat`: use when your agent accepts `POST` JSON with `{"userId", "sessionId", "message"}` and returns `{"sessionId", "reply"}`. If your agent speaks neither A2A nor that shape, wrap it in a small local HTTP endpoint that accepts and returns that JSON.
   * `--connect`: register the agent as a test target in the same command and skip step 3. If your organization has more than one product, add `--product-id PRODUCT_ID`.

   The relay forwards only your agent's requests to that address and removes authorization headers before forwarding. Configure your local agent to accept unauthenticated loopback requests.

3. If you didn't pass `--connect`, register the agent as a test target:

   **`Register the agent as a test target`**

   ```bash title="Register the agent as a test target"
   npx @runtypelabs/connect connect-test-target --kind agent --agent-id AGENT_ID --product-id PRODUCT_ID --json
   ```

   Replace `AGENT_ID` as in step 2. Replace `PRODUCT_ID` with the product ID from `init`, or omit `--product-id` when your organization has one product or `.env` holds a matching ingest key. In a non-interactive terminal, pass `--yes`.

   The command returns the target's ID and the command to price a run. Keep the relay running while you register.

The first relay pairs your computer with your account, and later relays reuse that pairing. The pairing key stays outside your repository.

## Start the relay from a manifest

To save relay settings and let `relay` start and stop your local agent, create `.runtype/agents.yaml` (or `.runtype/agents.yml`) at your repository root:

**`.runtype/agents.yaml`**

```yaml title=".runtype/agents.yaml"
agents:
  support:
    agentId: AGENT_ID
    forwardTo: http://127.0.0.1:3000/a2a
    command: pnpm dev
    cwd: apps/agent
    healthPath: /health
```

Replace `AGENT_ID` with the external agent's ID from `get_status`, and set the other fields to match your repository.

Start and register the relay from the repository root:

**`Start the relay from a manifest`**

```bash title="Start the relay from a manifest"
npx @runtypelabs/connect relay --connect
```

If nothing answers at `healthPath` (or `forwardTo` when `healthPath` is omitted), `relay` runs `command` in `cwd` and waits until the agent responds. When you stop the relay, it stops that process. If your agent is already running, `relay` leaves it alone.

To skip auto-start, pass `--no-start`. When the file defines more than one agent, pass `--entry ENTRY_NAME`. Explicit `--agent`, `--forward-to`, and `--protocol` options override the manifest. For every field, option, and error, see [Agent manifest](/reference/agent-manifest).

## Relay an MCP server

To connect a local MCP server that speaks Streamable HTTP and register it as a simulation test target, follow these steps:

1. Start the relay with `--protocol mcp` and the server's literal loopback address:

   **`Relay an MCP server`**

   ```bash title="Relay an MCP server"
   npx @runtypelabs/connect relay --protocol mcp --forward-to http://127.0.0.1:8000/mcp
   ```

   Replace `http://127.0.0.1:8000/mcp` with your server's Streamable HTTP address using the literal IP `127.0.0.1` or `[::1]`, not `localhost`, with no credentials, query string, or fragment. To register the target in the same command, pass `--connect`. If your organization has more than one product, also pass `--product-id PRODUCT_ID`.

   When the relay connects, it prints a device ID. Keep this terminal open while simulations run.

2. If you didn't pass `--connect`, register the MCP server as a test target:

   **`Register an MCP server as a test target`**

   ```bash title="Register an MCP server as a test target"
   npx @runtypelabs/connect connect-test-target --kind mcp_server --device-id DEVICE_ID --url http://127.0.0.1:8000/mcp --product-id PRODUCT_ID --json
   ```

   Replace `DEVICE_ID` with the device ID from step 1, and use the same server address. Replace `PRODUCT_ID` with your product ID, or omit `--product-id` when your organization has one product or `.env` holds a matching ingest key.

   Runtype reads the server's tools through the relay, so both the relay and the server must be running. Running the command again is safe.

### Choose tool modes for an MCP server

Each tool on a relayed MCP server uses one of three modes during a simulation:

* **`live`**: sends the call through the relay to your local MCP server.
* **`recorded`**: answers from a recorded production call.
* **`simulated`**: generates a simulated answer without calling your server.

On the first registration, tools that the server marks read-only start in `live` mode, and every other tool starts in `simulated` mode. Tools added later start in `simulated` mode until you set their mode.

To set a tool's mode, pass `--tools` as a `TOOL_NAME=MODE` pair (repeat `--tools` for multiple tools):

**`Set a tool mode on the CLI`**

```bash title="Set a tool mode on the CLI"
npx @runtypelabs/connect connect-test-target --kind mcp_server --device-id DEVICE_ID --url http://127.0.0.1:8000/mcp --product-id PRODUCT_ID --tools create_ticket=live --json
```

Replace `DEVICE_ID`, the server address, and `PRODUCT_ID` as in the preceding step. Replace `create_ticket=live` with your tool name and mode (`live`, `recorded`, or `simulated`).

> **Warning**
>
> Setting a tool to `live` lets a simulation send real calls that can change real data. Your coding agent asks you before it sets a tool to `live`. Live calls go only to the server address on your paired computer.

The result lists each tool's mode and recent live calls. Each live call shows its tool name, status, and arguments with secrets removed. A call with status `started` was sent with no recorded outcome, so it might or might not have taken effect. To see how each tool call in a run was answered, pass `--run-id RUN_ID`.

## Run the scenarios against the target

Registering a test target runs nothing. Runs against a real agent or a relayed MCP server always need spend approval. For details, see [Limits and pricing](/reference/limits-and-pricing#connect-credit).

To price and run your baseline scenarios against the target, follow these steps:

1. Price the run with `estimate`:

   **`Price a run against the target`**

   ```bash title="Price a run against the target"
   npx @runtypelabs/connect estimate --subject target_run --target-id TARGET_ID --product-id PRODUCT_ID --json
   ```

   Replace `TARGET_ID` with the target ID from `connect-test-target` or `relay --connect`. Replace `PRODUCT_ID` with your product ID, or omit `--product-id` when your organization has one product.

   The response gives the expected cost, an `estimateId`, and an `approve_spend` pending action. Pricing the same run while the estimate is current returns the same estimate.

2. Review the estimate, then approve the `approve_spend` pending action:

   **`Approve the spend`**

   ```bash title="Approve the spend"
   npx @runtypelabs/connect resolve-pending-action --action-id ACTION_ID --resolution approve --estimate-id ESTIMATE_ID --json
   ```

   Replace `ACTION_ID` and `ESTIMATE_ID` with the pending action ID and `estimateId` from step 1. An approval covers only that estimate. To decline, pass `--resolution dismiss`. Your coding agent asks you before it approves spend.

3. Start the run with `run-simulation`:

   **`Start the run`**

   ```bash title="Start the run"
   npx @runtypelabs/connect run-simulation --estimate-id ESTIMATE_ID --json
   ```

   Replace `ESTIMATE_ID` with the approved `estimateId`. Running `run-simulation` again with the same estimate returns the same run and charges nothing more. If your organization is at its concurrent run limit, wait for a run to finish and run this command again.

4. Follow the run with `list-runs`:

   **`Follow the run`**

   ```bash title="Follow the run"
   npx @runtypelabs/connect list-runs --product-id PRODUCT_ID
   ```

   Replace `PRODUCT_ID` with your product ID.

5. Read the report after the run finishes:

   **`Read the report`**

   ```bash title="Read the report"
   npx @runtypelabs/connect get-report --run-id RUN_ID --json
   ```

   Replace `RUN_ID` with the run ID from step 3.

   For a real-agent run, the report compares your agent's pass count with the copy's pass count on the scenarios both runs graded. It names the scenarios that passed on only one of them, and counts passes where your agent reported nothing about its tools. Reading a scored real-agent report closes any open `verify_real_agent` pending action for that agent.

   If your agent map declares a Slack, Telegram, SMS, or iMessage surface, the copy runs behind that channel. Your real agent receives the plain message. That channel difference can explain formatting-only mismatches.

## Stop the relay

Press Ctrl-C in the terminal where `relay` is running. The relay closes its connection and exits, and Runtype can no longer reach your local agent or MCP server until you start it again.

Stopping the relay keeps your device pairing, test target, and tool modes. Starting `relay` again for the same agent or MCP server reconnects without re-pairing.

## Troubleshooting

If the relay connects or starts with errors, check the following common causes:

* **Authentication errors during a run**: the relay removes authorization headers before forwarding requests. Configure your local agent to accept unauthenticated loopback requests during testing.
* **Timed-out turns**: real-agent turns time out after 300 seconds. Check that your local agent responds within that limit.
* **Auto-start exits or times out**: if `relay` reports that your command exited before becoming ready, check `command` and `cwd` in `.runtype/agents.yaml`. If `relay` reports that the target did not become ready in time, increase `readyTimeoutMs` (up to `120000`) or check that your server starts cleanly.

For refusal codes and other errors, see [Troubleshooting](/reference/troubleshooting).

## Next steps

Continue with one of these pages:

* [Read a simulation report](/simulate/read-a-simulation-report): inspect the verdict, scores, confidence, and proposals from a run.
* [Test a proposed change](/simulate/test-a-proposed-change): compare proposed changes side by side against the copy.
* [Analyze your MCP server](/simulate/analyze-your-mcp-server): evaluate how agents use an MCP server and read that report.
* [Connect CLI](/reference/connect-cli): see every Connect CLI command and option.
* [Connect MCP tools](/reference/connect-mcp-tools): look up the input and output fields for simulation and test-target tools.