Skip to main content
Glama
mcp-context-budget

mcp-context-budget

by yuehancn

mcp-context-budget

Your MCP servers eat the context window before you type anything. This tells you how much, and which one to drop.

Free, local, read-only. No account, no network call, no telemetry.


The problem this solves

Every MCP server you install injects its full tool schema into every request. There is no lazy loading in the protocol. A dozen servers can consume tens of thousands of tokens before your first message, and nothing in the client tells you this is happening — the agent just gets quietly worse.

Known incidents from public reports:

  • Cloudflare's standard MCP server consumed 1.17M tokens in production, prompting a dedicated workaround.

  • A practitioner measured 45K tokens for GitHub MCP alone — 22.5% of a 200K window.

  • A 12-server setup reported the system prompt at 18,000 tokens before the user typed.

This tool measures your actual setup instead of quoting those numbers at you.

Related MCP server: mcp-checkup

Why measurement, not estimation

The config file only records how to start a server. The real cost lives in the tools/list payload, which changes with the server version and its runtime flags. Guessing from the config produces a confident wrong answer.

So this tool starts each stdio server, asks it for its tools, measures the payload, and shuts it down. That is the only honest method, and it takes a few seconds.

Install

Requires Python 3.8+. No dependencies.

git clone <repo> mcp-context-budget

Add to your MCP client config (claude_desktop_config.json, .cursor/mcp.json, or ~/.workbuddy/mcp.json):

{
  "mcpServers": {
    "mcp-context-budget": {
      "command": "python",
      "args": ["/absolute/path/to/mcp-context-budget/run.py"]
    }
  }
}

Tools

audit_context_budget

Full report: cost per server, cost per tool, findings with quantified savings, and a fix order.

How much of my context window are my MCP servers eating?

Optional arguments: window (200k default, or 128k/32k/16k), config (explicit path), show_tools (list the N most expensive tools per server).

rank_servers_by_cost

Just the ranking. Answers "which server should I remove first" in one line per server.

explain_token_cost

Measure an arbitrary schema or string before you publish a server of your own. Reports the CJK/ASCII split and shows how wrong the naive len/4 heuristic would be.

What it detects

Finding

What it means

single_tool_dominates

One tool costs ≥2.5% of the window on its own

repeated_boilerplate

The same sentence appears in 4+ tool descriptions

enum_listed_twice

An enum is spelled out in prose and declared in the schema

near_duplicate_tools

4+ tools with identical parameter shapes, differing only by verb

param_desc_restates_name

A parameter description that only repeats the field name

Each finding carries an estimated token saving, so you can decide whether it is worth the edit.

What it does not do

  • Does not edit anything. It never writes to your configs and never removes a server.

  • Does not measure remote servers. URL-based (SSE / streamable HTTP) servers are listed as not probed rather than silently scored zero. Their cost is real but cannot be measured locally.

  • Does not prove a bad agent is caused by schema cost. It quantifies one specific tax. If your schemas are 2% of the window, the cause is elsewhere and the report says so.

  • Estimates, not exact tokenizer output. No tokenizer dependency, by design — that would triple install size and pin you to one model family. The estimator is calibrated to over-count slightly, because under-counting a budget is the failure that hurts.

Reading the verdict

Verdict

Share of window

healthy

under 5%

watch

5–10%

over_budget

10–20%

critical

over 20%

Ten percent is the line where trimming is worth the afternoon. Twenty percent is where the agent is measurably worse than it was before you installed things.

Self-verification

Do not take the claims on faith:

python tests/selftest.py

28 checks, both directions: pathological schemas must be caught, and clean well-written servers must produce zero findings. The negative tests are the important half — a tool that cries wolf gets ignored, which is worse than no tool.

License

MIT.

Available Tools

3 tools
audit_context_budgetA

Measure how many tokens the configured MCP servers consume in the context window. Probes each stdio server, reads its real tools/list payload, and reports cost per server and per tool against a chosen window size. Use when the agent feels degraded after adding servers, or before installing another one. Read-only.

Inputs: config, window, show_tools.

explain_token_costA

Estimate the context cost of an arbitrary tool schema or text snippet, split by CJK versus ASCII. Use to sanity-check a schema before publishing a server, or to compare two descriptions.

Inputs: text (required), json.

rank_servers_by_costA

Rank installed MCP servers by context cost without a full report. Answers 'which server should I remove first'. Cheaper and faster than audit_context_budget. Read-only.

Inputs: top, window.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4/5.0

    Scored across 3 tools

    Disambiguation4/5

    explain_token_cost is clearly separate (arbitrary schema/text estimation) from the two server-inventory tools. audit_context_budget and rank_servers_by_cost target the same data with different depth, but the descriptions explicitly frame them as full report vs. cheap ranking, so confusion is limited though real.

    Naming Consistency5/5

    All three follow a clean verb_noun snake_case pattern (audit_*, rank_*, explain_*). The noun components vary sensibly with what each acts on.

    Tool Count4/5

    Three tools is on the thin side, but the domain (context-cost measurement) is narrow and each tool covers a distinct query pattern. No filler tools are present.

    Completeness4/5

    Covers the core lifecycle: full audit, quick ranking, and ad-hoc schema/text estimation. Minor gaps exist — no single-server targeted query or budget-threshold/warning configuration — but agents can reach the same answers through the provided tools.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      Diagnoses MCP server token costs, finds duplicates, grades efficiency, and generates optimization reports.
      49 npm
      1
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables analyzing and optimizing context window token usage by measuring, compressing, and eliminating waste from MCP tool definitions.
      58 npm
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables auditing MCP servers' tools by their estimated context token cost, ranking verbose names, descriptions, and schemas before they consume the agent window. Can run as an MCP tool so agents can budget their own context.
      1
      MIT