Skip to main content
Glama

Scaffold the cost-governor-kit spend-safety pattern

scaffold_cost_governor
Read-only

Generates install guidance, starter snippets, and live examples for adding advisory pre-call spend checks, cache-aware pricing, and successful-call usage counting to apps that call paid AI APIs.

Instructions

cost-governor-kit is a RUNTIME LIBRARY your app installs and calls at the moment it's about to make an AI API call -- it is not something this MCP server can 'check' on demand the way it checks a document's citations. Its advisory check-then-commit piece (withReserveConfirm) needs a live UsageLedger backed by YOUR database and an async callback making the real call, neither of which exist as content to hand this tool. Call this to get all three pieces explained (estimated pre-call spend check, cache-aware pricing math, advisory successful-call usage counting), an install step, a copy-pasteable starter snippet, and (optionally) a live worked example: real checkPreCallCeiling calls (one allowed, one blocked), a real withReserveConfirm run against an in-memory demo ledger (one call under the limit, one over, one whose commit fails after a successful call), and a real estimateCostUsd comparison of the default 0.1x cache-read rate against a caller-supplied cacheReadPerMillion override. Use this when you're building or reviewing anything that calls a paid AI API and want a pre-call spend estimate plus usage counting that skips a call that threw -- NOT a strict concurrent limit and not proof a timed-out call was never billed by the provider (see concurrency_and_recovery in the output, and use withCapacityReservation instead if you need a real reservation).

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "scaffold_cost_governor"
  }
}

Input Schema

NameRequiredDescriptionDefault
includeWorkedExampleNoAlso run live examples against the real checkPreCallCeiling/withReserveConfirm, not just show a snippet.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true and openWorldHint=false, but the description adds real context: it clarifies that the advisory check needs a live UsageLedger backed by the caller's database and an async callback that this tool cannot supply, and that the worked example runs against an in-memory demo ledger rather than production state. It also discloses the known limitations (no strict concurrency limit, no proof about timed-out calls) and points to a concurrency_and_recovery section in the output. That is meaningful disclosure beyond the annotation set.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The content is valuable but delivered as one dense run-on paragraph with em-dash chains and nested parentheticals. The operative instruction ('Call this to get...') is buried in the middle, and the opening is a defensive digression about what the tool is not. Sizing is excessive for a single-optional-boolean tool and would benefit from a bare purpose sentence first, details second.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no output schema, the description carries the burden of describing returns, and it does so reasonably: it enumerates the three explained pieces, the install step and snippet, and the shape of the optional worked example, plus a pointer to a concurrency_and_recovery section. An agent knows what it will receive and what it will not, which is sufficient for a scaffolding tool with one optional flag.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% for the single parameter, so the schema baseline already documents it. The description nonetheless adds value by spelling out what the worked example contains when enabled — real checkPreCallCeiling calls (one allowed, one blocked), a withReserveConfirm run with three outcomes, and an estimateCostUsd cache-rate comparison — which tells an agent far more than the schema's one-line default explanation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a concrete deliverable set: explanation of the three cost-governor pieces, an install step, a copy-pasteable snippet, and an optional live worked example. It also draws a clear boundary against a sibling-style capability, contrasting it with withCapacityReservation and with an on-demand 'check' tool. The only drag is that the first two sentences are spent explaining what the tool is not, so the actual purpose arrives slightly late.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It names the triggering situation explicitly ('when you're building or reviewing anything that calls a paid AI API'), states the exclusions ('NOT a strict concurrent limit and not proof a timed-out call was never billed'), and routes to an alternative ('use withCapacityReservation instead if you need a real reservation'). Nothing about when-to-use is left to inference.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.