toolscript-mcp
by yeeyon
README.md
# toolscript-mcp
A standalone MCP server for code mode. The model writes one JavaScript program that calls the tools of your other MCP
servers in a sandbox. The program filters and joins the data there. Only the result goes back into the context.
The goal is a server that works with any MCP client, for example Claude Code, Claude Desktop, Cursor and Codex.
**New in 1.1.0: MCP Skills, SDK v2, the 2026-07-28 protocol.** The server runs on SDK v2. By default, a client of the
2026-07-28 protocol gets a session of that protocol and finds the hint notes of toolscript-mcp as [Skills](docs/skills.md). Every other
client and server gets the protocol of 1.0.5. [Protocol](docs/protocol.md) starts with the way back: `TOOLSCRIPT_PROTOCOL=legacy`. Whether Skills save tokens is not measured here. The
measurement is [issue 229](https://github.com/yeeyon/toolscript-mcp/issues/229).
> **Install from npm.** Set it up [from npm](docs/install.md#from-npm) with `npx -y toolscript-mcp init`. Read
> [Limits](docs/sandbox.md#limits) before you use it.
## Features
- **Two tools.** `search_tools` finds downstream tools and shows their argument types. `run_code` runs an async JavaScript program. A 2026-07-28 connection with Skills on lists a third, `add_hint`, that proposes a hint for you to [approve](docs/skills.md#hint-proposals).
- **Servers.** Local stdio and remote HTTP servers, with OAuth login or AWS SigV4 signing.
- **Policy.** Ordered `allow`, `deny` and `ask` rules check each nested call.
- **Results.** Compact output, `await recall(n)` for kept results and `await saveFile(name, data)` for exports.
- **Local development.** The built-in [Workspace](docs/workspace.md#workspace) lists, searches and reads the files of one folder. With a write grant, it edits them. It is off by default.
- **Clients.** Claude Code, Claude Desktop, Cursor and Codex. See [Client setup](docs/install.md#client-setup). A manual smoke test passed in Codex CLI 0.171.0 with `codex exec`. See the [result](bench/CODEX.md#smoke-test-result).
JavaScript variables do not persist between runs. A program cannot read MCP resources, and toolscript-mcp has no tool that writes a hint or a saved
function. On a 2026-07-28 connection, hint files and saved functions are served to the client as [Skills](docs/skills.md).
See [Roadmap](#roadmap) for the remaining work.
## Why
When a model calls MCP tools one by one, every full result goes into its context. Large results fill the context with
raw JSON, and each step costs a round trip. With code mode, the loops, filters and joins run in a program. The model
sees only the answer.
## How it works
1. Your MCP client connects to toolscript-mcp. toolscript-mcp connects to your other MCP servers.
2. The model finds tools with `search_tools`. A keyword search shows its best matches in full. Each full match has a
TypeScript declaration of its `call()`: the nested types and the note of each argument. If 3 or fewer tools match,
each one shows in full. If more match, match 1 always shows in full. Matches 2 and 3 show in full while all full
matches total 4,000 characters or less. The other matches show as one summary each. The same tool on a second server
shows as one line that names the full match above. That line takes no full place.
3. The model sends one program to `run_code`.
4. The program runs in a separate Node process. Each nested tool call goes through your allow, deny and ask rules.
5. The return value of the program goes back to the model. If the formatted value is longer than 20,000 characters,
the model gets its shape and the first 3,000 characters of compact JSON.
Your MCP client sees only `search_tools` and `run_code`. It does not see the tools of your other servers.
An example program:
```js
const issues = await call("mcp__jira__search_issues", {
jql: "assignee = currentUser() AND statusCategory != Done",
})
const cutoff = Date.now() - 14 * 24 * 3600 * 1000
return issues.issues
.filter(i => Date.parse(i.fields.updated) < cutoff)
.map(i => ({ key: i.key, title: i.fields.summary }))
```
The model sees a short list of keys and titles, not every full issue.
## Numbers
A bench of 6 tasks in headless Claude Code 2.1.332 with Haiku 5.5, 5 runs per task, compares direct tool calls with toolscript-mcp.
Read [Measured](docs/benchmarks.md#measured) for the method, and the comparison with Claude Code Code Mode.
| | Direct tool calls | toolscript-mcp |
| --- | --- | --- |
| Correct answers | 30/30 | 30/30 |
| Mean cost per task | $0.0058 | $0.0024 |
| Tool result characters in the context, mean | 39,213 | 3,022 |
On the 2 tasks with small results, toolscript-mcp cost more, because it adds a search step.
The [paid Codex benchmark](bench/RESULTS-codex.md) covers six tasks with `gpt-6-luna` on Codex CLI 0.172.0.
It records 18 runs each for direct MCP calls, native Code Mode, and toolscript-mcp.
## Quick start
You need Node 22.13 or later and npm.
### Let Claude Code set it up
Paste this prompt into Claude Code. The agent runs [onboard](docs/cli.md#onboard) and asks you before each change.
```text
Set up toolscript-mcp for me in Claude Code.
1. Run `npx -y toolscript-mcp@latest --version`. If it prints a version below 1.1.0, stop and tell me.
2. Run `npx -y toolscript-mcp@latest onboard`. It prints one next step. Do that step, then run onboard again.
3. Do one printed step at a time. Ask me before each step that writes a file, installs a package or changes Claude Code.
4. Run each command that onboard prints exactly as printed.
5. Never read or print the toolscript-mcp config file.
6. When onboard asks for a restart of Claude Code, stop and tell me.
```
After the restart, paste this line into the new session:
```text
Continue the toolscript-mcp setup: run `npx -y toolscript-mcp@latest onboard`, run the task that it prints with its marker line as the first line of the run_code program, then run `npx -y toolscript-mcp@latest onboard verify` and show me its last line.
```
The setup ends with `ready` only after the restarted server ran a task. See [Set up with one prompt](docs/install.md#set-up-with-one-prompt).
### Install with the plugin
```text
/plugin marketplace add yeeyon/toolscript-mcp
/plugin install toolscript@toolscript-mcp
```
Then run `/toolscript:setup`. See [With the Claude Code plugin](docs/install.md#with-the-claude-code-plugin).
### Install with npm
```sh
npx -y toolscript-mcp init
```
`init` imports user-scope servers from Claude Code, Claude Desktop, Cursor and Codex. It writes a config and prints the client changes. See [From npm](docs/install.md#from-npm).
### Try the demo server
The demo server has sample data and needs no account.
```sh
npm install --prefix toolscript-demo toolscript-mcp@latest
```
The demo file is `toolscript-demo/node_modules/toolscript-mcp/demo/server.mjs`. Add it to your config as [Demo server](docs/install.md#demo-server) shows.
## Client setup in brief
Replace the example config path with your absolute config path. Use the server name `toolscript`.
Claude Code on Linux and macOS:
```sh
claude mcp add --scope user toolscript '--' npx -y toolscript-mcp --config "/absolute/path/to/config.json"
```
Claude Desktop, Cursor and Codex need a different entry. Read [Client setup](docs/install.md#client-setup) for each client.
## Documentation
| Page | Sections |
| --- | --- |
| [Install](docs/install.md) | [From npm](docs/install.md#from-npm), [Move an existing clone setup to npm](docs/install.md#move-an-existing-clone-setup-to-npm), [With the Claude Code plugin](docs/install.md#with-the-claude-code-plugin), [Set up with one prompt](docs/install.md#set-up-with-one-prompt), [Client setup](docs/install.md#client-setup), [Configure downstream servers](docs/install.md#configure-downstream-servers), [From source](docs/install.md#from-source), [Demo server](docs/install.md#demo-server) |
| [Command line](docs/cli.md) | [init](docs/cli.md#init), [Doctor](docs/cli.md#doctor), [Check a server and a run](docs/cli.md#check-a-server-and-a-run), [onboard](docs/cli.md#onboard), [skills export](docs/cli.md#skills-export-and-skills-remove), [functions check and try](docs/cli.md#functions-check-and-functions-try) |
| [Configuration](docs/configuration.md) | [The policy](docs/configuration.md#the-policy), [Tools that require a person](docs/configuration.md#tools-that-require-a-person), [With Claude Code auto mode](docs/configuration.md#with-claude-code-auto-mode), [Files of a program](docs/configuration.md#files-of-a-program), [Non-text results](docs/configuration.md#non-text-results), [Untrusted text](docs/configuration.md#untrusted-text), [The config file](docs/configuration.md#the-config-file), [Run log](docs/configuration.md#run-log), [Learned result shapes](docs/configuration.md#learned-result-shapes), [Guarded folders](docs/configuration.md#guarded-folders) |
| [Protocol](docs/protocol.md) | [Go back to 1.0.5](docs/protocol.md#go-back-to-105), [The default and the two variables](docs/protocol.md#the-default-and-the-two-variables), [What a link ends on](docs/protocol.md#what-a-link-ends-on), [Approval on a 2026-07-28 connection](docs/protocol.md#approval-on-a-2026-07-28-connection), [Roots and the Workspace on a 2026-07-28 connection](docs/protocol.md#roots-and-the-workspace-on-a-2026-07-28-connection), [What auto does not do yet](docs/protocol.md#what-auto-does-not-do-yet) |
| [Skills](docs/skills.md) | [What toolscript-mcp serves](docs/skills.md#what-toolscript-mcp-serves), [Which skills a session gets](docs/skills.md#which-skills-a-session-gets), [See them](docs/skills.md#see-them), [Turn Skills off](docs/skills.md#turn-skills-off), [Turn a local skill into a function](docs/skills.md#turn-a-local-skill-into-a-function), [Claude Code](docs/skills.md#claude-code), [Permission](docs/skills.md#permission) |
| [Sharing](docs/sharing.md) | [Shared servers](docs/sharing.md#shared-servers), [Lazy start](docs/sharing.md#lazy-start), [Child guard](docs/sharing.md#child-guard) |
| [Authentication](docs/auth.md) | [OAuth login](docs/auth.md#oauth-login), [AWS SigV4](docs/auth.md#aws-sigv4) |
| [Sandbox and limits](docs/sandbox.md) | [Sandbox](docs/sandbox.md#sandbox), [Limits](docs/sandbox.md#limits) |
| [Workspace](docs/workspace.md) | [Turn it on](docs/workspace.md#turn-it-on), [The root of a session](docs/workspace.md#the-root-of-a-session), [The tools](docs/workspace.md#the-tools), [What the read tools cover](docs/workspace.md#what-the-read-tools-cover), [Named tasks](docs/workspace.md#named-tasks), [Set a task up safely](docs/workspace.md#set-a-task-up-safely), [Change files](docs/workspace.md#change-files), [How a file is opened](docs/workspace.md#how-a-file-is-opened), [What stays possible](docs/workspace.md#what-stays-possible), [Check it](docs/workspace.md#check-it), [Tested clients](docs/workspace.md#tested-clients) |
| [Claude Code as a downstream server](docs/claude-code-bridge.md) | [The entry and the policy](docs/claude-code-bridge.md#the-entry-and-the-policy), [The risks](docs/claude-code-bridge.md#the-risks), [In a program](docs/claude-code-bridge.md#in-a-program), [Measured with Claude Code 2.1.325](docs/claude-code-bridge.md#measured-with-claude-code-21325) |
| [Benchmarks](docs/benchmarks.md) | [Measured](docs/benchmarks.md#measured), [Comparison with native Code Mode](docs/benchmarks.md#comparison-with-native-code-mode), [toolscript-mcp and Claude Code Code Mode](docs/benchmarks.md#toolscript-mcp-and-claude-code-code-mode) |
## Roadmap
- [x] Move the core and the sandbox runner out of the Claude Code plugin.
- [x] Start the sandbox on Linux, macOS and Windows.
- [x] Read a server config, connect to your MCP servers and add `search_tools`.
- [x] Add `run_code` with allow, deny and ask rules.
- [x] Write the docs and add the release workflow.
- [x] Compare toolscript-mcp with Claude Code Code Mode in the bench.
- [x] Log in to remote servers with OAuth.
- [x] Offer guided setup through the Claude Code plugin.
- [x] Run Claude Code tools through the optional stdio bridge, with a project `cwd`.
- [x] Require per-run approval for tools marked for user interaction.
- [x] Keep images and other non-text results as files, and show the images that a program returns.
- [x] Publish 1.0.0 to npm.
- [x] Run the Codex comparison and publish the [results](bench/RESULTS-codex.md).
- [ ] Keep state between `run_code` calls, as an option.
- [x] Serve hint files and saved functions as MCP Skills on the 2026-07-28 protocol. See [Skills](docs/skills.md).
## Credits
toolscript-mcp is derived from [claude-code-mode](https://github.com/gabe4coding/claude-code-mode) by Gabriele
Pavanello, under the MIT License, at commit `eea4077`. The sandbox runner, its protocol, tool search, output
projection and the hint format are his work.
Do you use only Claude Code? Then use his plugin. It reuses the MCP connections and the permission checks of Claude
Code.
toolscript-mcp is an independent project. Gabriele Pavanello does not endorse it. It is not affiliated with or
endorsed by Anthropic. Claude and Claude Code are trademarks of Anthropic.
## Licence
MIT. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
The package has no runtime dependency. `dist/host/main.js` holds the MCP TypeScript SDK v2, `@modelcontextprotocol/client`,
`server` and `core` 2.4.0 (Apache License 2.0), and the packages that they use. These are under the MIT, ISC and BSD-3-Clause licences.
`dist/third-party-licenses.txt` holds their licence texts.
This server cannot be deployed
Maintenance
ActivityActive
ResponsivenessUsually handled