GitHub 0
Skip to content

Token budget

What a tools list costs in Claude tokens before any call, how is-mcp-ok counts it, and how to fail a run when it grows.

budget is what initialize and tools/list cost in Claude tokens before any call. A client sends the model the tools' total plus the server's instructions before the first call.

budget: 553 Claude tokens for the tools list at 2.4 characters a token, plus 1621 for the instructions
  tool                 description  input  output  total
  ask_wiki_question             45    148      46    244
  read_wiki_structure           25     82      46    158
  read_wiki_contents            19     82      46    151
  output schemas: 138 tokens, outside the total; whether clients send them to the model is unverified
text

Each tool has a row: its description, its input schema, its output schema, and total, the whole tool entry without its output schema. The server's instructions get their own row, instructions, outside the tools' total. Output schemas are counted apart in outputSchemas, since whether clients send them to the model is unverified.

Tokens are characters divided by 2.4, the ratio in the report. The usual ÷ 4 fits OpenAI's tokenizer, which measures 4.0 to 4.6 characters per token on tools/list. Claude measures 2.4 to 2.9 on tools/list, so ÷ 4 undercounts it by a quarter to a half.

Install the preview CLI for the examples below. npm 0.1.1 reports the budget but doesn't have the flags to save a baseline, compute a diff or enforce a limit.

Two flags fail a run on the budget, as a bundle-size check does:

  • --max-tokens <n> exits 1 when it is over <n> Claude tokens.
  • --max-increase <n|n%> exits 1 when it grew by more than <n> tokens, or <n> percent, since a baseline.

A baseline is the last tools/list you accepted, saved as JSON. --save writes what the CLI read from a server, { initialize, tools }, never the calls, a header or the URL:

pnpm exec is-mcp-ok http://localhost:3000/mcp --save mcp-tools.json
pnpm exec is-mcp-ok http://localhost:3000/mcp --baseline mcp-tools.json --max-increase 5%

Commit the baseline, and a pull request's diff shows which descriptions and schemas changed. To accept a larger budget, run --save again and commit the file. Any file the CLI reads works as a baseline.

With --baseline, the text output adds each tool that was added, removed or changed cost:

budget vs mcp-tools.json: 1930 → 2174, +244 Claude tokens (+12.6%)
                           before  after  change
  ask_wiki_question (new)       –    244    +244
  2 tools unchanged
text

--json adds budgetDiff: before, after, delta and share, the instructions before and after, and the same tool changes. Both sides are measured with the CLI that runs, so a new ratio never shows as a change.

Tool rows are rounded one by one, while the total is rounded after adding up characters. An edit can leave every row the same and still move the total.

advice holds rules on the list that cost tokens or calls without failing anything: no server instructions, a description that never says when to use the tool, output keys in mixed styles, or one parameter spelled two ways across tools. List advice has each rule and its fix. Advice is info and never changes the exit code.