Developer tools · MCP server

Trace AI API cost back to tokens and context.

AI Cost Analyzer turns usage records you provide into model-level cost breakdowns, token-waste estimates, and daily or weekly trends. It also projects savings from caching, model routing, and context pruning; applies simple prompt-cleanup rules; and compares a bundled set of model prices.

3 calls free Node.js 18+ stdio + optional SSE MIT license
stdio
$ npx -y ai-cost-analyzer

AI Cost Analyzer MCP server running on stdio

What it does

Calculations and recommendations from data you supply

The package performs local calculations and returns text reports through MCP. It does not need access to an AI provider account to analyze the records passed into its tools.

Measure

Break down recorded usage

Group requests by model, calculate input and output cost, account for cached input tokens, and summarize average request cost from supplied token counts.

Find

Surface possible context waste

Estimate unused tool-definition tokens and oversized system-prompt tokens, then organize supplied timestamps into daily and weekly cost trends.

Explore

Model optimization scenarios

Project potential effects of prompt caching, cheaper-model routing, and context pruning, or inspect a cleaned-up copy of a prompt and its tool definitions.

Agent workflows

Three concrete calls an MCP agent can make

Each example is a complete argument object using the parameter names and value types accepted by the shipped server.

Audit a usage sample

analyze_usage

Give the agent records from your own logs to calculate a cost summary, per-model breakdown, waste estimate, and time-based trends.

arguments.json
{
  "usage_data": [
    {
      "model": "claude-sonnet",
      "input_tokens": 12000,
      "output_tokens": 1600,
      "cached_tokens": 3000,
      "timestamp": "2026-03-15T10:00:00Z",
      "tool_definitions": 12,
      "system_prompt_tokens": 2400
    }
  ]
}

Project a monthly scenario

estimate_savings

Ask the agent to scale a usage sample and estimate savings from the analyzer's caching, routing, and pruning assumptions.

arguments.json
{
  "usage_data": [
    {
      "model": "gpt-4o",
      "input_tokens": 8000,
      "output_tokens": 900,
      "cached_tokens": 0,
      "timestamp": "2026-03-15T09:00:00Z",
      "tool_definitions": 10
    }
  ],
  "monthly_multiplier": 30
}

Review repeated prompt context

optimize_prompt

Have the agent return a cleaned-up prompt copy, estimated token counts, a cost projection, and recommendations. The original prompt is not modified.

arguments.json
{
  "system_prompt": "You are a support assistant. Please make sure to always answer concisely.",
  "tool_definitions": [
    "{\"name\":\"search_docs\",\"description\":\"Search product documentation\"}"
  ],
  "requests_per_month": 10000,
  "model": "claude-sonnet"
}

Quickstart

Run directly from npm

No global install is required. The package supports Node.js 18 or newer and starts with the stdio transport by default.

Open your client's config file

  • Claude Desktop ~/Library/Application Support/Claude/claude_desktop_config.json

    Windows: %APPDATA%\Claude\claude_desktop_config.json. In the app: Settings → Developer → Edit Config.

  • Cursor ~/.cursor/mcp.json

    Or .cursor/mcp.json inside a single project.

  • Windsurf ~/.codeium/windsurf/mcp_config.json

    Cascade panel → MCP icon → edit the raw config.

Paste this entry

All three clients accept the same object. If the file already has an mcpServers block, add just the "ai-cost-analyzer" entry inside it.

mcpServers entry
{
  "mcpServers": {
    "ai-cost-analyzer": {
      "command": "npx",
      "args": ["-y", "ai-cost-analyzer"]
    }
  }
}

No env block is needed to start: the first 3 tool calls total across this server's tools run without a license.

Using Claude Code instead? One command, no file

shell
$ claude mcp add --transport stdio ai-cost-analyzer -- npx -y ai-cost-analyzer

Check it registered with claude mcp list. Add a key later with --env LICENSE_KEY=your-key placed before --transport.

Restart the client, then confirm it loaded

  • Claude Desktop: quit and reopen the app, then look for AI Cost Analyzer in the tools/plugin menu.
  • Cursor: Settings → Customize → MCP; the server should list its tools.
  • Windsurf: reload Cascade; the server appears under the MCP panel.
  • Claude Code: run claude mcp list and look for ✔ Connected.

Running npx -y ai-cost-analyzer in a terminal looks frozen — that is correct. It is a stdio server: it waits silently for an MCP client on stdin and never returns a prompt. Press Ctrl+C to exit. Use the config above rather than the bare command; your client starts the process for you.

Add your license key when you buy

A key arrives on screen right after checkout. Add it as an environment variable in the same entry:

mcpServers entry with license
{
  "mcpServers": {
    "ai-cost-analyzer": {
      "command": "npx",
      "args": ["-y", "ai-cost-analyzer"],
      "env": {
        "LICENSE_KEY": "paste-your-key-here"
      }
    }
  }
}

Keys are verified offline against a public key compiled into the package — no account, no network check, no usage reporting. Lost the key? Recover it here. More detail on the FAQ.

Scope & limitations

Know what the output means

The server is an estimator and text-analysis utility, not a provider billing system or an optimization runtime.

No account or billing ingestion

It does not connect to Anthropic, OpenAI, or Google accounts, collect live traffic, read invoices, or import provider exports. You supply each usage record to analyze.

Fixed pricing snapshot

Rates are bundled in the package and labeled March 2026. They cover Claude Opus, Sonnet, and Haiku; GPT-4o and GPT-4o Mini; and Gemini 2.0 Flash. The server does not fetch live provider pricing.

Heuristic estimates

Waste and savings projections use assumptions in the package. Prompt token counts use an approximate four characters per token, and model recommendations use rule-based task classification—not measured benchmarks.

Recommendations are not changes

The server does not enable caching, route production requests, change model settings, edit source files, or deploy prompts. Review returned prompt text and projections before applying them yourself.

Start with your own records

Use three calls before choosing a plan.

Add the package to an MCP client without a license key, then pass a small, representative usage sample to the analyzer.