grok-budget-mcp
It lets an MCP client query your own Grok weekly budget and optional monthly credits using the local Grok CLI login session.
Call
get_budgetto get overall weekly pool used/remaining percent, per-product usage rows such asGrokBuild, reset time, and Extra Usage cap/used.Call
get_monthly_creditsfor secondary monthly credit units and billing period; this does not gate the weekly Grok Build limit.Use the results before long or expensive work to check whether remaining budget is low and ask the user before continuing.
Both tools take no input, are read-only/idempotent, re-read
auth.json, and make exactly one HTTPS request per call; avoid polling in a loop.Get structured tool errors or warnings for missing/expired login, rate limits, endpoint shape changes, and partial data.
It does not refresh tokens, write auth files, manage top-ups, or access the Management API/prepaid balance.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@grok-budget-mcp How much of my weekly Grok Build usage is left, and when does it reset?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
grok-budget-mcp
A small, local MCP server (stdio) that lets a Grok Build CLI agent ask
"how much of my SuperGrok / Grok Build weekly usage pool is left, and when does it reset?" —
the same figure the interactive TUI shows under /usage (alias /cost).
Part of Hobelbank, a set of projects on building software in the age of AI.
Today an agent has no first-class way to get that number: /usage is TUI-only, grok -p "/usage" is
treated as a prompt, and the ACP x.ai/billing method is not exposed over grok agent stdio.
This server reads your existing grok login session and returns the figures as JSON.
Unofficial, undocumented endpoint. This server calls
https://cli-chat-proxy.grok.com/v1/billing?format=credits, the private route the Grok Build CLI
itself uses for /usage. It is not a public xAI API, has no stability guarantee, and xAI can change
or remove it at any time. When the shape changes, this server fails loudly (error or warning + null
fields) instead of guessing numbers.
Terms of service / risk. Calling private product endpoints may conflict with xAI's terms. Use it only as a personal, local helper with your own account — not as a hosted or shared service. You are responsible for how you use it. This project is not affiliated with or endorsed by xAI.
What it does
Tool | Purpose |
| Primary. Weekly pool usage ( |
| Secondary / optional. Monthly credit units from |
Both tools take no input. Each call re-reads auth.json and makes exactly one HTTPS request
(15 s timeout, no retries, no caching).
get_budget output
All fields are always present; anything the endpoint did not return is null and explained in warning.
Field | Meaning |
| Overall-pool used percent ( |
|
|
| Every |
| e.g. |
|
|
|
|
| always |
| ISO-8601 time of the fetch |
| Human note when data is partial or the shape looks different; |
Example (illustrative values):
{
"used_percent": 42.5,
"remaining_percent": 57.5,
"products": [
{ "product": "GrokBuild", "used_percent": 61.25, "remaining_percent": 38.75 },
{ "product": "GrokChat", "used_percent": 7, "remaining_percent": 93 }
],
"period_type": "USAGE_PERIOD_TYPE_WEEKLY",
"period_start": "2026-09-28T01:53:09.930537+00:00",
"period_end": "2026-10-05T01:53:09.930537+00:00",
"on_demand_cap": 2500,
"on_demand_used": 120,
"source": "cli-chat-proxy:/v1/billing?format=credits",
"fetched_at": "2026-10-01T19:00:00.000Z",
"warning": null
}Mapping rules: numbers are never invented. If creditUsagePercent is omitted but a complete current
period is present, it is reported as 0 (proto3 JSON omits zero values) with a warning. A product row
without usagePercent is reported with null percents and a warning. A response with only monthly fields
is not relabelled as weekly. If neither usage nor a period can be parsed, the tool returns an error.
Errors
Errors are returned as MCP tool errors (isError: true) with a code and a readable message:
Situation | Message |
|
|
No |
|
|
|
HTTP 401 / 403 |
|
HTTP 429 |
|
HTTP 5xx / other / network / timeout |
|
200 but unparseable / no usage and no period |
|
Anything else (unexpected internal error) |
|
Related MCP server: agent-activity
Token handling (read-only)
Reads
$GROK_HOME/auth.jsonifGROK_HOMEis set, else~/.grok/auth.json— the file written bygrok login.Picks the OIDC /
grok loginentry (preferring issuerhttps://auth.x.ai, ignoring bare API-key entries) and uses itskeyfield as the Bearer token;expires_atis checked locally.Never refreshes the token, never writes
auth.json, never calls an auth endpoint. If the session is expired or rejected, it tells you to rungrok login(or simply use the Grok CLI, which refreshes its own session).Never logs, prints or returns the token, the Authorization header, or the raw upstream body.
No secrets go into MCP config
env.
Request sent (once per tool call):
GET https://cli-chat-proxy.grok.com/v1/billing?format=credits
Authorization: Bearer <key from auth.json>
X-XAI-Token-Auth: xai-grok-cli
Accept: application/jsonThe base URL can be overridden with GROK_CLI_CHAT_PROXY_BASE_URL (same variable the Grok CLI honours, e.g.
https://grok-proxy.example.com/v1); the server then calls <base>/billing?format=credits.
Install / build
Requires Node.js 22+.
git clone https://github.com/pihme/grok-budget-mcp.git
cd grok-budget-mcp
npm install # also builds dist/ via the prepare script
npm run build # tsc -> dist/
npm test # unit + stdio smoke tests (mocked fetch, fixture auth files)
npm run smoke # optional: start the server over stdio, list tools, call get_budget once with YOUR sessionOptionally put the grok-budget-mcp binary on your PATH with npm link (or
npm install -g github:pihme/grok-budget-mcp).
Prebuilt alternative: each release has a
grok-budget-mcp-X.Y.Z.tgz (built dist/, no build step); npm install -g ./grok-budget-mcp-X.Y.Z.tgz
puts grok-budget-mcp on your PATH. Versions follow SemVer; nothing is published to npm.
Wiring into Grok Build
Via the CLI (everything after -- is the server command):
grok mcp add grok-budget -- node /path/to/grok-budget-mcp/dist/index.js
# or, after `npm link`:
grok mcp add grok-budget -- grok-budget-mcpOr directly in ~/.grok/config.toml:
[mcp_servers.grok-budget]
command = "node"
args = ["/path/to/grok-budget-mcp/dist/index.js"]
startup_timeout_sec = 15
tool_timeout_sec = 30Then check it with grok mcp doctor grok-budget and /mcps in the TUI. The tools appear as
grok-budget__get_budget and grok-budget__get_monthly_credits. User scope is enough; no env is needed.
See the official Grok Build MCP docs.
A good agent instruction: "Before starting long or expensive work, call grok-budget__get_budget once; if
remaining_percent (or the GrokBuild product's) is low, tell me and ask before continuing."
Not covered
Not the Management API / console prepaid balance, and not per-request
cost_in_usd_ticks— those are different ledgers.No Auto Top Up management, no grok.com scraping, no caching.
Background
Design notes and the research behind this server: SPEC.md. Community prior art that documents the endpoint and the auth.json shape (not endorsements):
SergioComeron/GrokUsageBar,
marcelocantos/claudia docs/grok-usage-billing.md,
robinebers/openusage,
ColumbusLabs/QuotaKit.
Contributing
Issues and ideas are welcome: see Contributing. Website and handbook: pihme.github.io/grok-budget-mcp.
How this project is built
grok-budget-mcp is developed agent-first. AI coding agents write all code, tests, and documentation, and review each other's changes, under human direction: specs, design decisions, and acceptance based on observed behaviour and test results. No human reads the code line by line. This is a deliberate choice. Quality rests on automated tests, CI, and independent agent review.
Evaluate the code against your own requirements before you depend on it. Found a problem? Open an issue.
License
MIT. Third-party software installed with it, and its licenses: THIRD_PARTY_NOTICES.md.
Available Tools
2 toolsget_budgetGrok weekly usage budgetARead-onlyIdempotent
Return current Grok Build / SuperGrok weekly pool usage and reset time (same figure as the TUI /usage). Top-level used_percent/remaining_percent are the overall pool (config.creditUsagePercent); products lists every per-product row (e.g. GrokBuild) so you can pick the relevant one. period_end is the reset time. Data comes from an UNOFFICIAL, undocumented endpoint; null fields plus warning mean partial data. Call it once before expensive work; do not poll in a loop.
Inputs: no named parameters.
get_monthly_creditsGrok monthly credit units (secondary)ARead-onlyIdempotent
SECONDARY / optional: monthly credit units (monthly_limit, used, billing period) from the unofficial billing endpoint without format=credits. This does NOT gate the weekly Grok Build limit; prefer get_budget.
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 2 tools
Both tools retrieve credit/quota data, so there is surface-level overlap, but the descriptions sharply distinguish them: get_budget is the weekly Grok Build pool (the gating figure) while get_monthly_credits is explicitly labeled SECONDARY and non-gating. The explicit 'prefer get_budget' guidance makes misselection unlikely.
Both names use the identical get_<noun> snake_case pattern (get_budget, get_monthly_credits), with the noun reflecting the resource returned. No deviation in convention.
Two tools is on the thin side of the 3-15 ideal, but the server's scope is deliberately narrow (read-only usage/quota reporting), so each tool earns its place. A third tool would likely be redundant rather than additive.
For a usage-monitoring server the surface covers the two meaningful quota views (weekly pool with per-product breakdown, plus monthly credits). A read-only domain has limited lifecycle needs, though historical/trend data is absent as a minor gap.
Maintenance
Related MCP Connectors
A paid remote MCP for CLI tool MCP, built to return verdicts, receipts, usage logs, and audit-ready
LLM cost optimization gateway, repo token-waste auditor & model arbitrage MCP server.
A paid remote MCP for AI agent browser DevTools MCP, built to return verdicts, receipts, usage logs,
Financial data MCP server for Claude, ChatGPT, Cursor and Codex. Real-time stock quotes, financial statements, options flow, SEC filings, insider trades, 13F holdings, macro data and market news from gloom.sh, the open-source Bloomberg Terminal alternative.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceMCP server that reads local OpenClaw session files to provide token usage and cost data without any network calls or authentication.MIT
- AlicenseAqualityBmaintenanceA read-only MCP server that exposes local coding-agent session logs as three tools for introspection of recent work, debugging tool failures, and tracking token usage and estimated cost without parsing log files.3MIT
- AlicenseNot gradedqualityDmaintenanceA local, read-only MCP bridge that lets OpenAI Codex ask your authenticated Grok Build CLI for a second opinion without copying API keys into Codex.MIT
- FlicenseAqualityDmaintenanceMCP server that exposes a single tool to retrieve ChatGPT/Codex quota via the signed-in Codex CLI, reporting rate-limit windows and usage percentages.1-