Skip to main content
Glama

Save a new script

tool_write

Create 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

NameRequiredDescriptionDefault
runNoRun it right after saving, using args
argsNoUsed when run is true
codeYesThe script body (async function body)
nameYes2-40 letters, digits, _ or -; starts with a letter
paramsNoShort note on the args the script expects, e.g. {"source": "image path"}
overwriteNoReplace a script with the same name. Default false
descriptionNoOne line a person can read in the script list

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.1.0

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Goes well beyond the sparse annotations (idempotentHint=false, destructiveHint=false) by disclosing where scripts persist (tools/ next to config.json), the sandbox limits (no network, no other file access, no child processes), and the exact runtime API surface available inside the body. It also explains writeFile's output-folder behavior and the restriction that readFile only reaches args-named or tool-returned files, which an agent could not infer from structured fields.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loads purpose and the use condition before the dense API inventory, and the closing example body is worth its length because it demonstrates the contract. The middle section is a long run-on enumeration of runtime helpers, which is information-dense but slightly harder to scan than a short list would be.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 7-parameter code-execution tool with no output schema, it covers the essential ground: sandbox boundaries, file I/O semantics, available helpers, and the requirement to `return` a JSON value. An agent has enough to author and invoke a script correctly without trial and error.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3, but the description adds real meaning: it clarifies that run triggers immediate execution against args, that code is an async function body, and it supplies a concrete example body showing the expected idioms. The only gap is that overwrite's replacement semantics on disk are left to the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb+resource ("Write a new script") and immediately scopes it with the condition "when no existing tool does the job," which separates it from tool_use and tool_edit. The parenthetical example ("a special image clean-up") removes ambiguity about what kind of work warrants a new script.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives a clear triggering condition (no existing tool covers the job) and names the downstream reuse path via tool_use, plus the run:true shortcut for immediate execution. It stops short of explicitly contrasting with tool_edit, which is the nearest sibling an agent might confuse for modifying an existing script.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.