Save a new script
tool_writeCreate and save a custom reusable JavaScript tool when no existing print-mcp tool handles a task, and optionally run it right away with supplied arguments.
Instructions
Write a new script when no existing tool does the job (for example a special image clean-up). It is saved so it can be reused with tool_use, and run at once when run:true. Scripts are small JavaScript tools saved on this computer (folder tools/ next to config.json) so they can be run again later. The script body is an async function: it gets args, call(toolName, args) (runs any print-mcp tool and returns its parsed result), readFile(path) (Buffer; only files named in args or returned by tools), writeFile(name, bufferOrText) (saved in the run's output folder, returns the path), sharp(buffer) for image work (no file paths: pass a Buffer, save with writeFile), log(...), sleep(ms), and toolList / toolUse / toolWrite / toolEdit / toolRemove. return a JSON value. No network, no other file access, no child processes. Example body: const buf = await readFile(args.source); const out = await sharp(buf).trim().png().toBuffer(); return { saved: await writeFile('trimmed.png', out) };
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"name": "<name>",
"code": "<code>"
},
"name": "tool_write"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| run | No | Run it right after saving, using args | |
| args | No | Used when run is true | |
| code | Yes | The script body (async function body) | |
| name | Yes | 2-40 letters, digits, _ or -; starts with a letter | |
| params | No | Short note on the args the script expects, e.g. {"source": "image path"} | |
| overwrite | No | Replace a script with the same name. Default false | |
| description | No | One line a person can read in the script list |