Skip to main content
Glama
README.md
# mcp-plan-runner

<!-- mcp-name: io.github.costas1379/mcp-plan-runner -->

An MCP proxy that lets a model run a whole **plan** of tool calls in one call.

A normal agent calls one tool, reads the result, decides, and calls the next tool.
Each step costs a model turn, and every intermediate result goes into the context.
With `run_plan`, the model writes the full plan once: calls, loops and conditions.
The runner executes it next to the tools and returns only the final value.

It works with any MCP server. The servers need no changes.

## Results

On a mail job with about 30 tool calls (read 27 threads in two mailboxes, then build one
table), Claude Code with the plan runner needed **3 turns instead of 31** and cost
**84% less** (median 0.105 USD instead of 0.649), with the same answer totals.
A rerun on the final code cost about the same (median 0.111 USD), but took 5 turns: Gmail's
per-minute quota rejected some reads, and the model read them again in a second plan.
On small jobs the saving is smaller. Details and all rounds: [docs/benchmarks.md](docs/benchmarks.md).

## Quick start

You need [uv](https://docs.astral.sh/uv/). `uvx` downloads and runs the package from PyPI.

1. Write a config file, for example `~/.config/mcp-plan-runner/config.json`, with your servers
   (see [Configuration](#configuration) and [config.example.json](config.example.json)).
2. Add the runner to an MCP client, for example Claude Code:

```bash
claude mcp add plan-runner -- uvx mcp-plan-runner /abs/path/to/config.json
```

Other clients: the command is `uvx` and the arguments are `mcp-plan-runner /abs/path/to/config.json`.
The runner talks MCP over stdio. `pipx run mcp-plan-runner config.json` works too.

From source:

```bash
git clone https://github.com/costas1379/mcp-plan-runner
cd mcp-plan-runner
uv sync
cp config.example.json config.json   # edit: your servers and allow list
uv run mcp-plan-runner config.json   # runs the proxy on stdio
```

## Configuration

```json
{
  "servers": {
    "mail": {"command": "uv", "args": ["run", "mail-mcp"], "env": {"TOKEN_FILE": "/path"},
             "cwd": "/path", "max_parallel": 1, "log": "/path/logs/mail.log"},
    "docs": {"url": "https://example.com/mcp"}
  },
  "allow_in_plans": ["mail.search", "mail.get_thread"],
  "schema_cache": true
}
```

| Key | Meaning |
| --- | --- |
| `servers.<name>` | A stdio server (`command`, `args`, `env`, `cwd`) or an HTTP server (`url`). The name may not contain `.`. |
| `max_parallel` | Calls in flight to this server (default 4). Use `1` for servers that cannot handle parallel calls. |
| `log` | Stdio only: append the server's stderr to this file (mode 0600). A relative path starts from the folder the proxy runs in. |
| `allow_in_plans` | Tools (exact names or `fnmatch` patterns) that may run in a plan although they are not marked read-only. |
| `schema_cache` | `true` (default): learn output schemas, see [Learned output schemas](#learned-output-schemas). A file path: keep them in that file. `false`: do not learn. |

## Tools

| Tool | Purpose |
| --- | --- |
| `list_tools(query, server)` | Find tools. With a query, it returns the best matches (at most 15) with input and output schemas. Without a query and with more than 60 tools, it returns only the names, grouped by server. |
| `call(tool, args)` | Call one tool and return its result as JSON. Use it to see an output shape. |
| `run_plan(plan)` | Validate and run a plan. Returns `ok`, `result`, `calls` and a short `trace`. |

Tool names are `server.tool`, for example `mail.search`.

The client sees only these three tools, however many tools the servers behind the proxy
have. The model finds the tools it needs with `list_tools` and a query, so the schemas of
hundreds of tools never go into its context. Above 60 tools, a list without a query
gives only the names.

## Learned output schemas

A model writes a plan in one go only when it knows the shape of each tool's result.
Many MCP servers do not declare an `outputSchema`, so the model must first make a probe
`call` to see the shape. To avoid that probe on later runs, the runner learns the shape:

- Each time a tool without an output schema returns a result (from `call` or inside a plan),
  the runner reads the JSON types and keys of the result and adds them to what it saw before.
- A key becomes a field name only after it was in 3 different results. A result that is the
  same as a recent one does not count again. Real field names (`id`, `subject`,
  `next_page_token`) repeat in every result. Most data used as keys (names, ids) does not,
  so it is not stored.
- `list_tools` with a query shows the learned schema as `output_schema`, with
  `"output_schema_learned": true`. Any field in it may be missing in a result. A schema that
  the server declares always wins.
- The schemas are kept in `~/.cache/mcp-plan-runner/schemas.json` (or under `$XDG_CACHE_HOME`),
  file mode 0600 in a 0700 folder, so the next session starts with them. When a tool's input
  schema changes, its learned schema is dropped. To start again, delete the file.

What the cache file holds:

- JSON types and field names that were in at least 3 results. Never values.
- For a key seen fewer times: a hash of it and a count. The hash hides the key from someone
  who reads the file, but not from someone who guesses it.
- An object is stored as a map, with no key names at all, when a key does not look like a
  field name (emails, dates, ids with two or more digits, keys longer than 32 characters or
  with more than three `_` or `-`), when three or more keys hold objects of the same shape,
  or when more than 50 different keys never repeat.
- Stable names that a tool uses as keys in every result, for example
  `{"Alice": 3, "Bob": 5}` for the same users each time, look like field names. They are
  stored after 3 different results.

Field names come from tool results, which can contain untrusted text (a web page, an email).
A source that puts the same short key in 3 different results can get it into a learned schema,
and the model reads it there. If your servers return text from untrusted sources and that
matters to you, turn learning off.

To turn learning off, set `"schema_cache": false` in the config.

## A plan

```json
{"start": "find", "steps": {
  "find": {"call": "mail.search", "args": {"q": "invoice"},
           "next": [{"if": "length(find.messages) == `0`", "goto": "none"}, {"else": "read"}]},
  "read": {"for_each": "find.messages", "as": "m", "call": "mail.get_thread",
           "args": {"id": "{{m.thread_id}}"}, "parallel": 4, "retry": 2, "next": "out"},
  "out":  {"return": "read[].{subject: subject, from: from}"},
  "none": {"return": "'no invoices'"}}}
```

Step kinds:

- `call`: one tool call.
- `for_each`: one tool call for each item of a list, optionally in parallel. Gives a list.
  With `"do": {"start", "steps"}` instead of `call`, it runs a small sub-plan for each item (at most 2 levels deep).
- `paginate`: calls a tool again with the cursor from the last page until there is no cursor. Gives one list.
- `return`: ends the plan with a value.

Options: `retry` (0 to 5) tries a failed tool call again after 1 s, 2 s, 4 s ... (each try counts as a call);
`on_error` is `stop` (default) or `skip`.

Flow: `next` is a step id or a list of `if`/`goto` branches with a final `else`.
A branch may go back to an earlier step, for example to poll a status.

Expressions use [JMESPath](https://jmespath.org). In `args`, `"{{expr}}"` is replaced by the value.
The full grammar is in the `run_plan` tool description, which the model reads.

## Safety

- A plan may only call tools that are marked read-only (`readOnlyHint`) or match `allow_in_plans`.
  Other tools are rejected before the plan runs. Call write tools on their own server,
  so that the normal approval prompt of your client applies.
  Note: `readOnlyHint` is the server's own claim. Only connect servers you trust, and
  prefer exact tool names in `allow_in_plans` over wildcards.
- Hard limits stop runaway plans: maximum steps, maximum tool calls (each loop item counts),
  a timeout, and a maximum result size. A plan may lower these limits, never raise them.
  Sub-plan steps and calls count toward the same limits. The loop items of a whole run
  (all levels) are capped, and so are the calls in flight across the run.

To report a security problem, see [SECURITY.md](SECURITY.md).

## How it compares to code mode

Another way to cut tool-call turns is to let the model write code that calls the tools,
and run that code in a sandbox (for example Cloudflare's "Code Mode"). Code is more
flexible. A plan is less flexible, but it needs no sandbox, it can be checked before it
runs (allowed tools, limits, structure), and every run gives a short, readable trace.

## Benchmark your own servers

`bench/bench.py` runs the same task in headless Claude Code (`claude -p`) once per variant and
run, and saves every run as stream-json so you can trace each tool call. Copy
`bench/spec.example.json`, point each variant at an MCP config file (files named `*.local.json`
are ignored by git), then:

```bash
uv run python bench/bench.py bench/my-spec.local.json --runs 3
```

Each run is a real, paid model session.

## Tests

```bash
uv run pytest
```

## Limits of version 0.1

- Results are best when tools return structured output (`outputSchema`). For text results,
  the runner tries to parse JSON. Otherwise the step result is the text, and a plan cannot
  filter inside it. A learned schema cannot help with plain text. [docs/server-guide.md](docs/server-guide.md) lists what a server can add
  to work well in plans, with examples and a text to send to a server's maintainer.
- Remote servers that need OAuth are not supported yet. Stdio servers and plain HTTP URLs work.

## License

MIT

TDQS

A3.9/5.0

Scored across 3 tools

Disambiguation4/5

The three tools map to a clean discover/invoke/orchestrate triad: list_tools finds tools, call runs one, run_plan runs many. The only soft boundary is that call and run_plan overlap for trivial single-step jobs, but the descriptions make the intended division clear (call is for inspecting real output shapes before planning).

Naming Consistency4/5

All names are snake_case and short verb-oriented forms (list_tools, call, run_plan). 'call' is a bare verb where the others are verb_noun, a minor deviation, but the convention is still predictable and readable.

Tool Count4/5

Three tools is minimal but well-matched to a meta-orchestration server: discovery, single invocation, and multi-step execution are the natural primitives. Nothing feels redundant, though the surface is on the thin side of the 3-15 range.

Completeness4/5

Coverage is strong for the domain: discovery with schema learning, single calls, and plans with loops, pagination, branching, retries, and error policy. Minor gaps exist, such as no explicit server listing, plan dry-run/validation, or async/cancel support for long plans.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues