Skip to main content
Glama

mcp-cost-guard 🛡️

CI License: MIT Python 3.9+ PRs Welcome

Zero-dependency CLI and Model Context Protocol (MCP) server for auditing LLM token costs, enforcing CI/CD prompt budgets, compressing context windows, and scrubbing leaked API keys before sending requests to Claude, OpenAI, or Gemini.

Features

  • Instant Cost & Token Estimation: Supports claude-opus-4, claude-sonnet-4, claude-3-5-haiku, gpt-4o, and gemini-2.5-pro.

  • CI/CD Budget Gatekeeper: Fail builds automatically (--max-budget 0.05) when oversized context files or system prompts exceed budget thresholds.

  • Credential & Secret Scanner: Detects leaked Anthropic (sk-ant-...), OpenAI, GitHub, AWS, and private keys before prompts leave your machine.

  • Native MCP Server: Plugs directly into Claude Code and Claude Desktop over stdio with zero third-party dependencies.

Related MCP server: promptopt

Quick Start

git clone https://github.com/Git-AnshGrover/mcp-cost-guard.git
cd mcp-cost-guard
pip install -e .

CLI Usage

# Audit a prompt file against Claude Sonnet 4
mcp-cost-guard --file system_prompt.md --model claude-sonnet-4

# Enforce a strict USD budget and secret scan in CI/CD
mcp-cost-guard --file context.txt --max-budget 0.10 --fail-on-secrets --json

# List all supported models and pricing per 1M tokens
mcp-cost-guard --list-models

Claude Code / Claude Desktop MCP Configuration

Add the following to your claude_desktop_config.json or .mcp.json:

{
  "mcpServers": {
    "cost-guard": {
      "command": "mcp-cost-guard",
      "args": ["--mcp-stdio"]
    }
  }
}

Contributing

We actively welcome first-time and experienced open-source contributors! Check our open Good First Issues and read CONTRIBUTING.md to get started in under 5 minutes.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Local CLI and MCP server that redacts secrets from logs, files, and diffs before sending them to AI agents, with stable placeholders and token-budgeted truncation.
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables local, offline prompt compression, smart asking when needed, and routing to the cheapest capable model to save tokens and costs for terminal AI agents.
      1
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Local security layer for coding agents: keeps secret values out of what Claude Code, Codex CLI, Cursor and OpenCode send to their model, and checks untrusted text for prompt injection. MIT, runs on your machine, no account.
      4
      5
      MIT