tokendiet-mcp
tokendiet-mcp
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-alpinecontainer.Dual MCP Stdio Framing: Supports both newline-delimited JSON (
NDJSON) andContent-Lengthframing out of the box.Strict Tool Safety: All 4 tools enforce
additionalProperties: falseand explicit read-only safety annotations (readOnlyHint: true,destructiveHint: false,idempotentHint: true,openWorldHint: false).
Exposed MCP Tools
Tool Name | Purpose |
| Breaks down MCP |
| Simulates |
| Scans every candidate |
| Audits |
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-mcpGitHub 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 toolsaudit_instruction_bloatBRead-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_tokensBRead-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_turnBRead-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_costBRead-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
Scored across 4 tools
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.
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.
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.
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
Related MCP Connectors
LLM cost optimization gateway, repo token-waste auditor & model arbitrage MCP server.
Free, no-key MCP server: token estimates, JSON Schema conversion, MCP configs, tool search.
Hosted MCP server for LLM cost estimation, model comparison, and budget-aware routing.
Zero-auth Streamable HTTP MCP server for cited Web3, token risk, and on-chain deep research.
Related MCP Servers
- AlicenseBqualityDmaintenanceLocal 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.5ISC
- AlicenseNot gradedqualityDmaintenanceMCP server for deterministic, zero-dependency context-window math, enabling token estimation, text truncation, and budget reporting without a tokenizer.MIT
- AlicenseNot gradedqualityDmaintenanceA 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.1MIT
- AlicenseAqualityBmaintenanceAn MCP server that exposes token-optimization pipeline functions as tools, enabling MCP-compatible hosts to reduce token usage in requests before they are forwarded to an Anthropic-compatible backend.81Apache 2.0