Skip to main content
Glama

tokendiet-mcp

MCP Server License: MIT Node >= 20

Zero-dependency Open-Core MCP Server, CLI, and GitHub Action for auditing MCP JSON Schema token weight, simulating multi-turn O(T^2) prompt-cache TTL cliffs across 9 LLM pricing tiers, computing cost-minimizing /compact checkpoints, and blocking CLAUDE.md / AGENTS.md / .cursorrules / .mcp.json bloat in pull requests.

  • 100% Local & Offline: Zero external runtime dependencies, zero network telemetry, non-root node:22-alpine container.

  • Dual MCP Stdio Framing: Supports both newline-delimited JSON (NDJSON) and Content-Length framing out of the box.

  • Strict Tool Safety: All 4 tools enforce additionalProperties: false and explicit read-only safety annotations (readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false).


Exposed MCP Tools

Tool Name

Purpose

audit_mcp_schema_tokens

Breaks down MCP tools[] or .mcp.json JSON Schema token weight per server and per tool, projects 30-turn cumulative cost, and flags additionalProperties: true, verbose descriptions, and wildcard mounts.

simulate_agent_session_cost

Simulates 1..100 turn O(T^2) coding session and monthly spend across 5m / 1h prompt-cache TTLs, idle pause gaps, and mid-session screenshot cache-bust cliffs across 9 LLM pricing tiers (Claude Sonnet 4.5, Claude Opus 4.5, GPT-5, OpenAI o3, Gemini 2.5 Pro, Gemini 2.5 Flash, DeepSeek V3, DeepSeek R1, Qwen-Max).

find_optimal_compact_turn

Scans every candidate /compact checkpoint turn (4..T-2) to find the exact turn minimizing total session spend.

audit_instruction_bloat

Audits CLAUDE.md, AGENTS.md, .cursorrules, .windsurfrules, and .mcp.json sections for 30-turn cumulative token cost, embedded code-fence bloat, and cross-file duplicate instructions.

Also implements prompts/list, prompts/get, resources/list, and resources/read (tokendiet://reference/model-pricing-tiers and tokendiet://guides/github-action-setup).


Related MCP server: contextlens

Quick Start (MCP Clients)

Claude Desktop / Cursor / Claude Code (.mcp.json)

{
  "mcpServers": {
    "tokendiet": {
      "command": "npx",
      "args": ["-y", "github:z121245017-ai/tokendiet-mcp"]
    }
  }
}

Docker (node:22-alpine, Non-Root USER node)

docker build -t tokendiet-mcp .
docker run --rm -i tokendiet-mcp

GitHub Action (z121245017-ai/tokendiet-mcp@v1)

Block accidental CLAUDE.md, AGENTS.md, or .mcp.json static-prefix bloat in pull requests with inline ::error annotations and a Markdown PR Step Summary:

name: Agent Token Budget Gate
on: [pull_request, push]

jobs:
  tokendiet-gate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: z121245017-ai/tokendiet-mcp@v1
        with:
          workspace: '.'
          max-baseline-tokens: '12000'
          turns: '30'
          model: 'claude_sonnet_4_5'
          fail-on-duplicates: 'true'
          fail-on-unpinned-mcp: 'false'

Local CLI Usage

# Audit current repository against a 12,000-token static prefix budget
node ./bin/tokendiet-mcp.mjs --audit --workspace . --max-baseline-tokens 12000

# Invoke any MCP tool directly from the terminal
node ./bin/tokendiet-mcp.mjs --cli find_optimal_compact_turn '{"modelId":"claude_sonnet_4_5","turns":36,"mcpSchemaTokens":22000}'

License

MIT © 2026 z121245017-ai

Available Tools

4 tools
audit_instruction_bloatB
Read-onlyIdempotent

Audit CLAUDE.md, AGENTS.md, .cursorrules, .windsurfrules, and optional .mcp.json sections for 30-turn cumulative token cost, embedded code-fence bloat, and cross-file duplicate instructions.

Inputs: files, turns, mcpJson, modelId, +5 more.

audit_mcp_schema_tokensB
Read-onlyIdempotent

Break down MCP tools[] or .mcp.json configuration JSON Schema token weight per server and per tool, compute multi-turn cumulative prefix cost, and flag additionalProperties: true schemas, verbose tool descriptions, and wildcard eager mounts.

Inputs: mcpJson (required), turns, modelId, verboseDescriptionChars.

find_optimal_compact_turnB
Read-onlyIdempotent

Scan every candidate /compact checkpoint turn across a multi-turn coding session to compute the exact compaction turn that minimizes total session and monthly token spend.

Inputs: turns, modelId, imageTokens, cacheTtlMode, +8 more.

simulate_agent_session_costB
Read-onlyIdempotent

Simulate 1..100 turn O(T^2) coding agent session and monthly token spend across 5m/1h prompt-cache TTLs, pause gaps, and mid-session screenshot cache-bust cliffs across 9 published LLM pricing tiers.

Inputs: turns, modelId, compactTurn, imageTokens, +12 more.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 4 tools

    Disambiguation4/5

    The two audit tools target clearly different artifacts (MCP schema/config vs. instruction files), and the simulation and optimization tools have distinct roles. Minor potential overlap between the audit tools is mitigated by their explicit target names in the descriptions.

    Naming Consistency5/5

    All four tools use snake_case with a verb-first pattern (audit_*, simulate_*, find_optimal_*). The variation in verbs is meaningful and consistently applied across the set.

    Tool Count5/5

    Four tools is a well-scoped set for a token-cost auditing and simulation server. Each tool addresses a distinct stage—schema audit, instruction audit, session simulation, and compaction optimization—with no redundant entries.

    Completeness4/5

    The surface covers auditing, simulating, and optimizing token spend across MCP schemas and instruction files, which are the core domain needs. Minor gaps exist, such as no dedicated export/report tool or direct session comparison, but agents can chain the existing tools for most workflows.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      Local MCP server for token optimization, providing tools to compress code/JSON, optimize prompts, and manage placeholder-based content redaction and hydration to reduce LLM token usage.
      5
      ISC
    • A
      license
      Not graded
      quality
      D
      maintenance
      A local, zero-cloud MCP server for token and text compression. It provides tools to compress, auto-compress, measure, and decompress text using offline rules, lossless gzip packing, or a local Ollama semantic model.
      1
      MIT