mcp-plan-runner
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.
Related MCP server: mcp-compressor
Quick start
You need uv. uvx downloads and runs the package from PyPI.
Write a config file, for example
~/.config/mcp-plan-runner/config.json, with your servers (see Configuration and config.example.json).Add the runner to an MCP client, for example Claude Code:
claude mcp add plan-runner -- uvx mcp-plan-runner /abs/path/to/config.jsonOther 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:
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 stdioConfiguration
{
"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 |
| A stdio server ( |
| Calls in flight to this server (default 4). Use |
| Stdio only: append the server's stderr to this file (mode 0600). A relative path starts from the folder the proxy runs in. |
| Tools (exact names or |
|
|
Tools
Tool | Purpose |
| 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 one tool and return its result as JSON. Use it to see an output shape. |
| Validate and run a plan. Returns |
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
callor 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_toolswith a query shows the learned schema asoutput_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
{"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 ofcall, 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. 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 matchallow_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:readOnlyHintis the server's own claim. Only connect servers you trust, and prefer exact tool names inallow_in_plansover 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.
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:
uv run python bench/bench.py bench/my-spec.local.json --runs 3Each run is a real, paid model session.
Tests
uv run pytestLimits 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 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
Available Tools
3 toolscallA
Call one tool ('server.tool') and return its result as JSON data.
Use it to see the real shape of a tool's output before you write a plan.
The same timeout and result size limit as run_plan apply.
Inputs: tool (required), args.
list_toolsA
Find tools on the connected servers.
No query: every tool name with a one-line description. When there are many tools,
only the names, grouped by server: then search with a query.
With a query (words): the tools that match all words in name or description, or else
the best partial matches, with full input and output schemas (at most 15).
'plan_ok' says whether the tool may run inside run_plan and call.
'output_schema_learned': the tool declares no output schema; this one was learned from
its earlier results. Any field may be missing; field names come from tool results.
Inputs: query, server. Returns: result
run_planA
Run a multi-step plan of tool calls in ONE call and get back only the final value. Use it when a job needs several calls, loops or conditions. Find tool names and their output shapes with list_tools first. Only read-only (or allow-listed) tools may run in a plan.
Plan = {"start": "", "steps": {"": , ...}, "input": , "limits": {"max_steps", "max_calls", "timeout_s"} (optional, can only lower)} Step ids: lowercase letters, digits, underscore. Each step result is stored under its id.
Step kinds (each step is exactly one): call {"call": "server.tool", "args": {...}} for_each {"for_each": "", "as": "item", "call": "server.tool", "args": {... "{{item.id}}" ...}, "parallel": 4, "max_items": 100} -> list of results, in the same order as the items Several steps per item: use "do": {"start": "", "steps": {...}} instead of call/args. The sub-plan sees outer results and the loop variable; its step ids are new and local; the item's result is its return (or last value). retry goes on its steps. Nest at most 2. Inside do, next/goto reach only its own steps; ids must not reuse an outer id or the loop variable. parallel and on_error apply per item; sub-steps count toward the limits. {"for_each": "s.ids", "as": "c", "do": {"start": "f", "steps": {"f": {"call": "mail.search", "args": {"q": "{{c}}"}, "next": "g"}, "g": {"call": "mail.get_thread", "args": {"id": "{{f[0].id}}"}}}}} paginate {"paginate": "server.tool", "args": {...}, "cursor_in": "", "cursor_out": "", "collect": "", "max_pages": 10} -> all collected items joined into one list return {"return": ""} ends the plan with this value Optional on call/for_each/paginate: "on_error": "stop" (default) | "skip" (skip: a failed call gives null, a failed for_each item gives {"error": ...}), "retry": 0-5 (default 0) tries a failed call again after 1 s, 2 s, 4 s ... (per item or page). Use retry for tools that fail for a short time; on_error applies when the retries are used up. Do not retry errors that will not change (bad arguments, not found), or tools that write.
Flow: "next": "" or "next": [{"if": "", "goto": "", "wait_s": 0}, ..., {"else": ""}] A branch may point back to an earlier step (a loop); global limits stop runaway plans. No next and no return: the plan ends with the last step's value.
Expressions are JMESPath over {"input": ..., "": result, "": item}.
length(s1.items) == 0 s2[?total > 100].name s1.items[0].id
Literals: numbers and booleans in backticks (0, true), strings in single quotes ('draft').
In args, "{{expr}}" is replaced by the value (a whole-string template keeps its type).
Example:
{"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'"}}}
Inputs: plan (required). Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 3 tools
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).
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.
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.
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
Related MCP Connectors
One MCP endpoint for Claude, GPT & Gemini: 100+ tools + no-code connectors + agent workers.
The OpenRouter for tools. One MCP connection gives any AI agent 254 hosted tools, pay per call.
Pay-per-use tool marketplace for AI agents. Search, price-check, and call APIs via MCP.
Free public MCP for AI agents — 193 tools, 44 workflows. No API key.
Related MCP Servers
- AlicenseAqualityBmaintenanceUnified MCP orchestration layer that consolidates multiple MCPs into a single interface with semantic tool discovery, code-mode execution, scheduling, and intelligent caching to reduce token usage by 97% and eliminate choice paralysis.2158 npm102Elastic 2.0
- AlicenseNot gradedqualityBmaintenanceA proxy server that wraps existing MCP servers to significantly reduce token consumption by compressing tool descriptions into a two-step interface. It enables users to integrate extensive toolsets without exceeding context limits or incurring high API costs.145Apache 2.0
- AlicenseAqualityDmaintenanceMCP proxy that compresses tool schemas on the fly. Up to 98% token reduction, 100% signal preserved verified after every compression. Zero LLM calls, fully deterministic.53MIT
- AlicenseAqualityBmaintenanceEnables agents to accomplish multi-step work by writing a single sandboxed JavaScript program that drives shell, filesystem, HTTP, and every tool of any configured MCP server, returning only a small summary instead of raw JSON. This collapses dozens of advertised tool schemas into one tool, cutting per-request context by roughly 26× while keeping disabled upstream servers reachable.134 npmMIT