tokendiet-mcp
# tokendiet-mcp
[](https://glama.ai/mcp/servers/z121245017-ai/tokendiet-mcp)
[](./LICENSE)
[](./package.json)
**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`).
---
## Quick Start (MCP Clients)
### Claude Desktop / Cursor / Claude Code (`.mcp.json`)
```json
{
"mcpServers": {
"tokendiet": {
"command": "npx",
"args": ["-y", "github:z121245017-ai/tokendiet-mcp"]
}
}
}
```
### Docker (`node:22-alpine`, Non-Root `USER node`)
```bash
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:
```yaml
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
```bash
# 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](./LICENSE) © 2026 `z121245017-ai`
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.