MCP Cost Tracker Router

by dbsectrainer

Not rated
GitHub

About

Real-time cost awareness for MCP agent workflows — track spend, set budgets, and route by model pricing

Details

Author
dbsectrainer
Categories
Developer Tools

Setup

Install MCP Cost Tracker Router in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/dbsectrainer/mcp-cost-tracker-router

Follow the installation instructions in the repository README, then restart your MCP client.

Real-time cost awareness for MCP agent workflows — track spend, set budgets, and route by model pricing

Local-first cost awareness for MCP agent workflows. Token counts are calculated offline using js-tiktoken — no proxy, no API round-trip, no spend data leaving your machine. When costs climb, routing suggestions point you to cheaper models before the invoice arrives.

Tool reference|Configuration|Contributing|Troubleshooting

- Per-tool cost breakdown: See exactly which tool calls are consuming the most tokens and budget.
- Budget alerts: Set a session spend threshold and get warned at 80% and 100% before you exceed it.
- Offline token counting: Uses js-tiktoken for accurate counts — no API calls required.
- Model routing suggestions: Recommends cheaper models for the current task type (advisory, never enforced without opt-in).
- Multi-provider pricing: Tracks costs across Claude, OpenAI, and Gemini models from a single configurable pricing table.
- Spend history: Query daily, weekly, and monthly totals by model or tool.
- Project cost allocation: Tag sessions to named projects and generate chargeback reports.
- HTML spend reports: Export a single-file, self-contained HTML report with charts and budget status.
- Audit log: Append-only log of every budget enforcement decision.

Why this over proxy-based cost trackers?

Most cost-tracking tools work by routing all your API traffic through their server and measuring tokens server-side. That means your prompts and responses transit a third-party service, and you're dependent on their uptime.

If your prompts contain sensitive information or you can't route traffic through a third party, this is the right tool. If you need a managed dashboard with team sharing, a proxy-based service may suit you better.

mcp-cost-tracker-routerstores tool call metadata (token counts, model names, timestamps) locally in SQLite. It does not store prompt or response content. Cost calculations are estimates based on a local pricing table and may not exactly match your provider's invoice.

Add the following config to your MCP client:

{ "mcpServers": { "cost-tracker": { "command": "npx", "args": ["-y", "mcp-cost-tracker-router@latest"] } } }
{ "mcpServers": { "cost-tracker": { "command": "npx", "args": ["-y", "mcp-cost-tracker-router@latest", "--budget-alert=5.00"] } } }

Amp · Claude Code · Cline · Cursor · VS Code · Windsurf · Zed

Enter the following in your MCP client to verify everything is working:

Your client should return a token and USD cost summary for the current session.

- get_session_cost— Returns token totals and USD cost estimates for the current session. Read-only.
- get_tool_costs— Returns per-tool cost breakdown for the session, sorted by cost descending. Read-only.
- reset_session— Start a new cost-tracking session. Previous session data is retained in history.
- record_usage— Record token usage for a tool call. Takestool_name,model(optional),input_tokens, andoutput_tokens. Emits a budget warning notification if 80% of threshold is reached.

- set_budget_alert— Set a budget threshold in USD (threshold_usd). Warns at 80% and 100% of the threshold. Use with--enforce-budgetto block calls beyond the limit.
- suggest_model_routing— Heuristic model recommendation by task type. Takestask_descriptionand optionalconstraints.max_cost_usd. Returns recommended model with reasoning and estimated cost.
- check_routing_policy— Check whether a model is allowed for a given task type under the routing policy. Takestask_typeandmodel.

- get_spend_history— Query historical spend aggregated byperiod(day/week/month). Returns breakdown by model and tool. Read-only.
- estimate_workflow_cost— Pre-run cost estimation for a multi-step workflow. Takes astepsarray withtool_name,estimated_input_tokens,estimated_output_tokens, and optionalmodel. Read-only.
- export_spend_report— Generate a single-file HTML spend report with session breakdown, historical spend, model cost comparison, and budget status. Read-only.
- export_budget_audit— Export the audit log of budget enforcement decisions. Accepts optionalfrom_date,to_date, andformat(json/csv). Read-only.

- set_project— Create or update a project with an optionalbudget_usd. Takesproject_name.
- tag_session— Tag the current session with aproject_namefor cost allocation.
- get_project_costs— Get cost report for a project. Takesproject_nameand optionalsince(ISO date). Read-only.
- export_chargeback— Generate a chargeback report for internal billing. Takesfrom_date,to_date, optionalgroup_by(project/session), and optionalformat(json/csv). Read-only.

Session spend threshold in USD. A warning is returned when session costs reach 80% and again at 100% of this threshold.

Path to the SQLite database file used to store cost history.

Path to a JSON file containing custom model pricing ($/1K tokens). Merged with the built-in table; missing models fall back to defaults.

Model name to attribute costs to when no model can be inferred from context.

Block tool calls that would cause the session to exceed the budget alert threshold. Requires--budget-alertto be set.

Start in HTTP mode using Streamable HTTP transport instead of stdio. Useful for sharing a single cost-tracking instance across a team.

Type:numberDefault: disabled (uses stdio)

Pass flags via theargsproperty in your JSON config:

{ "mcpServers": { "cost-tracker": { "command": "npx", "args": [ "-y", "mcp-cost-tracker-router@latest", "--budget-alert=2.00", "--enforce-budget" ] } } }

Built-in pricing table (USD per 1K tokens):

Override individual model prices with--pricing-table. All costs are estimates.

Before publishing a new version, verify the server with MCP Inspector to confirm all tools are exposed correctly and the protocol handshake succeeds.

npm run build && npm run inspect
# List all tools npx @modelcontextprotocol/inspector --cli node dist/index.js --method tools/list # List resources and prompts npx @modelcontextprotocol/inspector --cli node dist/index.js --method resources/list npx @modelcontextprotocol/inspector --cli node dist/index.js --method prompts/list # Call a read-only tool npx @modelcontextprotocol/inspector --cli node dist/index.js \ --method tools/call --tool-name get_session_cost # Call record_usage with arguments npx @modelcontextprotocol/inspector --cli node dist/index.js \ --method tools/call --tool-name record_usage \ --tool-arg tool_name=my_tool --tool-arg input_tokens=500 --tool-arg output_tokens=200

Run before publishing to catch regressions in tool registration and runtime startup.

Updatesrc/pricing.tswhen new models are released. All cost calculation changes must include unit tests with known token counts and expected USD values. Routing suggestions live insrc/tools/routing.ts.

This is a web browser that enables your coding agent, such as Claude Code, to visit websites on your behalf and assist you in identifying bugs or creating UI test cases.

Create crafted UI components inspired by the best 21st.dev design engineers.

Bring agent evaluations, observability, and synthetic test set generation directly into your IDE for free with Galileo's new MCP server

An MCP server to help AI assistants to answer questions and generate AccelByte Extend SDK code more effectively .

MCP server for AI Diagram Maker — generate beautiful software engineering diagrams directly inside Cursor, Claude Desktop, Claude Code, or any MCP-compatible AI agent

ALAPI MCP Tools,Call hundreds of API interfaces via MCP

AI-powered SVG animation generator that transforms static files into animated SVG components using the Allyson platform

MCP server that gives AI assistants on-demand access to 1,500+ amCharts docs, ~300 code examples, and 1000+ class API references.

APIMatic MCP Server is used to validate OpenAPI specifications using APIMatic. The server processes OpenAPI files and returns validation summaries by leveraging APIMatic’s API.

One shared context layer for AI agents and humans — live API specs, DB schemas, and versioned contracts across repos so every agent and teammate works from the same source of truth.

Build and deploy full-stack Next.js apps with 98 tools for React, AWS, and MongoDB

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.