MCP Costs & Budget API

Track per-server spending, set monthly budgets, and automatically block requests when the budget is exceeded. Each tool call records a cost, and the proxy aggregates totals monthly with a per-tool breakdown.

Base URL

https://api.hookwatch.dev/v1/mcp/servers/:id/costs

How It Works

  1. Every tool call proxied through an MCP server records a cost (default: default_cost_cents from the server configuration, typically 1 cent).
  2. Costs are aggregated monthly per server.
  3. Before each tool call, the proxy checks the current month's spend against the configured budget.
  4. When the budget is exceeded, the proxy returns 429 Too Many Requests with a JSON-RPC error.
  5. When spending crosses the alert threshold, a notification is sent via your configured alert channels.

The Monthly Cost Summary Object

Json

Properties

FieldTypeDescription
total_centsintTotal cost in cents for the requested month
budget_centsintConfigured monthly budget in cents. 0 if no budget is set.
usage_percentfloatPercentage of budget used. 0 if no budget is configured.
tool_breakdownarrayPer-tool cost breakdown, sorted by total cost descending
tool_breakdown[].tool_namestringName of the tool
tool_breakdown[].total_centsintTotal cost in cents for this tool during the month
tool_breakdown[].call_countintNumber of times this tool was called during the month

Get Cost Summary

Retrieve the monthly cost summary for a specific MCP server. If no query parameters are provided, the current month is returned.

GET /v1/mcp/servers/:id/costs

Both query parameters are optional and default to the current date.

Path Parameters

FieldTypeDescription
idstringThe MCP server UUID

Query Parameters

FieldTypeDescription
yearintYear to query (defaults to current year)
monthintMonth to query, 1–12 (defaults to current month)

Example

curl

Response

Json

Budget Configuration

Budget settings are configured via the rate_limit_config.cost field on the MCP server object. Update it using the Servers API.

Cost Configuration Object

Json

Properties

FieldTypeRequiredDescription
enabledbooleanYesWhether cost tracking and budget enforcement are enabled
monthly_budget_centsintYesMaximum monthly spend in cents. When exceeded, the proxy returns 429 Too Many Requests.
alert_threshold_percentfloatNoPercentage of budget at which an alert notification is triggered (e.g., 80 for 80%)

Example — Set a Monthly Budget

curl

Default behaviour

Cost tracking is disabled by default. You must explicitly set enabled to true and provide a monthly_budget_cents value to activate budget enforcement.

Budget Exceeded Behaviour

When a tool call would push the monthly spend over the configured budget, the proxy rejects the request with a 429 Too Many Requests HTTP status and a JSON-RPC error body:

Json

Budget is checked before execution

The budget check occurs before the tool call is forwarded to the upstream server. If the budget has already been exceeded, the call is never made.

Error Codes

StatusErrorDescription
401UnauthorizedInvalid or missing access token
404Not FoundMCP server not found
429Too Many RequestsMonthly budget exceeded — tool call blocked
500Internal ErrorUnexpected server error while retrieving cost data

Related