Metadata-Version: 2.4
Name: mcph
Version: 0.4.0
Summary: MCP Harness: diagnostics, real-client proxy and agent evals for MCP servers.
Author: Libor Krzyzanek
Author-email: Libor Krzyzanek <libor.krzyzanek@gmail.com>
License-Expression: Apache-2.0
License-File: LICENSE
Requires-Dist: fastmcp-slim[client]>=4.2,<5
Requires-Dist: httpx2>=2.10.0
Requires-Dist: jsonschema>=4.20
Requires-Dist: platformdirs>=4.0
Requires-Dist: py-key-value-aio[filetree]>=0.4.6,<0.6
Requires-Dist: pydantic>=2.7
Requires-Dist: python-dotenv>=1.1.0
Requires-Dist: pyyaml>=6.0.1
Requires-Dist: typer>=0.16.0
Requires-Dist: uvicorn>=0.31.1
Requires-Dist: fastmcp-slim[server]>=4.2,<5 ; extra == 'gateway'
Requires-Python: >=3.12
Provides-Extra: gateway
Description-Content-Type: text/markdown

# mcph

[![Coverage](https://raw.githubusercontent.com/mcp-harness-io/mcph/python-coverage-comment-action-data/badge.svg)](https://github.com/mcp-harness-io/mcph/tree/python-coverage-comment-action-data)

MCP Harness: diagnostics, real-client proxy and agent evals for MCP servers.

> Early development: the commands and `mcph.yaml` may still change between 0.x releases.

## Install

```bash
pip install mcph                # Python 3.12+
uvx mcph --help                 # or run it without installing
pip install 'mcph[gateway]'     # with the gateway, mcph proxy --gateway (see The gateway)
```

## Quick start

`mcph init` writes a starter `mcph.yaml` for you:

```console
$ mcph init --server-cmd "uv run python src/server.py"
Created /path/to/mcph.yaml
Edit the server entries, then run `mcph doctor run`.
```

Or write it yourself. It describes your MCP servers: `stdio` servers that mcph starts for you, and `http` servers that are already running.

```yaml
extends:
  - builtin:core               # the rules that ship with mcph (without a pack there is no rule)

servers:
  - name: orders
    transport: stdio
    command: uv
    args: ["run", "python", "src/server.py"]
    env_file: .env             # more variables for the server, kept out of this file
    env:
      LOG_LEVEL: WARNING
      API_KEY: ${API_KEY}      # taken from the environment mcph runs in
  - name: docs
    transport: http
    url: http://localhost:8080/mcp
    env_file: .env             # where ${DOCS_TOKEN} is looked for if the environment does not have it
    auth:                      # optional: send a bearer token
      type: bearer
      token: ${DOCS_TOKEN}     # the token comes from this environment variable

eval:                          # optional, for `mcph eval`: what to run against a server with an agent
  suites:                      # the suites, as `servers` is a list of servers
    - name: order-tracking     # every suite has its own target, runners and matrix
      path: suites/order-tracking.yaml   # its file, with its tasks and checks
      target: orders           # the server the agent gets (default: the only server, or the gateway)
      runners:                 # the ways to run an agent, by name
        haiku: {preset: claude, model: haiku}
    - name: order-cancellation
      path: suites/order-cancellation.yaml
      target: orders
      runners:
        sonnet: {preset: claude, model: sonnet}
        haiku: {preset: claude, model: haiku}
      matrix:                  # every task runs once for each of these (see "Evaluating a server")
        runner: [sonnet, haiku]
      repeat: 5                # and 5 times, unless a task says otherwise: an agent does not do the same thing every time
```

A `stdio` server only gets the environment you give it: `${API_KEY}` takes a variable from the environment mcph runs in, and `env_file` points at a dotenv file (keep it out of Git) for the variables you do not want in `mcph.yaml` (see [Environment variables of a server](#environment-variables-of-a-server)). The bearer token of an `http` server is written the same way: `token: ${DOCS_TOKEN}`, and its own `env_file` is where mcph looks for the variable when the environment it runs in does not have it, which is the case for a client that starts mcph without your shell's variables.

Then check them:

```console
$ mcph doctor run
Checking 2 servers from /path/to/mcph.yaml

orders
  OK     started in 423 ms (orders-server 1.0.0, MCP 2026-07-28), 3 tools
  WARN   core.tool_name_snake_case: tool 'getOrder' is not snake_case (try 'get_order')
docs
  OK     connected in 87 ms (docs-server 2.1.0, MCP 2026-07-28), 5 tools
  OK     core.tool_name_snake_case
  SKIP   oauth.metadata, oauth.issuer, oauth.pkce, oauth.registration: not needed, the server accepted the connection

All servers OK, 1 warning.
```

`extends` lists the packs whose rules doctor uses; `builtin:core` is the pack that ships with mcph (see [Rules and packs](#rules-and-packs)). Under each server doctor lists every rule: `OK` ran and found nothing, `WARN` or `ERROR` found a problem, `OFF` is turned off in `mcph.yaml`, and `SKIP` could not run or was not needed (skipped rules with the same reason share one line). To make a rule fail the run instead, or to switch it off, add a `doctor` section to the same file:

```yaml
doctor:
  rules:
    core.tool_name_snake_case: error   # or warn, or off
```

See [Configuring rules](#configuring-rules) for the details.

## Commands

| Command | What it does |
|---|---|
| `mcph init [DIRECTORY]` | Writes a starter `mcph.yaml` that extends `builtin:core` (default: the current directory, created if needed). It never overwrites an existing file. |
| `mcph doctor run` | Starts each `stdio` server (or connects to an `http` one), completes the MCP handshake, lists its tools, checks them against the rules of the packs under `extends` and reports what each rule found. |
| `mcph doctor rules` | Lists the rules of the packs under `extends` with their severity: the default, or the setting from `doctor.rules` in `mcph.yaml`. It starts no server. |
| `mcph pack list` | Lists the packs under `extends` with the rules each one defines. |
| `mcph pack verify [PATH]` | Checks a pack directory (default `.`): its manifest, its rule files and the rules they define. It lists every problem and exits with `1` if there are any. |
| `mcph server auth login SERVER`, `status [SERVER]`, `logout SERVER` | Signs in to an `http` server that uses OAuth through the browser, shows who is logged in, and signs out again. `mcph server` is the group of the commands about the servers of `mcph.yaml`; `auth` is the first of them. |
| `mcph version` | Prints the installed version. |
| `mcph proxy [--trace-out FILE] [--no-redact] (-- COMMAND... \| --server NAME \| --gateway [--no-namespace-tools]) [--transport http [--host HOST] [--port N] [--path PATH] [--ready-file FILE] [--allow-remote]]` | Records the traffic between a client and a server, to a [trace](https://github.com/mcp-harness-io/mcph/blob/main/docs/trace-format.md): a `stdio` server given as a command, or a `stdio` or `http` server of `mcph.yaml` with its environment and `auth`, for a client that starts the proxy. With `--transport http`, an `http` server of `mcph.yaml` on a local URL, for a client that connects by URL. With `--gateway`, every server of `mcph.yaml` behind one endpoint, on stdio or a URL (needs `mcph[gateway]`). See [Recording traffic](#recording-traffic). |
| `mcph trace print FILE` | Prints what a [trace](https://github.com/mcp-harness-io/mcph/blob/main/docs/trace-format.md) says, in plain words: the session, the tools the client was offered, every tool call (named `server.tool`, with its arguments, how it ended and how long it took) and what went wrong. See [Reading a trace](#reading-a-trace). |
| `mcph eval [SUITE...] [--trace FILE ...] [--task ID] [--runner NAMES] [--model NAMES] [--target NAMES] [--repeat N] [--report FILE] [--junit FILE]` | Runs the tasks of the suites with an agent (`claude`, in a sandbox, or a command of yours), in every cell of the matrix of runners, models and servers that each suite of `eval.suites` in `mcph.yaml` defines, as many times as the suite or the task says (`repeat`: an agent does not do the same thing every time), and checks each session (every call worked, the arguments fit the schema of the tool, tools that must or must not be called, the answer, ...). With `--trace` it checks recorded traces instead. Says what failed and exits with `1` if a check failed. Can also write the results as a JSON report and as JUnit XML. See [Evaluating a server](#evaluating-a-server). |
| `mcph report print FILE` | Prints a run report (the file of `mcph eval --report`) as `mcph eval` printed it: a block for each run, the grid of how each task did in each cell, and the count of the traces that failed. The same text, made by the same code, for reading a report later. Exits with `0` when it could be read, whatever the report says. See [Evaluating a server](#evaluating-a-server). |
| `mcph report diff BASE HEAD [--cell ID ...] [--fail-on-regression] [--markdown]` | Compares two run reports (the files of `mcph eval --report`): the tasks that passed in a cell in `BASE` and do not pass in `HEAD` are regressions (a task passes when its pass rate reaches what its suite asks for), improvements and other changes are listed too, and for a regression the checks that failed. With `--fail-on-regression` it exits with `1` when there is a regression; `--markdown` writes it for a pull request comment. See [Evaluating a server](#evaluating-a-server). |

`mcph doctor` is a group of commands: on its own it is an error, so a script that still calls it fails instead of passing without checking anything. `mcph doctor --help` lists its commands.

- `mcph init --template minimal|multi-server|oauth` picks the starter: one `stdio` server (the default), a `stdio` server plus an `http` server with a bearer token from an environment variable, or an `http` server that signs in with OAuth. `--server-cmd "uv run python src/server.py"` sets how the `stdio` server starts (split like a shell would). `--extend SOURCE` (repeatable) replaces the default `builtin:core`, so add `--extend builtin:core` to keep the core rules next to a pack of your own. `--force` overwrites an existing `mcph.yaml`. `init` writes `DIRECTORY/mcph.yaml`, so the global `-c` does not apply to it.
- `-c, --config PATH` selects the config file (default `./mcph.yaml`). It goes before the command: `mcph -c other.yaml doctor run`.
- `mcph doctor run --timeout SECONDS` limits how long each server may take to start and answer (default 30).
- `mcph doctor run --strict` also fails on warnings, which is handy in CI.
- `mcph doctor run` exits with `0` if all servers are OK, `1` if a server failed (or, with `--strict`, if there are warnings), `2` if the config is invalid.

If an `http` server refuses mcph, doctor says why instead of a generic error: no token was sent (401), the token was rejected (with the server's `error`, its explanation and the scope it asks for), or the token lacks a scope (403). It also shows what the server announces about its OAuth setup when it publishes protected resource metadata (RFC 9728): its authorization server and scopes.

```console
docs
  ERROR  authentication required: the server answered 401 (add `auth` to this server in mcph.yaml)
         challenge: Bearer resource_metadata="http://localhost:8080/.well-known/oauth-protected-resource/mcp"
         authorization server: https://auth.example.com/
         scopes: api.read, api.write
  SKIP   core.tool_name_snake_case: mcph could not connect to the server
  OK     oauth.metadata
  OK     oauth.issuer
  OK     oauth.pkce
  OK     oauth.registration
```

Doctor also checks the OAuth setup the server announces (for an `auth: {type: oauth}` server that is not logged in yet too), so a problem that would stop a client from signing in shows up before anyone tries. It only sends unauthenticated requests, and only for a server that needs authentication. For a server that connected, these checks are listed as `SKIP`:

| Check | Severity | Looks for |
|---|---|---|
| `oauth.metadata` | error | The authorization server's metadata can be found and has an authorization and a token endpoint. |
| `oauth.issuer` | error (warning if only a trailing slash differs) | The metadata's `issuer` is the authorization server the resource announced. |
| `oauth.pkce` | error | PKCE with `S256` is advertised. |
| `oauth.registration` | warning | Dynamic client registration is offered. |

These rules are in the `core` pack, and you can configure each of them (see [Rules and packs](#rules-and-packs) and [Configuring rules](#configuring-rules)).

## OAuth login

For a server that uses OAuth, set `auth: {type: oauth}` (optionally with `scopes`) and sign in once:

```console
$ mcph server auth login docs
Signing in to docs (http://localhost:8080/mcp)
Opening your browser. If it does not open, visit:
  https://auth.example.com/authorize?response_type=code&client_id=...
Logged in to docs; the token expires in 15 min.
mcph renews it with the refresh token that the server issued.
```

`mcph doctor run` then uses the stored token. An access token usually expires after a few minutes. When the server issued a refresh token, mcph uses it to get a new access token once the old one has expired (or is about to), so doctor keeps working without another sign-in for as long as the authorization server accepts the refresh token. If it does not (the refresh token expired or was revoked), or if the server issued none, doctor says so and asks you to log in again. `mcph server auth status` shows who is logged in, when each token expires and whether a refresh token is stored (`mcph server auth login` tells you right after signing in), and `mcph server auth logout docs` deletes the tokens. For CI use a bearer token from an environment variable instead.

Some authorization servers only issue a refresh token to a client that asks for the `offline_access` scope; the sign-in asks for it when the server's metadata lists it. A login made with an older mcph kept no refresh token: log in once more to get one.

Tokens are kept in files only you can read, under mcph's state directory (set `MCPH_STATE_DIR` to put it elsewhere). A refresh token stays valid much longer than an access token, so that directory deserves the care you give your other credentials.

If login stops with `Authorization server metadata issuer mismatch`, the server announces its authorization server differently from the way that server describes itself. The standard wants the two to be identical, so the right fix is on the server. When the only difference is a trailing slash (`https://auth.example.com/` against `https://auth.example.com`), you can have mcph accept it with `ignore_issuer_trailing_slash: true` under `auth`. It tolerates that one difference and nothing else.

## Recording traffic

`mcph proxy` sits between an MCP client and a server and records everything the two say to each other. You name the server as a command, or as a server of `mcph.yaml`, or take every server of `mcph.yaml` at once (see [The gateway](#the-gateway)). A client that starts its servers as processes starts the proxy instead of the server; a client that connects by URL is given the URL of a proxy that you start (see [A URL](#a-url)).

### A command

For a `stdio` server, put `mcph proxy --` in front of its command in the client's configuration (the `mcpServers` format of `.mcp.json`, Cursor and Claude Desktop):

```json
{
  "mcpServers": {
    "orders": {
      "command": "uvx",
      "args": ["mcph", "proxy", "--", "uv", "run", "python", "src/server.py"]
    }
  }
}
```

Use the client as usual. The proxy writes the trace while you do and tells you where it is on stderr, which clients show in their server logs:

```console
mcph proxy: recording to /path/to/project/.mcph/traces/20261130T101503Z-3f9a1c.jsonl
```

The traffic is passed on byte for byte, in both directions: the proxy changes nothing that the client or the server says. The server's stderr is the proxy's stderr. Signals (Ctrl-C, terminate, hangup) are passed on to the server, and when the client closes its input the server's input is closed too. The proxy exits with the server's exit code: `128 + N` if signal `N` ended it, `127` if the command was not found and `126` if it cannot be run.

### A server of mcph.yaml

`mcph proxy --server NAME` proxies a server that `mcph.yaml` already describes, with everything the entry says about it. The global `-c` goes before the command:

```json
{
  "mcpServers": {
    "docs": {
      "command": "uvx",
      "args": ["mcph", "-c", "/path/to/mcph.yaml", "proxy", "--server", "docs"]
    }
  }
}
```

- **A `stdio` server** is run as above, byte for byte, with the `command` and `args` of the entry, in the directory of `mcph.yaml`, and with its environment: the minimal one plus `env_file` and `env`, as `mcph doctor run` starts it. A client that has none of your shell's variables still gets them from `mcph.yaml` and your `.env`.
- **An `http` server** is reached over Streamable HTTP with the `auth` of the entry. With none, nothing is sent. With `type: bearer`, the token is `token: ${NAME}` from the environment *of the proxy* or, if that does not have it, from the `env_file` of the entry: a client that does not have your shell's variables needs nothing in its own `env` setting when the entry has an `env_file` with the variable, and if it is set nowhere the proxy stops with a message before anything starts. With `type: oauth`, run `mcph server auth login NAME` first: the proxy sends the stored token and renews it with its refresh token whenever it has expired, also in the middle of a session. A login made or renewed in another terminal is used at once.
- **The relay is transparent.** There is one session at the server for the whole session of the client, and the messages go through as they are, including the server's own requests to the client (sampling, roots, elicitation). The trace says `reserialized`: the messages are parsed and sent on again, so the HTTP details are the proxy's.
- **A server that is down, or refuses a request, is answered, never waited on.** The client gets an error that says why and what to do, and the same text goes to stderr: `mcph proxy: cannot reach http://localhost:8080: ConnectError: All connection attempts failed`, `mcph proxy: not logged in (run `mcph server auth login docs`)`, `mcph proxy: the server rejected the token in $DOCS_TOKEN (HTTP 401)`.
- **It ends** when the client closes its input, after the server has answered what is still open (at most five seconds, so that `echo request | mcph proxy --server docs` gets its answer), and the session at the server is ended properly. A SIGINT, SIGTERM or SIGHUP ends it at once. The exit code is `0`, or `128 + N` for a signal, or the server's own for a `stdio` server.
- **Not supported:** the older HTTP+SSE transport (a server with a separate `/sse` endpoint), which MCP has deprecated in favour of Streamable HTTP, and tool parameters that the newer protocol revision copies into HTTP headers. A client that connects by URL can use [the listener](#a-url).

### A URL

A client that connects by URL, instead of starting a process, needs `--transport http`. It serves a server of `mcph.yaml` that is itself an `http` server (Streamable HTTP) on a local address, and you start the proxy yourself:

```
$ mcph proxy --server docs --transport http --port 8081
mcph proxy: recording to /path/to/project/.mcph/traces/20261130T101503Z-3f9a1c.jsonl
mcph proxy: proxying the server docs (http)
mcph proxy: listening on http://127.0.0.1:8081/mcp
```

Then give the client that URL, for example in VS Code's `.vscode/mcp.json`:

```json
{ "servers": { "docs": { "type": "http", "url": "http://127.0.0.1:8081/mcp" } } }
```

- **It is the server, as far as the client can tell.** A request goes to the URL of the entry as it is, and the answer (one JSON body, or an event stream) comes back as it is. mcph does not interpret the protocol, so both generations of Streamable HTTP (with or without the `initialize` handshake and a session id), streamed progress, the server's own requests to the client and resuming a stream with `Last-Event-ID` work as they do without the proxy.
- **mcph signs in for the client.** The `auth` of the entry (the stored OAuth token, renewed as it expires, or `token: ${NAME}`) replaces any `Authorization` header of the client, which therefore needs no login of its own. An entry without `auth` leaves the client's own header alone. A server that is down, or refuses a request, is answered with its HTTP status and an error that says why and what to do, with the id of the request (`mcph proxy: not logged in (run `mcph server auth login docs`)`). Cookies and `Origin` of the client are not sent on, and `Set-Cookie` and `WWW-Authenticate` of the server are not sent back, so that a client does not start a sign-in of its own at the real server.
- **`--port 0` picks a free port**, which is what a program that starts the proxy wants. The URL is printed once the proxy accepts connections, and written to `--ready-file FILE` if you give one, so that the program can wait for the file (it is written whole, an old one is removed at the start, and it is removed again at the end). `--host` (default `127.0.0.1`), `--port` (default `8080`) and `--path` (default `/mcp`) say where. A port that is taken stops the proxy at once, before a trace exists.
- **Only you can reach it, unless you say otherwise.** The proxy uses your login of the server, so anyone who can reach it can use it. It listens on a loopback address, and refuses any other `--host` unless you give `--allow-remote`. On loopback a request whose `Host` or `Origin` is not a loopback name (a web page that has pointed its own name at `127.0.0.1`) is refused with `421` or `403`.
- **It ends on SIGINT, SIGTERM or SIGHUP, with exit code `0`.** It stops accepting connections, ends the event streams that clients keep open, lets requests in progress finish for up to five seconds (one that is still running then is answered with an error that says the proxy is shutting down), ends the sessions that the server opened, as their clients would have, and ends the trace. A second signal does not wait.
- **The trace is one for the whole run**, whichever clients come and go, and says `passthrough`: the frames are the bytes that went through. The format has no field for which client a frame belongs to, so when several clients use the proxy at the same time their frames are interleaved, and `latency_ms` can pair wrongly if two of them use the same id at the same moment.
- **Not supported:** a `stdio` server on a URL (use it through the standard input and output), TLS, and CORS for web pages that call the proxy.

### The gateway

`mcph proxy --gateway` serves **every server of `mcph.yaml` as one MCP server**: a client has a single entry in its configuration for all of them, and the trace shows what went to each. The global `-c` goes before the command, and the gateway needs the `gateway` extra of mcph (see below), which `uvx --from 'mcph[gateway]'` brings:

```json
{
  "mcpServers": {
    "mcph": {
      "command": "uvx",
      "args": ["--from", "mcph[gateway]", "mcph", "-c", "/path/to/mcph.yaml", "proxy", "--gateway"]
    }
  }
}
```

A client that connects by URL needs `--transport http`, with `--host`, `--port`, `--path` and `--ready-file` as for [a URL](#a-url) (the gateway listens on a loopback address and is not reachable by anyone else, unless you give `--allow-remote`):

```
$ mcph proxy --gateway --transport http --port 8081
mcph proxy: recording to /path/to/project/.mcph/traces/20261130T101503Z-3f9a1c.jsonl
mcph proxy: starting the gateway for orders (stdio), billing (http)
mcph proxy: the gateway serves orders (2 tools), billing (2 tools)
mcph proxy: listening on http://127.0.0.1:8081/mcp
```

- **It needs the `gateway` extra**, which installs FastMCP's server part (15 packages, about 7 MB, that nothing else in mcph uses): `pip install 'mcph[gateway]'`, or `uvx --from 'mcph[gateway]' mcph ...` to run it without installing. Without it `mcph proxy --gateway` says so and stops before it starts anything (exit code `2`, no trace); every other command works without it.
- **Names get the name of their server in front**, so that two servers can both have a `get_order`: with the servers `orders` and `billing` the client sees `orders_get_order` and `billing_get_order`. The same goes for prompts (`orders_greet`); a resource gets it as the first part of its path (`data://orders/items`). A call goes to the server it belongs to, under the name that server knows. `--no-namespace-tools` leaves the names as the servers have them, to see what a client does when names collide: the first server of `mcph.yaml` wins, and mcph says which tools are hidden when it starts.
- **One session per server for the whole run.** All the servers are started and connected when the gateway starts, in parallel, and kept: a `stdio` server is one process for as long as the gateway runs, not one for every request. If one cannot be reached the gateway stops at once, with an error that names it, instead of serving fewer tools than the client expects (exit code `1`): `Error: the server 'billing': cannot reach http://localhost:8080: ConnectError: All connection attempts failed`. Every entry is checked first, the same way as for `--server`, and an entry that cannot be used (a variable that is not set) is named before anything starts.
- **The gateway is a server of its own towards the client**, not a pass-through: the client sees one merged list, whichever generation of the protocol it speaks, and the gateway speaks to each server as a client of the older generation (with the `initialize` handshake). Progress that a server reports is passed on to clients of both generations. The questions it asks the client in the middle of a call (elicitation, sampling, roots) are passed on to clients of the older generation only (the one with the `initialize` handshake): for a client of the newer one the call ends with an error that says so.
- **The trace holds both conversations**, in one file for the whole run, `reserialized`. The frames **without** a `server` are what the client and the gateway say to each other (the client's `initialize`, the merged list of tools with their prefixed names, its calls and the answers), recorded the way `--server` records its client. The frames **with** a `server` are the traffic between the gateway and that server, under the names that server knows. The two are interleaved in the order they happened, each with its own request ids and its own `latency_ms`, so a call of the client is followed by the calls that the gateway makes to the servers for it. The tokens that go to the servers are hidden, as for `--server`. With several clients at once on a URL their frames are interleaved, as for [a URL](#a-url).
- **It ends** when the client closes its input (on stdio), or on SIGINT, SIGTERM or SIGHUP, also while the servers are still starting. The sessions at the servers are ended, so no server process is left, and the trace is ended. The exit code is `0`, or `128 + N` for a signal on stdio.
- **Limits:** a server that exits while the gateway runs is not started again (its tools disappear from the list, and mcph says so on stderr: restart the gateway); there is no way yet to serve only some of the servers; the output of a `stdio` server on stderr is the gateway's stderr.

### The trace

- It goes to `.mcph/traces/<session>.jsonl` in the directory where the client starts the proxy, or next to the `mcph.yaml` selected with `-c` (for `--server`, always next to it). `--trace-out FILE` picks the file instead. An existing file is never overwritten.
- Secrets such as tokens, passwords and `Authorization` values are hidden unless you pass `--no-redact`, and so is every token that mcph itself sends to an `http` server. A trace still holds the arguments and results of tool calls, which can be sensitive: treat it like a log. `.mcph/` gets a `.gitignore` so that it is not committed by accident.
- The [trace format](https://github.com/mcp-harness-io/mcph/blob/main/docs/trace-format.md) describes the events: every frame with its time, and for a response how long the server took. A trace of the gateway names its servers (`upstreams`) and says which server a frame was with (`server`), or, without one, that it was the client's.

### Reading a trace

`mcph trace print FILE` prints what a trace says, so that you do not have to read the JSON lines:

```console
$ mcph trace print .mcph/traces/20261130T101503Z-3f9a1c.jsonl
Trace 20261130T101503Z-3f9a1c (.mcph/traces/20261130T101503Z-3f9a1c.jsonl)
  recorded by mcph 0.3.0 (reserialized); complete: 23 messages in 240 ms
  gateway of 2 servers, tool names prefixed with the server
    orders   uv run python orders.py (stdio, calls itself orders 1.0)
    billing  https://billing.example/mcp (http, calls itself billing 1.0)
  client: demo-client 1.0, MCP 2025-06-18
  messages: 7 between the client and the gateway, 7 with orders, 9 with billing

Tools offered to the client (3): orders_get_order, billing_get_order, billing_pay
Requests of the client: initialize 1, tools/list 1, tools/call 1

Tool calls (1: 1 ok):
  seq 20  billing.pay {"amount":5}  (called as billing_pay)
          ok, 30 ms, 79 B: paid 5

Problems: none
```

- It shows the session (how it ended, the servers, the client), the tools the client was offered, every tool call, and what went wrong: error answers to other requests, requests that were never answered, frames that are not JSON-RPC.
- **A tool is named `server.tool`**: the name of the server in `mcph.yaml`, a dot, and the tool's own name at that server. Behind a gateway the client uses the prefixed name (`billing_pay`); mcph works out the server and the tool (`billing.pay`) from the tool lists of the servers in the same trace, and shows the name the client used next to it. For a trace of one server, the server is the name that the trace records (`--server NAME`), if it has one.
- **A call ends in one of four ways:** *ok*; *tool error* (the result says `isError`); *protocol error* (a JSON-RPC error, such as an unknown tool or arguments the server refused); *unanswered*. A call to a tool that the client had not been offered says so.
- It exits with `0` when it could read the trace (the problems it lists do not change that), and with `1` when it could not: the file is not a trace, or is of a version of the format that this mcph does not know.

## Evaluating a server

`mcph eval` runs tasks against your server with an agent, and checks what happened: the session that the proxy recorded (every call, its arguments and its answer) and what the agent answered. mcph has no agent of its own: you name one (`claude`, in a sandbox, or any command), and mcph gives it the server to work with.

Two kinds of files say what to do. A **suite file** says *what to check*: tasks, and what each session has to show. **`eval` in `mcph.yaml`** has a list of `suites`, as the top of the file has a list of `servers`, and says *how to run each one*: its file, which server the agent gets, which agents (**runners**) there are for it, and a **matrix** of runners, models and servers, so that a suite can be run with different agents or models and the results compared side by side.

```yaml
# mcph.yaml (the servers are above)
eval:
  suites:
    - name: order-tracking
      path: suites/order-tracking.yaml
      target: orders
      runners:
        haiku: {preset: claude, model: haiku}

    - name: order-cancellation
      path: suites/order-cancellation.yaml
      target: orders
      runners:
        sonnet: {preset: claude, model: sonnet}
        haiku: {preset: claude, model: haiku}
      matrix:
        runner: [sonnet, haiku]
      repeat: 5                # and 5 times, unless a task says otherwise
```

```yaml
# suites/order-tracking.yaml
tasks:
  - id: where-is-my-order
    prompt: Where is order 1042, and has it shipped?
    expect_tools: [orders.get_order]
    forbid_tools: [orders.cancel_order]
    max_tool_calls: 4
    answer: {contains: in transit}
```

```yaml
# suites/order-cancellation.yaml
tasks:
  - id: cancel-after-shipping
    prompt: Cancel order 1042 and tell me what happened.
    expect_tools: [orders.cancel_order]
    answer: {contains: shipped}
    checks:
      allow_tool_errors: [orders.cancel_order]   # the tool is meant to say no here
  - id: cancel-before-shipping
    prompt: Cancel order 1044 and tell me what happened.
    expect_tools: [orders.cancel_order]
    repeat: 1                                    # a plain cancellation does not need five runs
```

```console
$ mcph eval
mcph eval: 13 runs: order-tracking: 1 cell (haiku/orders) x 1 task; order-cancellation: 2 cells (sonnet/orders, haiku/orders) x 2 tasks x 1 to 5 repeats; the runs of claude cost at most $13.00
mcph eval: [1/13] haiku/orders order-tracking where-is-my-order: running claude
mcph eval: [1/13] haiku/orders order-tracking where-is-my-order: done in 7.9 s
mcph eval: [2/13] sonnet/orders order-cancellation cancel-after-shipping (1 of 5): running claude
...
Checks of .mcph/traces/20261202T095905Z-7af762-order-cancellation-sonnet_orders-cancel-after-shipping-r1.jsonl (suite order-cancellation, task cancel-after-shipping, cell sonnet/orders, run 1 of 5)
  ran claude in 5.6 s, exit code 0, 2 turns, $0.0151
  answer: I didn't cancel order 1042, because it has already shipped. Its status is "in transit" and its tracking number is T-1042-X. The cancel function only works on orders that haven't shipped, so I didn't …
  OK     agent_finished
  FAIL   expect_tools: orders.cancel_order was not called
  OK     answer
  ...

1 of 9 checks failed, 2 off.

...
Checks of .mcph/traces/20261202T095905Z-7af762-order-cancellation-haiku_orders-cancel-before-shipping.jsonl (suite order-cancellation, task cancel-before-shipping, cell haiku/orders)
  ran claude in 4.3 s, exit code 0, 2 turns, $0.0108
  answer: Order 1044 has been successfully cancelled.
  OK     agent_finished
  OK     expect_tools
  OK     no_tool_errors
  ...

8 checks passed, 2 off.

...
Results of each task of order-cancellation in each cell:
                          sonnet/orders  haiku/orders
  cancel-after-shipping   1/5 FAIL       5/5
  cancel-before-shipping  OK             OK

4 of 13 traces failed.
```

That is a real run (13 runs, $0.15; some of the runs and of the check lines are left out): `sonnet` did not try to cancel the shipped order in 4 of its 5 runs, while `haiku` tried in all 5 (and was told no, which the suite allows). The pass rate of a task in a cell is how many of its runs passed (`1/5`); `5/5` is pass^k, that every run passed. One run could not have told whether what `sonnet` did was its habit or luck. `cancel-before-shipping` asks for `repeat: 1` itself, so it ran once in each cell.

- **`mcph eval`** runs every suite of `eval.suites`, or the ones whose names you give (`mcph eval order-cancellation`), one after the other. Every task of a suite runs in every cell of *its* matrix. For each run the agent gets a fresh server: it starts `mcph proxy` itself, through an MCP configuration that mcph writes, in an empty directory, and the proxy records the session to `.mcph/traces/` (kept out of Git). If the time is up, or you press Ctrl-C, mcph stops the agent and everything it started (that is done with a process group, so `mcph eval` is for macOS and Linux, or WSL; it has not been tried on Windows).
- **Repeats:** `repeat: 5` runs every task of a suite 5 times in each cell, because an agent does not do the same thing every time; a task of the suite file can have a `repeat` of its own (and a `pass_rate`), for the ones that need fewer or more runs than the rest. A task passes in a cell when its **pass rate**, the share of its runs that passed, reaches its `pass_rate` or that of its suite (by default `1`: every run); pass^k says that all of them did. A run that failed is written out check by check, one that passed in a few lines. `--repeat N` replaces `repeat` of every task for one command. Repeats multiply the runs, and what they cost.
- **The matrix** of a suite has the axes `runner`, `model` and `target` (a server of `mcph.yaml`, or `gateway` for all of them), and optional `exclude` and `include`. Without one there is one run of each task. `--runner`, `--model` and `--target` replace an axis for one command: `mcph eval order-cancellation --runner haiku --model haiku,sonnet`. A matrix multiplies the runs, so mcph says how many there are, and what the runs of `claude` can cost at most, before it starts.
- **`preset: claude` runs in a sandbox**: `claude -p` with the server under test and nothing else, not the MCP servers that are configured for you (a Jira server, say), not Bash or the file tools, not your settings. mcph does not take that on trust: it reads what `claude` says it has, and **stops the run at once, with exit code `2`**, if there is anything else.
- **A runner can also be a command** that starts any agent: `command: [my-agent, --model, "{model}", "{mcp_config}", "{prompt}"]`. mcph tells it where the server is with `{mcp_config}`; what it prints is its answer. For another agent the sandbox is yours to make.
- **Checks:** `OK`, `FAIL` (with every problem), `SKIP` (the trace does not have what the check needs) or `OFF`. The session checks (every call worked, the arguments fit the schema of the tool, no tool that was not offered, no loop, `latency_under`, `response_size_under`, ...) need no task; a task adds `expect_tools`, `expect_sequence`, `forbid_tools`, `max_tool_calls`, `expect_args` and `answer`; a run also has `agent_finished`. A tool is written `server.tool`, also behind the gateway.
- **Exit codes:** `0` when no check failed (when every task passed in every cell, if it was run), `1` when one did, `2` when `mcph eval` could not run (a file it needs cannot be read, an unknown suite, runner, task or target, an agent that cannot start or breaks the sandbox, a report that cannot be written).
- **A recorded trace** is checked with `mcph eval order-tracking --trace FILE` (a suite of `mcph.yaml` by its name, or a suite file), without running anything: from any client, or a script. Several `--trace FILE` are checked against the same checks.
- **Reports:** `--report FILE` writes the results as one JSON report ([docs/run-report.md](https://github.com/mcp-harness-io/mcph/blob/main/docs/run-report.md): the cells, every run and every check, with a JSON Schema), `--junit FILE` as JUnit XML for the test reports of CI. Both are written after the text.
- **Printing a report:** `mcph report print report.json` prints a report as `mcph eval` printed it (the same text, made by the same code), so that it can be read later, from a CI artifact or on another machine.
- **Comparing two runs:** `mcph report diff base.json head.json` compares two run reports and lists the tasks that passed in a cell before and do not now (a regression), with the checks that failed. What a suite accepts (`pass_rate: 0.8`) is not a regression. `--fail-on-regression` makes it exit with `1`, `--markdown` writes it for a pull request comment or `$GITHUB_STEP_SUMMARY`, and it exits with `2` when it has nothing to compare, so that a comparison of nothing does not pass.

[docs/eval-suites.md](https://github.com/mcp-harness-io/mcph/blob/main/docs/eval-suites.md) has the whole reference: the suite file and every check, `eval` and the matrix, the runners and the sandbox, the results, printing a report, and comparing two runs.

## Rules and packs

Rules come from **packs**. A pack is a directory with a `mcph-pack.yaml` that lists the Python files defining its rules. Name the packs doctor should use under `extends` in `mcph.yaml`:

```yaml
extends:
  - builtin:core      # the rules that ship with mcph
  - ./packs/acme      # a pack of your own, relative to the directory of mcph.yaml
```

A source is a directory (relative to the directory of `mcph.yaml`, absolute, or starting with `~`) or `builtin:<name>` for a pack bundled with mcph. **Without any pack there is no rule**: `mcph doctor run` then only reaches the servers and warns about it, and the warning fails a `--strict` run.

`mcph pack list` shows the packs that are loaded and the rules each one defines:

```console
$ mcph pack list
Packs (from /path/to/mcph.yaml)

core 1.0.0 (builtin:core)
  The rules that ship with mcph.
  core.tool_name_snake_case
  oauth.metadata
  oauth.issuer
  oauth.pkce
  oauth.registration

acme 1.0.0 (./packs/acme)
  Our checks.
  acme.no_delete
```

### The core pack

`builtin:core` has the `oauth.*` checks described above and this rule:

| Rule | Severity | Checks |
|---|---|---|
| `core.tool_name_snake_case` | warning | Tool names are snake_case, like `get_order` rather than `getOrder`. |

Warnings do not fail the run unless you pass `--strict`.

### Writing a pack

```
packs/acme/
  mcph-pack.yaml
  rules/no_delete.py
```

```yaml
# mcph-pack.yaml
name: acme
version: "1.0.0"
description: Our checks.        # optional
rules:
  - rules/no_delete.py          # the files that define rules
```

```python
# rules/no_delete.py
from mcph.extensions import doctor_rule

@doctor_rule(id="acme.no_delete", description="No tool deletes data.", severity="error")
def no_delete(context):
    return [
        f"{tool.name} deletes data"
        for tool in context.snapshot.tools
        if tool.name.startswith("delete")
    ]
```

Rules can look at the arguments and the annotations of a tool too:

```python
@doctor_rule(id="acme.say_read_only", description="Every tool says whether it is read-only.")
def say_read_only(context):
    for tool in context.snapshot.tools:
        if tool.annotations.read_only_hint is None:
            yield f"{tool.name} does not say whether it is read-only"


@doctor_rule(id="acme.describe_parameters", description="Every parameter has a description.")
def describe_parameters(context):
    for tool in context.snapshot.tools:
        for name, schema in tool.input_schema.get("properties", {}).items():
            if not schema.get("description"):
                yield f"{tool.name}: parameter {name!r} has no description"
```

- A rule id looks like `namespace.name` (lowercase letters, digits and `_`, and `-` in the namespace) and is unique across all packs. Two packs with the same name are an error too.
- The function gets a context: `server` (the entry of `mcph.yaml`), `snapshot` (what the server exposes: `server_name`, `server_version`, `protocol_version`, `startup_seconds` and `tools`; `None` if mcph could not connect), `error` (why it could not), `timeout`, and a `cache` shared by the rules that check one server.
- Each tool in `snapshot.tools` is described as the server sent it: `name`, `title` and `description` (each may be `None`), `input_schema` (the JSON Schema of the arguments, a dict), `output_schema` (a dict, or `None`) and `annotations` with `title`, `read_only_hint`, `destructive_hint`, `idempotent_hint` and `open_world_hint`, each `None` when the server did not say. Do not change what you receive: every rule of a server sees the same objects. (`ServerSnapshot` and `ToolInfo` are in `mcph.mcp_client`, if you want to build them in tests of your rules.)
- It returns a message for each problem, at the rule's severity, or `Issue(message, severity)` objects (from `mcph.rules`) to choose the severity per problem. It may be `async`, and it may raise `SkipRule("why")` (from `mcph.rules`) when there is nothing to check.
- `@doctor_rule` also takes `transports=["http"]` for a rule that only applies to HTTP servers (the default is both kinds), and `needs_connection=False` for a rule that is still useful when the server could not be reached (without it, such a rule is skipped, because there is no snapshot).
- A rule that raises is reported as an error finding, and the other rules still run.
- A pack file is imported on its own, so it can import `mcph` and installed packages but not the other files of the pack.
- **The Python of a pack runs with your privileges**, like the `command` of a `stdio` server in the same file, so list only packs you trust.

While you write a pack, `mcph pack verify packs/acme` checks it without a config or a server: the manifest, that every listed file exists, imports and defines rules, and that rule ids are not used twice. It lists every problem (and exits with `1`), or the rules it found:

```console
$ mcph pack verify packs/acme
acme 1.0.0: valid, 1 rule
  acme.no_delete  error  No tool deletes data.

$ mcph pack verify packs/other
packs/other: 2 problems
  pack 'other': rules/missing.py, listed under rules in mcph-pack.yaml, does not exist
  pack 'other': cannot import broken.py: SyntaxError: invalid syntax (broken.py, line 1)
```

### Configuring rules

Under `doctor.rules` in `mcph.yaml`, set how serious a rule is, or turn it off. This applies to the rules of every loaded pack, by rule id:

```yaml
doctor:
  rules:
    core.tool_name_snake_case: error   # a camelCase tool name now fails the run
    oauth.registration: off            # do not check for dynamic client registration
```

- `error`: findings of the rule are errors, so the run fails (exit code `1`).
- `warn`: findings are warnings, which fail the run only with `--strict`.
- `off`: the rule does not run, and the report lists it as `OFF`. Write it without quotes if you like: YAML reads `off` as false, and mcph accepts that.

Rules you do not list keep their default severity. A configured severity replaces the default for all findings of that rule, so `oauth.issuer: error` also makes a trailing-slash difference an error. With all four `oauth.*` checks off, doctor does not contact an authorization server at all.

A rule id that no loaded pack defines is a config error (exit code `2`) that lists the known ids and suggests the closest one. (Without `extends` no rule is known, and the message says how to add the core pack.)

`mcph doctor rules` lists the rules of the loaded packs, under the pack each comes from, with the setting that applies and the default next to one you changed. It starts no server:

```console
$ mcph doctor rules
Rules (settings from /path/to/mcph.yaml)

core (builtin:core)
  core.tool_name_snake_case  error (default: warn)  Tool names are snake_case.
  oauth.metadata             error                  The authorization server's metadata can be found and has an authorization and a token endpoint.
  oauth.issuer               error                  The metadata's issuer is the authorization server the resource announced (a difference of only a trailing slash is a warning).
  oauth.pkce                 error                  PKCE with S256 is advertised.
  oauth.registration         off (default: warn)    Dynamic client registration is offered.

acme (./packs/acme)
  acme.no_delete             error                  No tool deletes data.
```

Without a `mcph.yaml` in the current directory, or without `extends`, no pack is loaded and the listing says so. A `-c` path that does not exist, a pack that cannot be loaded, or an invalid config is an error (exit code `2`).

## mcph.yaml

- `version`: optional, `"1"`.
- `servers`: a list of servers, each with:
  - `name`: unique; letters, digits, `_` and `-`.
  - `transport`: `stdio` or `http`.
  - `command`, `args` (`stdio`): how to start the server.
  - `env` (`stdio`, optional): the server's environment variables, in which `${NAME}` takes a variable.
  - `env_file` (optional): dotenv files that hold variables, for a `stdio` server to get and for an `http` server (with a bearer token) to take the variables of its `${...}` from (see [Environment variables of a server](#environment-variables-of-a-server)).
  - `url` (`http`): the Streamable HTTP endpoint of a server you have already started, such as `http://localhost:8080/mcp`. mcph does not start it.
  - `auth` (`http`, optional), one of:
    - `type: bearer` and `token`, a reference such as `${DOCS_TOKEN}` to the environment variable that holds the bearer token (the same references as in `env` values, so it can also sit in other text). mcph takes the token from its own environment or, if that does not have the variable, from the `env_file` of the server, never from the YAML: a token written there is refused. It is sent as `Authorization: Bearer ...` to the server's URL only, and never printed. In YAML's `{...}` style put it in quotes: `auth: {type: bearer, token: "${DOCS_TOKEN}"}`. Earlier versions wrote this as `token_env: DOCS_TOKEN`, which is now an error that says what to write instead.
    - `type: oauth`, optional `scopes` and optional `ignore_issuer_trailing_slash`: sign in through the browser with `mcph server auth login <server>` (see [OAuth login](#oauth-login)).
  - `primary`: optional `true` for the server you are developing (at most one).
- `extends`: optional list of the packs whose rules doctor uses: a directory or `builtin:<name>` (see [Rules and packs](#rules-and-packs)). Without any pack there is no rule; `builtin:core` has the rules that ship with mcph.
- `doctor`: optional settings for `mcph doctor`.
  - `rules`: how serious each rule is, as `rule id: error | warn | off` (see [Configuring rules](#configuring-rules)).
- `eval`: optional settings for `mcph eval` (see [Evaluating a server](#evaluating-a-server)).
  - `suites`: the list of the suites to run, each with:
    - `name`: unique; letters, digits, `_` and `-`.
    - `path`: the suite file, with its tasks and checks, relative to `mcph.yaml`.
    - `target`: the server the agent gets, or `gateway` (default: the only server, or the gateway when there are several).
    - `runners`: the ways to run an agent for this suite, by name: `preset: claude` (with `model`, `max_turns`, `max_budget_usd`) or a `command`, and a `timeout`.
    - `runner`: the runner to use when nothing else says (default: the only one).
    - `matrix`: the cells to run: `runner`, `model` and `target` lists, `exclude` and `include`.
    - `repeat`: how many times every task is run in each cell (default `1`), and `pass_rate`: the share of those runs that has to pass (default `1`, all of them). A task of the suite file may have its own `repeat` and `pass_rate`, which replace these for it.

`stdio` servers run from the directory containing `mcph.yaml`, with a minimal environment (`HOME`, `PATH`, ...) plus what `env_file` and `env` give them; the rest of your environment is not passed on. Unknown keys are rejected, so typos are reported.

### Environment variables of a server

A `stdio` server starts with a minimal environment (`HOME`, `PATH`, ...), so your shell's variables, API keys included, do not reach it by themselves. The bearer token of an `http` server is a variable too. There are two ways to give a server what it needs, and you can use both.

**From the environment mcph runs in**, with `${NAME}` in an `env` value (or in a `token`):

```yaml
servers:
  - name: orders
    transport: stdio
    command: uv
    args: ["run", "python", "src/server.py"]
    env:
      LOG_LEVEL: WARNING       # a plain value
      API_KEY: ${API_KEY}      # the variable API_KEY of the environment mcph runs in
      DATA_DIR: ${HOME}/data   # a variable can sit in other text
```

```console
$ API_KEY=abc123 mcph doctor run
```

**From a dotenv file**, with `env_file`, so the secrets never touch `mcph.yaml`. Every server has files of its own, and an `http` server with a bearer token can have one too:

```yaml
  - name: orders
    # ...
    env_file: .env             # or a list of files: [base.env, local.env]
  - name: docs
    transport: http
    url: https://docs.example.com/mcp
    env_file: docs.env         # the variables that ${...} in the token may use
    auth: {type: bearer, token: "${DOCS_TOKEN}"}
```

```ini
# .env (keep it out of Git)
API_KEY=abc123
LOG_LEVEL=DEBUG
```

- `${NAME}` is replaced by the variable `NAME` of the environment mcph runs in and, if that does not have it, by the variable `NAME` of the `env_file` files of the entry. It can sit in other text (`Bearer ${TOKEN}`), `$$` is a literal `$`, and a variable that is set nowhere is an error that names it and the files that were looked in. Values are never printed. In YAML's `{...}` style, put the value in quotes: `env: {API_KEY: "${API_KEY}"}`.
- `env_file` is a path, or a list of paths, relative to the directory of `mcph.yaml` (`~` and absolute paths work). It uses dotenv syntax (`KEY=value`, `#` comments, quotes, `export KEY=value`) and nothing in it is expanded. It usually holds secrets, so keep it out of Git with `.gitignore`. It is read when the server starts (for an `http` server, when mcph reads its token); a file that is missing is an error for that server.
- **The precedence is the one of Docker Compose.** For `${...}` the environment wins over the files: a key or a token that you export beats the one in `.env`, which is only used when the environment does not have the variable, so a stale `.env` cannot hide a new value. For a `stdio` server the `env` entries win over the variables of the files (as `environment:` wins over `env_file:` in Compose), and a later file wins over an earlier one. A variable of a file that `env` does not name is passed on as it is.
- An `http` server has no process to give variables to: its `env_file` only holds what the `${...}` of its bearer token may use, so it is an error without `auth: {type: bearer}`.
- This is for the servers in `mcph.yaml`. `mcph proxy -- <command>` passes its own environment on to the server unchanged: give that server its variables in the client's own `env` setting.
