Featured

Deploy OpenClaw in 60 seconds — 20% off logoDeploy OpenClaw in 60 seconds — 20% off

Launch OpenClaw on Hostinger in about 60 seconds and keep your agent live 24/7. Our referral link gives you 20% off, no coupon code needed.

Launch on Hostinger
Run your Hermes agent on Hostinger, fully managed logoRun your Hermes agent on Hostinger, fully managed

Launch Hermes on Hostinger in one click, fully managed, no VPS knowledge needed. Use code ZACAARON10 for 10% off.

Launch on Hostinger
Crawl and scrape any site into clean data, 10% off logoCrawl and scrape any site into clean data, 10% off

Firecrawl crawls and scrapes any site into clean markdown for your agent. Get 1,000 free credits, and new users get 10% off their first purchase.

Try Firecrawl free
6,000+ web scrapers for your AI agent, start free logo6,000+ web scrapers for your AI agent, start free

Apify gives your agent live web data: 6,000+ prebuilt scrapers and actors, MCP-ready. Sign up free with $5 in usage credits.

Try Apify free
One API to scrape, enrich, and extract the internet. logoOne API to scrape, enrich, and extract the internet.

Context.dev gives your agents a single API to scrape, enrich, and extract live web data — no proxies, no parsers, no maintenance.

Start building free
SetupClaw: done-for-you OpenClaw for founders & exec teams logoSetupClaw: done-for-you OpenClaw for founders & exec teams

White-glove OpenClaw for founders and exec teams (4–50+ employees): we install, harden, integrate your tools, and maintain it — secured from day one.

Get it set up for you
SEO data APIs for your agent, $1 free credit logoSEO data APIs for your agent, $1 free credit

DataForSEO gives your agent live access to SERP results, keyword data, backlinks, and on-page SEO data through one API. New accounts get a $1 credit, good for up to 20,000 keyword or backlink lookups.

Try DataForSEO free
Reach 48,000+ AI builders

A flat monthly placement in front of developers actively installing AI tools. No lock-in, cancel anytime.

Advertise here

Works with

Claude CodeClaude DesktopCursorVS CodeClineCodex CLIOpenClaw+ any MCP client

Install to Claude Code

This server doesn't publish a one-line install command. Follow the setup in the source repository.

Summary

Enables AI agents to track LLM costs, enforce budgets, compare models, and estimate expenses through simple tool calls.

README.md

CosTrack MCP — Agent Cost Control Layer

Lightweight MCP server that gives any AI agent or developer instant cost tracking, spend analysis, budget enforcement, and model cost optimization for LLM operations.

What It Does

CosTrack sits between simple price-lookup tools and full observability platforms. It's an MCP-native cost control layer — log costs, get reports, check budgets, compare models — all via tool calls.

Tools

| Tool | Description | |------|-------------| | cost_log | Record a cost event for an LLM call or agent operation | | cost_report | Generate cost summary with breakdowns by model, agent, task | | cost_compare | Compare costs side-by-side for models, agents, or periods | | budget_check | Check spend vs budget with end-of-period projection | | cost_estimate | Estimate cost for planned calls with cheaper alternatives | | pricing_table | Get current pricing data for 17+ supported models |

Supported Models

  • Anthropic: Claude Opus 4, Opus 4.6, Sonnet 4, Sonnet 4.6, Haiku 4
  • OpenAI: GPT-4o, GPT-4o Mini, GPT-4 Turbo, o1, o1-mini
  • Google: Gemini 2.5 Pro, Gemini 2.5 Flash, Gemini 2.0 Flash
  • Meta: Llama 4 Scout, Llama 4 Maverick
  • DeepSeek: DeepSeek V3, DeepSeek R1

Model names are automatically normalized — use aliases like sonnet, gpt-4o, haiku etc.

Quick Start

Connect via Claude Desktop / Claude Code

Add to your MCP server configuration:

{
  "mcpServers": {
    "costrack": {
      "url": "https://costrack-mcp.<your-subdomain>.workers.dev/mcp"
    }
  }
}

Example Usage

Log a cost event: `` cost_log(model: "claude-sonnet-4", input_tokens: 1500, output_tokens: 800, agent_id: "my-agent") → { cost_usd: 0.0165, running_session_total: 1.23 } ``

Check budget: `` budget_check(budget_usd: 100, scope: "all", period: "30d") → { current_spend_usd: 65.0, status: "PROJECTED_OVERAGE", projected_end_of_period_spend_usd: 130.1 } ``

Estimate before calling: `` cost_estimate(model: "claude-opus-4", estimated_input_tokens: 5000, estimated_output_tokens: 2000) → { cost_per_call_usd: 0.225, alternatives: [{ model: "anthropic/claude-sonnet-4", savings_percent: 90.0 }] } ``

Features

  • Model Normalizationsonnet, claude-sonnet-4, anthropic/claude-sonnet-4 all resolve to the same model
  • Idempotency — Pass idempotency_key to prevent duplicate cost logging
  • Hard Limit Signaling — Set hard_limit_usd to get alerts when spend exceeds threshold (fail-safe, not fail-stop)
  • Price Snapshots — Each event stores the price at time of logging; historical costs never change
  • Budget Projection — Predicts end-of-period spend based on daily average
  • Alternative Suggestionscost_estimate recommends cheaper models in same capability tier

Deployment

Prerequisites

  • Node.js 18+
  • Cloudflare account with Workers enabled
  • Wrangler CLI (npm install -g wrangler)

Deploy

# Install dependencies
npm install

# Login to Cloudflare
wrangler login

# Create KV namespace
wrangler kv:namespace create COSTRACK_EVENTS
# Update wrangler.toml with the returned namespace ID

# Deploy
wrangler deploy

Local Development

npm run dev

Type Check

npm run build

Architecture

  • Runtime: Cloudflare Workers (TypeScript)
  • Storage: Hybrid — Durable Objects (real-time aggregations) + KV (raw event audit trail)
  • Protocol: MCP (Model Context Protocol) over Streamable HTTP
  • Pricing: Built-in table, single-file source of truth (src/pricing/pricing-table.ts)

Configuration

Edit wrangler.toml to set:

  • COSTRACK_EVENTS KV namespace ID (Rich fills in after wrangler kv:namespace create)
  • Production environment variables

Project Structure

costrack-mcp/
├── src/
│   ├── tools/           # 6 tool implementations
│   ├── pricing/         # Pricing data + model aliases
│   ├── normalize/       # Model name normalization
│   ├── storage/         # Durable Object + KV + DO client
│   ├── utils/           # Cost calculator, tier check
│   ├── types/           # Shared TypeScript types
│   ├── index.ts         # MCP server core
│   └── worker.ts        # Cloudflare Workers entry point
├── wrangler.toml        # CF Workers config
├── package.json
├── tsconfig.json
└── README.md

License

MIT

See related servers & alternatives →

Related MCP servers

Browse all →

Related guides

Hand-picked reading to help you choose and use AI & ML servers.