Anthropic Billing MCP Server

Anthropic Billing MCP Server

Enables retrieval of Anthropic billing and cost report data, with time-based filtering, grouping, and daily cost summaries.

Category
访问服务器

README

Anthropic Billing MCP Server

An MCP (Model Context Protocol) server for retrieving Anthropic billing and cost report data.

Features

  • Retrieve detailed cost reports from Anthropic's billing API
  • Support for time-based filtering and grouping
  • Daily cost summaries with USD conversion
  • Support for beta API features
  • Pagination support for large datasets
  • Type-safe with Zod validation

Installation

Option 1: Using claude mcp add (Recommended)

# Add the MCP server from GitHub
claude mcp add anthropic-billing https://github.com/your-username/anthropic-billing-mcp

# Set your API key
claude mcp env anthropic-billing ANTHROPIC_API_KEY=your_api_key_here

Option 2: Manual Installation

git clone https://github.com/your-username/anthropic-billing-mcp
cd anthropic-billing-mcp
npm install
npm run build

Setup

  1. Get your Anthropic Admin API key from https://platform.claude.com/settings/admin-keys
    • Note: Regular API keys from console.anthropic.com will not work for billing endpoints
    • You need an Admin API key with billing access permissions
  2. If using claude mcp add, set the environment variable:
    claude mcp env anthropic-billing ANTHROPIC_API_KEY=your_api_key_here
    
  3. If installing manually, set the environment variable:
    export ANTHROPIC_API_KEY=your_api_key_here
    

Usage

With claude mcp add

After installation, the server will be automatically configured and available in Claude Desktop.

Manual Configuration

Add to your MCP configuration (e.g., in Claude Desktop config):

{
  "mcpServers": {
    "anthropic-billing": {
      "command": "node",
      "args": ["/path/to/anthropic-billing-mcp/dist/index.js"],
      "env": {
        "ANTHROPIC_API_KEY": "your_api_key_here"
      }
    }
  }
}

Available Tools

get_cost_report

Retrieve raw cost report data from Anthropic's API.

Parameters:

  • starting_at (required): RFC 3339 timestamp for start of time range
  • ending_at (optional): RFC 3339 timestamp for end of time range
  • bucket_width (optional): Time granularity ("1d" only)
  • group_by (optional): Array of grouping options ["workspace_id", "description"]
  • limit (optional): Maximum number of time buckets to return
  • page (optional): Page token for pagination
  • beta_headers (optional): Array of beta feature headers

Example:

{
  "starting_at": "2024-01-01T00:00:00Z",
  "ending_at": "2024-01-31T23:59:59Z",
  "group_by": ["description"],
  "beta_headers": ["fast-mode-2026-02-01"]
}

get_daily_costs_summary

Get a formatted summary of daily costs with USD conversion.

Parameters:

  • start_date (required): Start date in YYYY-MM-DD format
  • end_date (optional): End date in YYYY-MM-DD format (defaults to today)
  • group_by_workspace (optional): Whether to group by workspace (default: false)
  • group_by_description (optional): Whether to group by description (default: false)
  • beta_headers (optional): Array of beta feature headers

Example:

{
  "start_date": "2024-01-01",
  "end_date": "2024-01-31",
  "group_by_description": true
}

Demo: Real-World Usage for Budget Management

This MCP server enables powerful budget management and cost analysis workflows. Here's a real-world example of using it to create a comprehensive burn down analysis.

Scenario: Trading Profit vs API Costs

A trader made $1,000 profit in March 2026 and wanted to track their Anthropic API costs against this budget to ensure profitable AI-assisted trading decisions.

Live Cost Analysis (March 7, 2026)

Using the MCP server's get_cost_report tool, we retrieved actual spending data:

📊 Executive Summary
- Trading Profit This Month: $1,000.00
- Current API Costs: $91.05
- Remaining Budget: $908.95
- Days Elapsed: 7 of 31 (22.6%)
- Budget Utilization: 9.1%

📈 Key Performance Metrics
- Daily Average Cost: $13.01 ($91.05 ÷ 7 days)
- Projected Monthly Cost: $403.31 (at current rate)
- Target Daily Budget: $32.26 (1000 ÷ 31 days)
- API ROI: 1,098% ($1000 profit vs $91.05 cost)

Budget Burn Rate Visualization

Week 1  [███████████████████████████▓▓▓▓▓] $91.05 (28% of weekly target)
Week 2  [█████████████████████████████████] $91.05 (projected)
Week 3  [█████████████████████████████████] $91.05 (projected)
Week 4  [█████████████████████████████████] $91.05 (projected)
Week 5  [█████████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] $39.11 (projected)

Risk Assessment & Strategic Insights

🟢 Current Status: LOW-MODERATE Risk

  • Tracking 59% below daily budget target
  • Cost efficiency: 9.1¢ per dollar of trading profit
  • Room to scale usage 2.5x while staying in budget
  • Outstanding ROI demonstrates profitable AI integration

MCP Integration Benefits

1. Real-Time Budget Monitoring

# Get current month costs instantly
get_daily_costs_summary start_date=2026-03-01

2. Automated Burn Rate Calculations

The MCP server enables programmatic cost analysis without manual API calls:

  • Daily average spending calculations
  • Projected monthly costs based on current usage
  • Budget variance tracking
  • ROI analysis against business metrics

3. Multi-Scenario Planning

# Scenario 1: Current pace → $403.31 monthly (40.3% of budget)
# Scenario 2: 25% increase → $504.14 monthly (50.4% of budget)
# Scenario 3: 50% increase → $604.97 monthly (60.5% of budget)

4. Integration with Business Logic

The MCP server allows seamless integration with:

  • Trading algorithms that factor in API costs
  • Automated budget alerts and thresholds
  • Cost-per-decision optimization
  • Dynamic usage scaling based on profitability

Sample Budget Management Workflow

# Pseudo-code showing typical workflow
def optimize_trading_strategy():
    # Get real-time costs via MCP
    current_costs = get_daily_costs_summary()
    daily_avg = current_costs.total / days_elapsed

    # Calculate remaining budget runway
    remaining_budget = trading_profit - current_costs.total
    safe_daily_spend = remaining_budget / days_remaining

    # Adjust API usage based on cost efficiency
    if daily_avg < safe_daily_spend * 0.8:
        return "SCALE_UP"  # Opportunity to use more AI
    elif daily_avg > safe_daily_spend * 1.2:
        return "SCALE_DOWN"  # Risk of budget overrun
    else:
        return "MAINTAIN"  # Optimal pace

This real-world example demonstrates how the MCP server transforms basic billing data into actionable business intelligence, enabling data-driven decisions about AI investment and usage optimization.

📋 Full Analysis Available: See examples/trading-budget-burndown.md for the complete burn down analysis with weekly projections, risk assessments, and KPI tracking.

API Response Structure

Cost Items

Each cost item includes:

  • amount: Cost in cents as decimal string
  • currency: Currency code (always "USD")
  • description: Description of the cost item
  • model: Model name used
  • cost_type: Type of cost ("tokens", "web_search", "code_execution")
  • token_type: Token type for token costs
  • service_tier: Service tier ("standard", "batch")
  • context_window: Input context window used
  • workspace_id: Associated workspace ID
  • inference_geo: Inference geography used
  • speed: Speed tier (with beta header)

Daily Summary Format

{
  "summary": [
    {
      "date": "2024-01-01",
      "total_cost_cents": 1234,
      "total_cost_usd": "12.34",
      "items": [...]
    }
  ],
  "total_cost_cents": 50000,
  "total_cost_usd": "500.00",
  "period": {
    "start": "2024-01-01",
    "end": "2024-01-31"
  },
  "has_more": false,
  "next_page": null
}

Development

Build

npm run build

Run in Development

npm run dev

Test

npm test

Environment Variables

Error Handling

The server includes comprehensive error handling for:

  • Missing API keys
  • Invalid API responses
  • Network errors
  • Validation errors
  • API rate limits

All errors are returned with descriptive messages to help with debugging.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选
mcp-server-qdrant

mcp-server-qdrant

这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。

官方
精选
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选