mcp-plan-runner 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mcp_plan_runner-0.1.0/LICENSE +21 -0
- mcp_plan_runner-0.1.0/PKG-INFO +222 -0
- mcp_plan_runner-0.1.0/README.md +201 -0
- mcp_plan_runner-0.1.0/pyproject.toml +76 -0
- mcp_plan_runner-0.1.0/pyproject.toml.orig +62 -0
- mcp_plan_runner-0.1.0/src/mcp_plan_runner/__init__.py +1 -0
- mcp_plan_runner-0.1.0/src/mcp_plan_runner/hub.py +165 -0
- mcp_plan_runner-0.1.0/src/mcp_plan_runner/plan.py +499 -0
- mcp_plan_runner-0.1.0/src/mcp_plan_runner/py.typed +0 -0
- mcp_plan_runner-0.1.0/src/mcp_plan_runner/schemas.py +303 -0
- mcp_plan_runner-0.1.0/src/mcp_plan_runner/server.py +192 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Costas Christodoulou
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcp-plan-runner
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: One MCP tool that runs a whole plan of tool calls (calls, loops, conditions) across any MCP servers.
|
|
5
|
+
Keywords: mcp,model-context-protocol,llm,agents,tool-calling,proxy
|
|
6
|
+
Author: Costas
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
15
|
+
Requires-Dist: jmespath>=1.1.0
|
|
16
|
+
Requires-Dist: mcp>=2.3.0
|
|
17
|
+
Requires-Python: >=3.12
|
|
18
|
+
Project-URL: Homepage, https://github.com/costas1379/mcp-plan-runner
|
|
19
|
+
Project-URL: Changelog, https://github.com/costas1379/mcp-plan-runner/blob/main/CHANGELOG.md
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# mcp-plan-runner
|
|
23
|
+
|
|
24
|
+
An MCP proxy that lets a model run a whole **plan** of tool calls in one call.
|
|
25
|
+
|
|
26
|
+
A normal agent calls one tool, reads the result, decides, and calls the next tool.
|
|
27
|
+
Each step costs a model turn, and every intermediate result goes into the context.
|
|
28
|
+
With `run_plan`, the model writes the full plan once: calls, loops and conditions.
|
|
29
|
+
The runner executes it next to the tools and returns only the final value.
|
|
30
|
+
|
|
31
|
+
It works with any MCP server. The servers need no changes.
|
|
32
|
+
|
|
33
|
+
## Results
|
|
34
|
+
|
|
35
|
+
On a mail job with about 30 tool calls (read 27 threads in two mailboxes, then build one
|
|
36
|
+
table), Claude Code with the plan runner needed **3 turns instead of 31** and cost
|
|
37
|
+
**84% less** (median 0.105 USD instead of 0.649), with the same answer totals.
|
|
38
|
+
A rerun on the final code cost about the same (median 0.111 USD), but took 5 turns: Gmail's
|
|
39
|
+
per-minute quota rejected some reads, and the model read them again in a second plan.
|
|
40
|
+
On small jobs the saving is smaller. Details and all rounds: [docs/benchmarks.md](docs/benchmarks.md).
|
|
41
|
+
|
|
42
|
+
## Quick start
|
|
43
|
+
|
|
44
|
+
You need [uv](https://docs.astral.sh/uv/). `uvx` downloads and runs the package from PyPI.
|
|
45
|
+
|
|
46
|
+
1. Write a config file, for example `~/.config/mcp-plan-runner/config.json`, with your servers
|
|
47
|
+
(see [Configuration](#configuration) and [config.example.json](config.example.json)).
|
|
48
|
+
2. Add the runner to an MCP client, for example Claude Code:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
claude mcp add plan-runner -- uvx mcp-plan-runner /abs/path/to/config.json
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Other clients: the command is `uvx` and the arguments are `mcp-plan-runner /abs/path/to/config.json`.
|
|
55
|
+
The runner talks MCP over stdio. `pipx run mcp-plan-runner config.json` works too.
|
|
56
|
+
|
|
57
|
+
From source:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
git clone https://github.com/costas1379/mcp-plan-runner
|
|
61
|
+
cd mcp-plan-runner
|
|
62
|
+
uv sync
|
|
63
|
+
cp config.example.json config.json # edit: your servers and allow list
|
|
64
|
+
uv run mcp-plan-runner config.json # runs the proxy on stdio
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Configuration
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"servers": {
|
|
72
|
+
"mail": {"command": "uv", "args": ["run", "mail-mcp"], "env": {"TOKEN_FILE": "/path"},
|
|
73
|
+
"cwd": "/path", "max_parallel": 1, "log": "/path/logs/mail.log"},
|
|
74
|
+
"docs": {"url": "https://example.com/mcp"}
|
|
75
|
+
},
|
|
76
|
+
"allow_in_plans": ["mail.search", "mail.get_thread"],
|
|
77
|
+
"schema_cache": true
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
| Key | Meaning |
|
|
82
|
+
| --- | --- |
|
|
83
|
+
| `servers.<name>` | A stdio server (`command`, `args`, `env`, `cwd`) or an HTTP server (`url`). The name may not contain `.`. |
|
|
84
|
+
| `max_parallel` | Calls in flight to this server (default 4). Use `1` for servers that cannot handle parallel calls. |
|
|
85
|
+
| `log` | Stdio only: append the server's stderr to this file (mode 0600). A relative path starts from the folder the proxy runs in. |
|
|
86
|
+
| `allow_in_plans` | Tools (exact names or `fnmatch` patterns) that may run in a plan although they are not marked read-only. |
|
|
87
|
+
| `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. |
|
|
88
|
+
|
|
89
|
+
## Tools
|
|
90
|
+
|
|
91
|
+
| Tool | Purpose |
|
|
92
|
+
| --- | --- |
|
|
93
|
+
| `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. |
|
|
94
|
+
| `call(tool, args)` | Call one tool and return its result as JSON. Use it to see an output shape. |
|
|
95
|
+
| `run_plan(plan)` | Validate and run a plan. Returns `ok`, `result`, `calls` and a short `trace`. |
|
|
96
|
+
|
|
97
|
+
Tool names are `server.tool`, for example `mail.search`.
|
|
98
|
+
|
|
99
|
+
The client sees only these three tools, however many tools the servers behind the proxy
|
|
100
|
+
have. The model finds the tools it needs with `list_tools` and a query, so the schemas of
|
|
101
|
+
hundreds of tools never go into its context. Above 60 tools, a list without a query
|
|
102
|
+
gives only the names.
|
|
103
|
+
|
|
104
|
+
## Learned output schemas
|
|
105
|
+
|
|
106
|
+
A model writes a plan in one go only when it knows the shape of each tool's result.
|
|
107
|
+
Many MCP servers do not declare an `outputSchema`, so the model must first make a probe
|
|
108
|
+
`call` to see the shape. To avoid that probe on later runs, the runner learns the shape:
|
|
109
|
+
|
|
110
|
+
- Each time a tool without an output schema returns a result (from `call` or inside a plan),
|
|
111
|
+
the runner reads the JSON types and keys of the result and adds them to what it saw before.
|
|
112
|
+
- A key becomes a field name only after it was in 3 different results. A result that is the
|
|
113
|
+
same as a recent one does not count again. Real field names (`id`, `subject`,
|
|
114
|
+
`next_page_token`) repeat in every result. Most data used as keys (names, ids) does not,
|
|
115
|
+
so it is not stored.
|
|
116
|
+
- `list_tools` with a query shows the learned schema as `output_schema`, with
|
|
117
|
+
`"output_schema_learned": true`. Any field in it may be missing in a result. A schema that
|
|
118
|
+
the server declares always wins.
|
|
119
|
+
- The schemas are kept in `~/.cache/mcp-plan-runner/schemas.json` (or under `$XDG_CACHE_HOME`),
|
|
120
|
+
file mode 0600 in a 0700 folder, so the next session starts with them. When a tool's input
|
|
121
|
+
schema changes, its learned schema is dropped. To start again, delete the file.
|
|
122
|
+
|
|
123
|
+
What the cache file holds:
|
|
124
|
+
|
|
125
|
+
- JSON types and field names that were in at least 3 results. Never values.
|
|
126
|
+
- For a key seen fewer times: a hash of it and a count. The hash hides the key from someone
|
|
127
|
+
who reads the file, but not from someone who guesses it.
|
|
128
|
+
- An object is stored as a map, with no key names at all, when a key does not look like a
|
|
129
|
+
field name (emails, dates, ids with two or more digits, keys longer than 32 characters or
|
|
130
|
+
with more than three `_` or `-`), when three or more keys hold objects of the same shape,
|
|
131
|
+
or when more than 50 different keys never repeat.
|
|
132
|
+
- Stable names that a tool uses as keys in every result, for example
|
|
133
|
+
`{"Alice": 3, "Bob": 5}` for the same users each time, look like field names. They are
|
|
134
|
+
stored after 3 different results.
|
|
135
|
+
|
|
136
|
+
Field names come from tool results, which can contain untrusted text (a web page, an email).
|
|
137
|
+
A source that puts the same short key in 3 different results can get it into a learned schema,
|
|
138
|
+
and the model reads it there. If your servers return text from untrusted sources and that
|
|
139
|
+
matters to you, turn learning off.
|
|
140
|
+
|
|
141
|
+
To turn learning off, set `"schema_cache": false` in the config.
|
|
142
|
+
|
|
143
|
+
## A plan
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{"start": "find", "steps": {
|
|
147
|
+
"find": {"call": "mail.search", "args": {"q": "invoice"},
|
|
148
|
+
"next": [{"if": "length(find.messages) == `0`", "goto": "none"}, {"else": "read"}]},
|
|
149
|
+
"read": {"for_each": "find.messages", "as": "m", "call": "mail.get_thread",
|
|
150
|
+
"args": {"id": "{{m.thread_id}}"}, "parallel": 4, "retry": 2, "next": "out"},
|
|
151
|
+
"out": {"return": "read[].{subject: subject, from: from}"},
|
|
152
|
+
"none": {"return": "'no invoices'"}}}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Step kinds:
|
|
156
|
+
|
|
157
|
+
- `call`: one tool call.
|
|
158
|
+
- `for_each`: one tool call for each item of a list, optionally in parallel. Gives a list.
|
|
159
|
+
With `"do": {"start", "steps"}` instead of `call`, it runs a small sub-plan for each item (at most 2 levels deep).
|
|
160
|
+
- `paginate`: calls a tool again with the cursor from the last page until there is no cursor. Gives one list.
|
|
161
|
+
- `return`: ends the plan with a value.
|
|
162
|
+
|
|
163
|
+
Options: `retry` (0 to 5) tries a failed tool call again after 1 s, 2 s, 4 s ... (each try counts as a call);
|
|
164
|
+
`on_error` is `stop` (default) or `skip`.
|
|
165
|
+
|
|
166
|
+
Flow: `next` is a step id or a list of `if`/`goto` branches with a final `else`.
|
|
167
|
+
A branch may go back to an earlier step, for example to poll a status.
|
|
168
|
+
|
|
169
|
+
Expressions use [JMESPath](https://jmespath.org). In `args`, `"{{expr}}"` is replaced by the value.
|
|
170
|
+
The full grammar is in the `run_plan` tool description, which the model reads.
|
|
171
|
+
|
|
172
|
+
## Safety
|
|
173
|
+
|
|
174
|
+
- A plan may only call tools that are marked read-only (`readOnlyHint`) or match `allow_in_plans`.
|
|
175
|
+
Other tools are rejected before the plan runs. Call write tools on their own server,
|
|
176
|
+
so that the normal approval prompt of your client applies.
|
|
177
|
+
Note: `readOnlyHint` is the server's own claim. Only connect servers you trust, and
|
|
178
|
+
prefer exact tool names in `allow_in_plans` over wildcards.
|
|
179
|
+
- Hard limits stop runaway plans: maximum steps, maximum tool calls (each loop item counts),
|
|
180
|
+
a timeout, and a maximum result size. A plan may lower these limits, never raise them.
|
|
181
|
+
Sub-plan steps and calls count toward the same limits. The loop items of a whole run
|
|
182
|
+
(all levels) are capped, and so are the calls in flight across the run.
|
|
183
|
+
|
|
184
|
+
To report a security problem, see [SECURITY.md](SECURITY.md).
|
|
185
|
+
|
|
186
|
+
## How it compares to code mode
|
|
187
|
+
|
|
188
|
+
Another way to cut tool-call turns is to let the model write code that calls the tools,
|
|
189
|
+
and run that code in a sandbox (for example Cloudflare's "Code Mode"). Code is more
|
|
190
|
+
flexible. A plan is less flexible, but it needs no sandbox, it can be checked before it
|
|
191
|
+
runs (allowed tools, limits, structure), and every run gives a short, readable trace.
|
|
192
|
+
|
|
193
|
+
## Benchmark your own servers
|
|
194
|
+
|
|
195
|
+
`bench/bench.py` runs the same task in headless Claude Code (`claude -p`) once per variant and
|
|
196
|
+
run, and saves every run as stream-json so you can trace each tool call. Copy
|
|
197
|
+
`bench/spec.example.json`, point each variant at an MCP config file (files named `*.local.json`
|
|
198
|
+
are ignored by git), then:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
uv run python bench/bench.py bench/my-spec.local.json --runs 3
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Each run is a real, paid model session.
|
|
205
|
+
|
|
206
|
+
## Tests
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
uv run pytest
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Limits of version 0.1
|
|
213
|
+
|
|
214
|
+
- Results are best when tools return structured output (`outputSchema`). For text results,
|
|
215
|
+
the runner tries to parse JSON. Otherwise the step result is the text, and a plan cannot
|
|
216
|
+
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
|
|
217
|
+
to work well in plans, with examples and a text to send to a server's maintainer.
|
|
218
|
+
- Remote servers that need OAuth are not supported yet. Stdio servers and plain HTTP URLs work.
|
|
219
|
+
|
|
220
|
+
## License
|
|
221
|
+
|
|
222
|
+
MIT
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# mcp-plan-runner
|
|
2
|
+
|
|
3
|
+
An MCP proxy that lets a model run a whole **plan** of tool calls in one call.
|
|
4
|
+
|
|
5
|
+
A normal agent calls one tool, reads the result, decides, and calls the next tool.
|
|
6
|
+
Each step costs a model turn, and every intermediate result goes into the context.
|
|
7
|
+
With `run_plan`, the model writes the full plan once: calls, loops and conditions.
|
|
8
|
+
The runner executes it next to the tools and returns only the final value.
|
|
9
|
+
|
|
10
|
+
It works with any MCP server. The servers need no changes.
|
|
11
|
+
|
|
12
|
+
## Results
|
|
13
|
+
|
|
14
|
+
On a mail job with about 30 tool calls (read 27 threads in two mailboxes, then build one
|
|
15
|
+
table), Claude Code with the plan runner needed **3 turns instead of 31** and cost
|
|
16
|
+
**84% less** (median 0.105 USD instead of 0.649), with the same answer totals.
|
|
17
|
+
A rerun on the final code cost about the same (median 0.111 USD), but took 5 turns: Gmail's
|
|
18
|
+
per-minute quota rejected some reads, and the model read them again in a second plan.
|
|
19
|
+
On small jobs the saving is smaller. Details and all rounds: [docs/benchmarks.md](docs/benchmarks.md).
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
You need [uv](https://docs.astral.sh/uv/). `uvx` downloads and runs the package from PyPI.
|
|
24
|
+
|
|
25
|
+
1. Write a config file, for example `~/.config/mcp-plan-runner/config.json`, with your servers
|
|
26
|
+
(see [Configuration](#configuration) and [config.example.json](config.example.json)).
|
|
27
|
+
2. Add the runner to an MCP client, for example Claude Code:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
claude mcp add plan-runner -- uvx mcp-plan-runner /abs/path/to/config.json
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Other clients: the command is `uvx` and the arguments are `mcp-plan-runner /abs/path/to/config.json`.
|
|
34
|
+
The runner talks MCP over stdio. `pipx run mcp-plan-runner config.json` works too.
|
|
35
|
+
|
|
36
|
+
From source:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
git clone https://github.com/costas1379/mcp-plan-runner
|
|
40
|
+
cd mcp-plan-runner
|
|
41
|
+
uv sync
|
|
42
|
+
cp config.example.json config.json # edit: your servers and allow list
|
|
43
|
+
uv run mcp-plan-runner config.json # runs the proxy on stdio
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"servers": {
|
|
51
|
+
"mail": {"command": "uv", "args": ["run", "mail-mcp"], "env": {"TOKEN_FILE": "/path"},
|
|
52
|
+
"cwd": "/path", "max_parallel": 1, "log": "/path/logs/mail.log"},
|
|
53
|
+
"docs": {"url": "https://example.com/mcp"}
|
|
54
|
+
},
|
|
55
|
+
"allow_in_plans": ["mail.search", "mail.get_thread"],
|
|
56
|
+
"schema_cache": true
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
| Key | Meaning |
|
|
61
|
+
| --- | --- |
|
|
62
|
+
| `servers.<name>` | A stdio server (`command`, `args`, `env`, `cwd`) or an HTTP server (`url`). The name may not contain `.`. |
|
|
63
|
+
| `max_parallel` | Calls in flight to this server (default 4). Use `1` for servers that cannot handle parallel calls. |
|
|
64
|
+
| `log` | Stdio only: append the server's stderr to this file (mode 0600). A relative path starts from the folder the proxy runs in. |
|
|
65
|
+
| `allow_in_plans` | Tools (exact names or `fnmatch` patterns) that may run in a plan although they are not marked read-only. |
|
|
66
|
+
| `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. |
|
|
67
|
+
|
|
68
|
+
## Tools
|
|
69
|
+
|
|
70
|
+
| Tool | Purpose |
|
|
71
|
+
| --- | --- |
|
|
72
|
+
| `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. |
|
|
73
|
+
| `call(tool, args)` | Call one tool and return its result as JSON. Use it to see an output shape. |
|
|
74
|
+
| `run_plan(plan)` | Validate and run a plan. Returns `ok`, `result`, `calls` and a short `trace`. |
|
|
75
|
+
|
|
76
|
+
Tool names are `server.tool`, for example `mail.search`.
|
|
77
|
+
|
|
78
|
+
The client sees only these three tools, however many tools the servers behind the proxy
|
|
79
|
+
have. The model finds the tools it needs with `list_tools` and a query, so the schemas of
|
|
80
|
+
hundreds of tools never go into its context. Above 60 tools, a list without a query
|
|
81
|
+
gives only the names.
|
|
82
|
+
|
|
83
|
+
## Learned output schemas
|
|
84
|
+
|
|
85
|
+
A model writes a plan in one go only when it knows the shape of each tool's result.
|
|
86
|
+
Many MCP servers do not declare an `outputSchema`, so the model must first make a probe
|
|
87
|
+
`call` to see the shape. To avoid that probe on later runs, the runner learns the shape:
|
|
88
|
+
|
|
89
|
+
- Each time a tool without an output schema returns a result (from `call` or inside a plan),
|
|
90
|
+
the runner reads the JSON types and keys of the result and adds them to what it saw before.
|
|
91
|
+
- A key becomes a field name only after it was in 3 different results. A result that is the
|
|
92
|
+
same as a recent one does not count again. Real field names (`id`, `subject`,
|
|
93
|
+
`next_page_token`) repeat in every result. Most data used as keys (names, ids) does not,
|
|
94
|
+
so it is not stored.
|
|
95
|
+
- `list_tools` with a query shows the learned schema as `output_schema`, with
|
|
96
|
+
`"output_schema_learned": true`. Any field in it may be missing in a result. A schema that
|
|
97
|
+
the server declares always wins.
|
|
98
|
+
- The schemas are kept in `~/.cache/mcp-plan-runner/schemas.json` (or under `$XDG_CACHE_HOME`),
|
|
99
|
+
file mode 0600 in a 0700 folder, so the next session starts with them. When a tool's input
|
|
100
|
+
schema changes, its learned schema is dropped. To start again, delete the file.
|
|
101
|
+
|
|
102
|
+
What the cache file holds:
|
|
103
|
+
|
|
104
|
+
- JSON types and field names that were in at least 3 results. Never values.
|
|
105
|
+
- For a key seen fewer times: a hash of it and a count. The hash hides the key from someone
|
|
106
|
+
who reads the file, but not from someone who guesses it.
|
|
107
|
+
- An object is stored as a map, with no key names at all, when a key does not look like a
|
|
108
|
+
field name (emails, dates, ids with two or more digits, keys longer than 32 characters or
|
|
109
|
+
with more than three `_` or `-`), when three or more keys hold objects of the same shape,
|
|
110
|
+
or when more than 50 different keys never repeat.
|
|
111
|
+
- Stable names that a tool uses as keys in every result, for example
|
|
112
|
+
`{"Alice": 3, "Bob": 5}` for the same users each time, look like field names. They are
|
|
113
|
+
stored after 3 different results.
|
|
114
|
+
|
|
115
|
+
Field names come from tool results, which can contain untrusted text (a web page, an email).
|
|
116
|
+
A source that puts the same short key in 3 different results can get it into a learned schema,
|
|
117
|
+
and the model reads it there. If your servers return text from untrusted sources and that
|
|
118
|
+
matters to you, turn learning off.
|
|
119
|
+
|
|
120
|
+
To turn learning off, set `"schema_cache": false` in the config.
|
|
121
|
+
|
|
122
|
+
## A plan
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
{"start": "find", "steps": {
|
|
126
|
+
"find": {"call": "mail.search", "args": {"q": "invoice"},
|
|
127
|
+
"next": [{"if": "length(find.messages) == `0`", "goto": "none"}, {"else": "read"}]},
|
|
128
|
+
"read": {"for_each": "find.messages", "as": "m", "call": "mail.get_thread",
|
|
129
|
+
"args": {"id": "{{m.thread_id}}"}, "parallel": 4, "retry": 2, "next": "out"},
|
|
130
|
+
"out": {"return": "read[].{subject: subject, from: from}"},
|
|
131
|
+
"none": {"return": "'no invoices'"}}}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Step kinds:
|
|
135
|
+
|
|
136
|
+
- `call`: one tool call.
|
|
137
|
+
- `for_each`: one tool call for each item of a list, optionally in parallel. Gives a list.
|
|
138
|
+
With `"do": {"start", "steps"}` instead of `call`, it runs a small sub-plan for each item (at most 2 levels deep).
|
|
139
|
+
- `paginate`: calls a tool again with the cursor from the last page until there is no cursor. Gives one list.
|
|
140
|
+
- `return`: ends the plan with a value.
|
|
141
|
+
|
|
142
|
+
Options: `retry` (0 to 5) tries a failed tool call again after 1 s, 2 s, 4 s ... (each try counts as a call);
|
|
143
|
+
`on_error` is `stop` (default) or `skip`.
|
|
144
|
+
|
|
145
|
+
Flow: `next` is a step id or a list of `if`/`goto` branches with a final `else`.
|
|
146
|
+
A branch may go back to an earlier step, for example to poll a status.
|
|
147
|
+
|
|
148
|
+
Expressions use [JMESPath](https://jmespath.org). In `args`, `"{{expr}}"` is replaced by the value.
|
|
149
|
+
The full grammar is in the `run_plan` tool description, which the model reads.
|
|
150
|
+
|
|
151
|
+
## Safety
|
|
152
|
+
|
|
153
|
+
- A plan may only call tools that are marked read-only (`readOnlyHint`) or match `allow_in_plans`.
|
|
154
|
+
Other tools are rejected before the plan runs. Call write tools on their own server,
|
|
155
|
+
so that the normal approval prompt of your client applies.
|
|
156
|
+
Note: `readOnlyHint` is the server's own claim. Only connect servers you trust, and
|
|
157
|
+
prefer exact tool names in `allow_in_plans` over wildcards.
|
|
158
|
+
- Hard limits stop runaway plans: maximum steps, maximum tool calls (each loop item counts),
|
|
159
|
+
a timeout, and a maximum result size. A plan may lower these limits, never raise them.
|
|
160
|
+
Sub-plan steps and calls count toward the same limits. The loop items of a whole run
|
|
161
|
+
(all levels) are capped, and so are the calls in flight across the run.
|
|
162
|
+
|
|
163
|
+
To report a security problem, see [SECURITY.md](SECURITY.md).
|
|
164
|
+
|
|
165
|
+
## How it compares to code mode
|
|
166
|
+
|
|
167
|
+
Another way to cut tool-call turns is to let the model write code that calls the tools,
|
|
168
|
+
and run that code in a sandbox (for example Cloudflare's "Code Mode"). Code is more
|
|
169
|
+
flexible. A plan is less flexible, but it needs no sandbox, it can be checked before it
|
|
170
|
+
runs (allowed tools, limits, structure), and every run gives a short, readable trace.
|
|
171
|
+
|
|
172
|
+
## Benchmark your own servers
|
|
173
|
+
|
|
174
|
+
`bench/bench.py` runs the same task in headless Claude Code (`claude -p`) once per variant and
|
|
175
|
+
run, and saves every run as stream-json so you can trace each tool call. Copy
|
|
176
|
+
`bench/spec.example.json`, point each variant at an MCP config file (files named `*.local.json`
|
|
177
|
+
are ignored by git), then:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
uv run python bench/bench.py bench/my-spec.local.json --runs 3
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Each run is a real, paid model session.
|
|
184
|
+
|
|
185
|
+
## Tests
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
uv run pytest
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Limits of version 0.1
|
|
192
|
+
|
|
193
|
+
- Results are best when tools return structured output (`outputSchema`). For text results,
|
|
194
|
+
the runner tries to parse JSON. Otherwise the step result is the text, and a plan cannot
|
|
195
|
+
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
|
|
196
|
+
to work well in plans, with examples and a text to send to a server's maintainer.
|
|
197
|
+
- Remote servers that need OAuth are not supported yet. Stdio servers and plain HTTP URLs work.
|
|
198
|
+
|
|
199
|
+
## License
|
|
200
|
+
|
|
201
|
+
MIT
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mcp-plan-runner"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "One MCP tool that runs a whole plan of tool calls (calls, loops, conditions) across any MCP servers."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.12"
|
|
9
|
+
keywords = [
|
|
10
|
+
"mcp",
|
|
11
|
+
"model-context-protocol",
|
|
12
|
+
"llm",
|
|
13
|
+
"agents",
|
|
14
|
+
"tool-calling",
|
|
15
|
+
"proxy",
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Software Development :: Libraries",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"jmespath>=1.1.0",
|
|
27
|
+
"mcp>=2.3.0",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[[project.authors]]
|
|
31
|
+
name = "Costas"
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/costas1379/mcp-plan-runner"
|
|
35
|
+
Changelog = "https://github.com/costas1379/mcp-plan-runner/blob/main/CHANGELOG.md"
|
|
36
|
+
|
|
37
|
+
[project.scripts]
|
|
38
|
+
mcp-plan-runner = "mcp_plan_runner.server:main"
|
|
39
|
+
|
|
40
|
+
[build-system]
|
|
41
|
+
requires = ["uv_build>=0.13.6,<0.14.0"]
|
|
42
|
+
build-backend = "uv_build"
|
|
43
|
+
|
|
44
|
+
[dependency-groups]
|
|
45
|
+
dev = [
|
|
46
|
+
"hypothesis>=6.170.22",
|
|
47
|
+
"mypy>=2.4.1",
|
|
48
|
+
"pytest>=9.2.0",
|
|
49
|
+
"pytest-asyncio>=1.5.0",
|
|
50
|
+
"ruff>=0.17.6",
|
|
51
|
+
"types-jmespath>=1.1.0.20260724",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
[tool.pytest.ini_options]
|
|
55
|
+
asyncio_mode = "auto"
|
|
56
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
57
|
+
|
|
58
|
+
[tool.ruff]
|
|
59
|
+
line-length = 120
|
|
60
|
+
target-version = "py312"
|
|
61
|
+
|
|
62
|
+
[tool.ruff.lint]
|
|
63
|
+
select = [
|
|
64
|
+
"E",
|
|
65
|
+
"F",
|
|
66
|
+
"W",
|
|
67
|
+
"I",
|
|
68
|
+
"B",
|
|
69
|
+
"UP",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
[tool.mypy]
|
|
73
|
+
python_version = "3.12"
|
|
74
|
+
files = ["src"]
|
|
75
|
+
warn_unused_ignores = true
|
|
76
|
+
check_untyped_defs = true
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mcp-plan-runner"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "One MCP tool that runs a whole plan of tool calls (calls, loops, conditions) across any MCP servers."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Costas" }
|
|
10
|
+
]
|
|
11
|
+
requires-python = ">=3.12"
|
|
12
|
+
keywords = ["mcp", "model-context-protocol", "llm", "agents", "tool-calling", "proxy"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Topic :: Software Development :: Libraries",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"jmespath>=1.1.0",
|
|
23
|
+
"mcp>=2.3.0",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/costas1379/mcp-plan-runner"
|
|
28
|
+
Changelog = "https://github.com/costas1379/mcp-plan-runner/blob/main/CHANGELOG.md"
|
|
29
|
+
|
|
30
|
+
[build-system]
|
|
31
|
+
requires = ["uv_build>=0.13.6,<0.14.0"]
|
|
32
|
+
build-backend = "uv_build"
|
|
33
|
+
|
|
34
|
+
[dependency-groups]
|
|
35
|
+
dev = [
|
|
36
|
+
"hypothesis>=6.170.22",
|
|
37
|
+
"mypy>=2.4.1",
|
|
38
|
+
"pytest>=9.2.0",
|
|
39
|
+
"pytest-asyncio>=1.5.0",
|
|
40
|
+
"ruff>=0.17.6",
|
|
41
|
+
"types-jmespath>=1.1.0.20260724",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[project.scripts]
|
|
45
|
+
mcp-plan-runner = "mcp_plan_runner.server:main"
|
|
46
|
+
|
|
47
|
+
[tool.pytest.ini_options]
|
|
48
|
+
asyncio_mode = "auto"
|
|
49
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
50
|
+
|
|
51
|
+
[tool.ruff]
|
|
52
|
+
line-length = 120
|
|
53
|
+
target-version = "py312"
|
|
54
|
+
|
|
55
|
+
[tool.ruff.lint]
|
|
56
|
+
select = ["E", "F", "W", "I", "B", "UP"]
|
|
57
|
+
|
|
58
|
+
[tool.mypy]
|
|
59
|
+
python_version = "3.12"
|
|
60
|
+
files = ["src"]
|
|
61
|
+
warn_unused_ignores = true
|
|
62
|
+
check_untyped_defs = true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Run a whole plan of MCP tool calls in one call."""
|