--- name: design-mcp-tools description: Design or review the tools of an MCP server (a toolsmelt plan.yaml, or any existing server's tool names, descriptions, arguments and output size). Use when the user asks to improve, audit or write tool definitions so agents call them correctly and cheaply. --- # Design MCP tools The source of truth is `toolsmelt guide` (prints the tool-design rules). Run it first and follow it where it differs from this list. This file is the checklist and the measuring loop. ``` toolsmelt guide ``` Without a shell, call the `smith_guide` MCP tool (`claude mcp add toolsmelt -- uvx toolsmelt mcp`). ## Checklist (per plan or server) Tool set - Few tools: aim under 10, hard stop 20 (validation warns above 20). One tool per user task, not per endpoint. Merge list + filter + sort variants into one tool with args. - Drop endpoints no stated task needs (admin, health, duplicates, tracking calls). - Names: `_`, snake_case, stable. Renaming later breaks callers. Descriptions - First line: one complete sentence on what the tool returns. It becomes the catalog summary, so it must stand alone and end with a period. - Then: when to use it, what to call next (name the tool), what to do when the result is empty. - Plan `description` (the whole server) is at most 100 characters. Arguments - Plain names a person would say: `query`, `max_price`, `city`. Not wire names like `q[price_lte]`. - Each description has the unit and one example value ("price in toman, e.g. 500000"). - Add `enum`, `minimum`, `maximum`, `default` where known. Required only when the call cannot work without it (a required arg cannot have a default). - Cut args the model never needs; pin constants with `fixed:`. - Cryptic wire values (sort codes, index names): use `map: {newest: sort_date_desc}` so the model sees plain words. - Cryptic wire names (`emp_id`, `dt_from`, `Item_dev`): rename the arg to a plain word and keep the wire name in `to:`. - Dates and numbers the API wants in another format: `transform` on the arg (`date->unix`, `date->unix_end` for an inclusive end day, `toman->rial`, `int->str`; also `jalali->...` for the Persian calendar). The model passes `YYYY-MM-DD`; day boundaries follow plan `timezone` (IANA name, e.g. `Europe/Berlin`; empty = system local zone). - A public key the site ships to every visitor may go in `fixed:`; a user's own token stays in `auth` (env var). - Each arg `to:` is one of `path.`, `query.`, `header.`, `cookie.`, `body`, `body.`. Output - `output.root` points at the useful part; `output.fields` maps short names to dotted paths. Compact: id, title/name, price, url, one-line status. Drop images arrays, tracking, HTML, nulls. - Convert on the way out with `output.transforms` (output name -> `unix->date`, `unix->datetime`, `minutes->hh:mm`, `rial->toman`, `date->jalali`) so the model never reads raw unix times or minute counts. - Keep every id or slug the next tool needs as input. - `max_items` on lists (the result also reports the total count); lower `clip` for long strings. - Paginated APIs: expose `page` (or cursor) as an arg and mention in the description how to get the next page. - Do not return raw JSON dumps; an endpoint response over 4 KB without `fields` triggers a warning. Safety and server - `read_only: true` only for GET-like reads; writes get `read_only: false` and say what they change. - `example` for every tool with required args; real values that return data. - `instructions`: the cross-tool workflow ("search, then details by id"), units, currency, language, rate limits, limits of the data. - Secrets only via env vars (`

_...`) or `toolsmelt secret set`, never in args or descriptions. - Site that needs the user's login: `auth: {type: browser, login_path: /login}` (hub only; `login_path` is where the site redirects when logged out). Also set `session_cookie`, the login cookie's name: compare the cookie NAMES Chrome holds logged in vs logged out (`toolsmelt.browser.cookies_for`, names only, never print values). Some sites answer an ended session with HTTP 200 and an empty body. `generate` refuses it: switch to token auth to export. ## Measure ``` toolsmelt validate -w .toolsmelt toolsmelt check --json ``` `check` calls each tool live with its `example` and reports `ok`, `error`, `chars` (output size) and `empty_fields` (output fields that came back empty). - Aim under about 4,000 chars per call. Over that: trim `fields`, lower `max_items`/`clip`, split the tool. - `empty_fields` non-empty: wrong dotted path or an optional field; open `tests/fixtures/.json` for the real shape. - Any `error`: fix the example, auth or mapping before polishing wording. - Non-GET tools hit the real service; get the user's confirmation before running `check` on them. Tool choice (needs an LLM API key, e.g. `ANTHROPIC_API_KEY`): ``` toolsmelt eval -w .toolsmelt --write --provider anthropic toolsmelt eval -w .toolsmelt ``` `--write` asks the LLM for one or two natural questions per tool (expected args from its `example`) plus a few questions no tool fits, saved as `evals.yaml` (never overwritten without `--force`). Review and edit it, then commit it. A plain run sends each question with the tool list exactly as the server exposes it and scores the pick: `score` (cases with right tool and args), tool and arg accuracy, and per tool which tool was picked instead. Pass a generated project instead of `-w` to evaluate it; `--json` and `--min 0.9` for CI. - A tool often picked instead of another: sharpen both first lines and say when to use which. - Right tool, wrong args: improve the arg descriptions (unit, format, one example), add `enum` or `map`. - A negative answered with a tool: say in the description what the tool does not cover. Loop: edit `plan.yaml`, `toolsmelt validate`, `toolsmelt generate -o --force`, `cd && uv run pytest`, `toolsmelt check `. Regenerating overwrites hand edits to `server.py`. ## Reviewing a server not made with toolsmelt Read its tool list, apply the same checklist, and report findings as: tool, problem, concrete rewrite (new name, first-line sentence, trimmed fields). Measure real output sizes by calling the tools, not by guessing. Do not claim a size you did not measure.