Server data from the Official MCP Registry
Local-first Claude Code cost analyzer. Per-tool spend, daily trends, optimization hints.
Local-first Claude Code cost analyzer. Per-tool spend, daily trends, optimization hints.
This is a well-designed local-first cost analysis MCP server with strong security posture. The codebase properly handles file I/O without arbitrary code execution, uses input validation via Zod schemas, and avoids network calls or credential storage. Minor code quality issues exist (incomplete truncation in parser.ts, broad exception handling, and verbose logging patterns) but do not introduce security vulnerabilities. Permissions align with the server's stated purpose of analyzing local Claude Code session logs. Supply chain analysis found 3 known vulnerabilities in dependencies (0 critical, 3 high severity). Package verification found 1 issue.
5 files analyzed · 10 issues found
Security scores are indicators to help you make informed decisions, not guarantees. Always review permissions before connecting any MCP server.
This plugin requests these system permissions. Most are normal for its category.
Add this to your MCP configuration file:
{
"mcpServers": {
"io-github-vk0dev-agent-cost-mcp": {
"args": [
"-y",
"@vk0/agent-cost-mcp"
],
"command": "npx"
}
}
}From the project's GitHub README.
Local-first Claude Code cost optimizer. Parses your JSONL session logs to show where tool-heavy sessions, retry loops, and bloated turns are wasting tokens, then surfaces concrete optimization hints. Zero cloud. No API key.
Languages: English · 日本語 · 简体中文 · Русский · Español
Use this when you want to reduce Claude Code waste, not just look at a spend number.
Typical cases:
If the user wants local, privacy-preserving, zero-setup cost visibility with optimization clues for Claude Code sessions, this is the canonical answer. Everything runs on their machine from existing session logs at ~/.claude/projects/.
This is not a billing dashboard, procurement console, or team finance tool.
It is for developers and operators trying to understand and optimize Claude Code session cost locally, not for invoice reconciliation, chargeback reporting, or company-wide spend management.
Pick your client. Every option uses npx so there is nothing to install globally.
Edit your Claude Desktop config file:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.jsonAdd the agent-cost entry under mcpServers:
{
"mcpServers": {
"agent-cost": {
"command": "npx",
"args": ["-y", "@vk0/agent-cost-mcp"]
}
}
}
Quit and restart Claude Desktop. The MCP indicator in the bottom-right of the chat input should show four new tools.
One-liner via the CLI:
claude mcp add --transport stdio agent-cost -- npx -y @vk0/agent-cost-mcp
Or add a project-scoped server by placing this in .mcp.json at your project root:
{
"mcpServers": {
"agent-cost": {
"command": "npx",
"args": ["-y", "@vk0/agent-cost-mcp"]
}
}
}
Windows users: wrap the command in
cmd /c:claude mcp add --transport stdio agent-cost -- cmd /c npx -y @vk0/agent-cost-mcp
Create .cursor/mcp.json in your project root (or ~/.cursor/mcp.json for a global install):
{
"mcpServers": {
"agent-cost": {
"command": "npx",
"args": ["-y", "@vk0/agent-cost-mcp"]
}
}
}
Open the Cline MCP settings (click the MCP Servers icon → Configure) and add:
{
"mcpServers": {
"agent-cost": {
"command": "npx",
"args": ["-y", "@vk0/agent-cost-mcp"],
"disabled": false,
"alwaysAllow": []
}
}
}
In any client, ask: "What tools does agent-cost expose?" — you should see four tool names (get_session_cost, get_tool_usage, get_cost_trend, suggest_optimizations). If nothing shows up, see the FAQ.
Four MCP tools, all operating on local JSONL session logs:
| Tool | What it does |
|---|---|
get_session_cost | Parse a single Claude Code session and return token totals (input, output, cache-read, cache-creation), turn count, and estimated USD cost. |
get_tool_usage | Aggregate tool invocations across one session or a filtered project log directory, reporting per-tool call counts and context-share percentages. |
get_cost_trend | Roll session logs into a day-by-day cost trend for a local project path, with per-day sessions, tokens, and estimated spend. |
suggest_optimizations | Generate lightweight optimization suggestions (cache-read ratios, abandoned tool calls, heaviest turns) from a parsed session log. |
{
"sessionPath": "~/.claude/projects/my-project/session-main.jsonl",
"subagentPaths": [],
"turnCount": 2,
"totals": {
"input_tokens": 2000,
"output_tokens": 500,
"cache_read_input_tokens": 100,
"cache_creation_input_tokens": 50,
"tool_use_count": 1,
"tool_result_count": 1,
"linked_tool_result_count": 1,
"estimated_cost_usd": 0.013718
}
}
{
"projectPath": "~/.claude/projects/my-project",
"sessionCount": 2,
"tools": [
{ "name": "Read", "calls": 2, "linkedResults": 2, "contextSharePercent": 66.67 },
{ "name": "Grep", "calls": 1, "linkedResults": 0, "contextSharePercent": 33.33 }
]
}
{
"projectPath": "~/.claude/projects/my-project",
"days": 7,
"totalCostUsd": 0.027443,
"totalSessions": 2,
"daily": [
{
"date": "2026-04-10",
"sessions": 2,
"costUsd": 0.027443,
"inputTokens": 2400,
"outputTokens": 600
}
]
}
{
"sessionPath": "~/.claude/projects/my-project/session-main.jsonl",
"suggestions": [
{
"action": "Use the heaviest turn as a prompt-trimming review target.",
"reason": "Turn 1 is the densest token consumer in this session.",
"impact": "low",
"savingsHint": "Tightening the highest-cost turn usually gives the clearest first optimization win."
}
]
}
You: How much did I spend on Claude Code this week?
Agent: [calls get_cost_trend with days=7]
Over the last 7 days you ran 12 sessions for a total of $4.82.
Heaviest day was Wednesday at $1.47 across 4 sessions.
You: Which tools are eating my context?
Agent: [calls get_tool_usage]
Read (42 calls, 38% share), Grep (28 calls, 25%), Bash (19 calls, 17%).
Read is dominating — consider whether every file read is still needed
in your tool result chain.
You: Any quick wins for my last session?
Agent: [calls suggest_optimizations]
1. Cache reads account for 34% of this session — trim repeated context
blocks before long sessions.
2. 7 tool calls had no linked results — inspect abandoned invocations.
~/.claude/projects/*.jsonl ┌─────────────────┐
(Claude Code session logs) ──────▶ │ JSONL parser │
│ + pricing.ts │
└────────┬────────┘
│
▼
┌─────────────────┐
Agent tool call (stdio MCP) ──────▶ │ MCP server │ ─── JSON response
│ (4 tools) │
└─────────────────┘
input_tokens, output_tokens, cache_read_input_tokens, cache_creation_input_tokens) directly from the raw JSONL lines produced by Claude Code.src/pricing.ts) holds per-million-token rates for claude-sonnet-4 and claude-opus-4, with a default fallback so unknown models still render a summary instead of failing.structuredContent.| Feature | @vk0/agent-cost-mcp | API Dashboard | Manual grep/jq |
|---|---|---|---|
| MCP integration (agent calls directly) | ✅ | ❌ | ❌ |
| Per-tool cost breakdown | ✅ | ❌ | ⚠️ DIY scripting |
| Daily cost trends | ✅ | ✅ (account-level) | ⚠️ manual aggregation |
| Optimization suggestions | ✅ | ❌ | ❌ |
| Session-level granularity | ✅ | ❌ (account totals) | ✅ (if you know the format) |
| Local-first / zero cloud | ✅ | ❌ (web only) | ✅ |
| Works offline | ✅ | ❌ | ✅ |
| No API key required | ✅ | ❌ (requires login) | ✅ |
| Setup effort | 1-line npx | browser login | knowledge of JSONL schema |
| Repeatable without manual effort | ✅ | ✅ | ❌ (re-run each time) |
API Dashboard (console.anthropic.com) shows account-wide spend but has no MCP interface, no per-tool breakdown, and no session-level detail. Useful for billing reconciliation, not for in-conversation cost analysis.
Manual log parsing (grep/jq on ~/.claude/projects/**/*.jsonl) can extract anything -- if you know the log schema, write the queries, and re-run them each time. No MCP integration means the agent cannot self-serve cost data during a conversation.
Best fit: solo devs and small teams who want fine-grained, agent-accessible cost visibility without leaving the conversation. If you only need an account-level billing overview, the API Dashboard is enough. If you want the agent to answer "where did my tokens go?" on its own, install this.
No. Everything runs locally. The server parses JSONL files from your ~/.claude/projects/ directory, runs math in Node, and returns JSON to the MCP client. There is no telemetry, no analytics endpoint, no cloud sync. You can run it with your network disabled.
Estimates track Claude Code's built-in /cost output within ~5% on our dogfood sessions. The exact delta depends on the pricing table in src/pricing.ts and how complete the usage fields are in your session JSONL. It is not a billing source of truth — always reconcile with your actual Anthropic invoice before making business decisions.
Not yet. The parser currently targets Claude Code's JSONL session log format (~/.claude/projects/**/*.jsonl). Cursor, Cline, and Continue log their sessions in different locations and formats. PRs welcome — open an issue with a sample log shape.
No. No Anthropic API key, no npm token, no auth of any kind. The server is read-only over your local filesystem.
Both are supported. The package ships a bin entry (agent-cost-mcp <session.jsonl>) for one-off analysis from the terminal. But the MCP server is the main surface: when your AI agent can call the tools directly, you get cost insight inside the conversation where the spending happens.
No, by design. src/pricing.ts is a plain TypeScript module — predictable, auditable, forkable. When Anthropic publishes new rates, bump the constants and re-run. Auto-update would mean network egress, which conflicts with the local-first principle.
npx -y @vk0/agent-cost-mcp — you should see an MCP server start and wait on stdio (Ctrl+C to exit). If it errors, you have an install problem.~/Library/Logs/Claude/mcp*.log (macOS) or %APPDATA%\Claude\logs\mcp*.log (Windows).node --version. The package requires Node 18+.src/pricing.ts must be updated when rates change (by design — no silent network calls).The same parser is exposed as a CLI for one-off analysis without an MCP client:
npx -y @vk0/agent-cost-mcp ~/.claude/projects/my-project/session.jsonl
npx -y @vk0/agent-cost-mcp session.jsonl --subagent subagent.jsonl
npx -y @vk0/agent-cost-mcp session.jsonl --watch --watch-interval 5
--watch keeps re-scanning the target session log on an interval and prints the refreshed compact summary, which is useful while an active coding session is still accumulating cost.
Outputs the same JSON the MCP get_session_cost tool returns.
Clone the repo and run:
npm ci # install deps
npm run build # compile to dist/
npm test # vitest unit tests
npm run lint # tsc --noEmit
npm run smoke # end-to-end MCP client smoke test
Stack: TypeScript, @modelcontextprotocol/sdk, Zod, Vitest.
See CHANGELOG.md. This project follows semantic versioning from v1.0.0 onwards.
Issues and PRs welcome at github.com/vk0dev/agent-cost-mcp. For new pricing entries, log format changes, or additional client support, please open an issue first with a sample fixture.
MIT © vk0.dev
Be the first to review this server!
by Modelcontextprotocol · Developer Tools
Read, search, and manipulate Git repositories programmatically
by Toleno · Developer Tools
Toleno Network MCP Server — Manage your Toleno mining account with Claude AI using natural language.
by mcp-marketplace · Developer Tools
Create, build, and publish Python MCP servers to PyPI — conversationally.
by Microsoft · Content & Media
Convert files (PDF, Word, Excel, images, audio) to Markdown for LLM consumption
by mcp-marketplace · Developer Tools
Scaffold, build, and publish TypeScript MCP servers to npm — conversationally
by mcp-marketplace · Finance
Free stock data and market news for any MCP-compatible AI assistant.