Skip to main content
Glama
gralliry

opencode-balance-mcp

by gralliry

opencode-balance-mcp

あなたのOpenCodeサブスクリプションデータ(GoクォータとZenプリペイド残高)をツールとして公開するMCPサーバー(stdio)です。MCP対応クライアント(pi、Claude Desktop、opencode、Cursorなど)から利用できます。

  • query_go_usage — OpenCode Goクォータ(ローリング5時間、週次、月次の各ウィンドウ)。/workspace/{id}/goページを取得し、埋め込まれたRSCペイロードを解析します。

  • query_zen_balance — OpenCode Zenプリペイド残高。ワークスペースのダッシュボードページを取得し、埋め込まれたSolidJS SSRスカラー値を解析します。

リクエストは一時的な障害(5xx、429 — Retry-Afterを尊重)に対してバックオフ付きで再試行され、15秒でタイムアウトします。

依存関係ゼロ。Node.js ≥ 18。

インストールと実行

npx -y opencode-balance-mcp \
  --workspace-id wrk_xxx \
  --auth-cookie "Fe26.2**..."

Related MCP server: kitepass-mcp

認証情報

サーバーにはOpenCodeのワークスペースID認証Cookieが必要です。優先順位は以下のとおりです:

  1. CLI引数: --workspace-id / --auth-cookie

  2. 環境変数: OPENCODE_GO_WORKSPACE_ID / OPENCODE_GO_AUTH_COOKIE

⚠️ authCookieはOpenCodeのセッションCookieです(Fe26.2**で始まります)。有効期限があります — https://opencode.ai にログイン → DevTools → Application → Cookies → auth で更新してください。

ツール

query_go_usage

引数なし。3つのウィンドウすべてのGoサブスクリプションクォータを返します:

{
  "timestamp": "...",
  "workspaceId": "wrk_...",
  "rolling":  { "status": "ok", "usagePercent": 1, "limitUsd": 12, "estSpentUsdLow": 0.12, "estSpentUsdHigh": 0.24, "resetsInSeconds": 8660, "resetsIn": "2h 24m" },
  "weekly":   { "status": "ok", "usagePercent": 1, "limitUsd": 30, "...": "..." },
  "monthly":  { "status": "ok", "usagePercent": 0, "limitUsd": 60, "...": "..." }
}
  • usagePercentは整数です — 0%はウィンドウ上限の1%未満しか使用していないことを意味します(5時間 $12 / 週次 $30 / 月次 $60)。opencode.ai/docs/goを参照してください。

  • estSpentUsdLow/Highは現在の使用率に対する推定支出額の範囲を示します。

  • resetsInresetsInSecondsから算出した人間にわかりやすいカウントダウンです。

query_zen_balance

引数なし。ワークスペースのダッシュボードページを読み取り、Zen残高(SolidJS SSRハイドレーションデータ)を解析します:

{
  "timestamp": "...",
  "workspaceId": "wrk_...",
  "plan": "pay-as-you-go",
  "balanceRaw": 0,
  "balanceUsd": 0,
  "balanceFormatted": "$0.00",
  "autoReload": { "triggerUsd": 5, "triggerMinUsd": 5, "reloadUsd": 20, "reloadMinUsd": 10 },
  "reloadAmount": 20,
  "reloadTrigger": 5
}
  • balanceRaw1e-8 USD単位の整数です(ダッシュボードクライアントと同じ単位:formatBalance = amount / 1e8)。負の値 = プリペイド残高、正の値 = 未払い額。

  • balanceUsd / balanceFormattedはそこから導出されます。符号はラベルに(credit) / (owed)として表示されます。

  • autoReloadはZenの自動チャージを反映します:残高がtriggerUsdを下回ると、reloadUsdを追加します。

公式のZen残高APIは存在しないため、サーバーはGoクォータと同じ方法でダッシュボードをスクレイピングします。パーサーはsrc/parse.mjsにあり、ページ構造が変更された場合は更新が必要になる可能性があります。

MCPクライアントでの設定

opencode(~/.config/opencode/opencode.json

{
  "mcp": {
    "opencode-balance": {
      "type": "local",
      "command": ["npx", "-y", "opencode-balance-mcp"],
      "environment": {
        "OPENCODE_GO_WORKSPACE_ID": "wrk_xxx",
        "OPENCODE_GO_AUTH_COOKIE": "Fe26.2**..."
      }
    }
  }
}

標準MCP(stdio)— 任意のクライアント

{
  "mcpServers": {
    "opencode-balance": {
      "command": "npx",
      "args": ["-y", "opencode-balance-mcp"],
      "env": {
        "OPENCODE_GO_WORKSPACE_ID": "wrk_xxx",
        "OPENCODE_GO_AUTH_COOKIE": "Fe26.2**..."
      }
    }
  }
}

Claude Code(プロジェクトルートの.mcp.json

{
  "mcpServers": {
    "opencode-balance": {
      "command": "npx",
      "args": ["-y", "opencode-balance-mcp"],
      "env": {
        "OPENCODE_GO_WORKSPACE_ID": "wrk_xxx",
        "OPENCODE_GO_AUTH_COOKIE": "Fe26.2**..."
      }
    }
  }
}

またはCLI経由:claude mcp add opencode-balance -e OPENCODE_GO_WORKSPACE_ID=wrk_xxx -e OPENCODE_GO_AUTH_COOKIE="Fe26.2**..." -- npx -y opencode-balance-mcp

Codex(~/.codex/config.toml

[mcp_servers.opencode-balance]
command = "npx"
args = ["-y", "opencode-balance-mcp"]
enabled = true

[mcp_servers.opencode-balance.env]
OPENCODE_GO_WORKSPACE_ID = "wrk_xxx"
OPENCODE_GO_AUTH_COOKIE = "Fe26.2**..."

pi(~/.pi/agent/mcp.json

{
  "mcpServers": {
    "opencode-balance": {
      "command": "npx",
      "args": ["-y", "opencode-balance-mcp"],
      "env": {
        "OPENCODE_GO_WORKSPACE_ID": "wrk_xxx",
        "OPENCODE_GO_AUTH_COOKIE": "Fe26.2**..."
      }
    }
  }
}

開発

npm start      # run the server directly
npm test       # unit tests (parser, zen formatting, HTTP retry policy) + a protocol smoke test

プロトコルのスモークテスト(test/test.mjs)はstdio経由でサーバーを起動し、initializetools/listtools/call、およびtools/callのエラーハンドリングを検証します。認証情報がない場合、2つのツール呼び出しはisError結果で失敗することが期待されます。

アーキテクチャ

  • src/index.mjs — MCP stdioプロトコル、認証情報(CLI/環境変数)、ページ取得の接着層

  • src/http.mjs — ネットワークポリシー:タイムアウト、バックオフ付き再試行、429/Retry-After処理

  • src/parse.mjs — 純粋な解析/フォーマットヘルパー(I/Oなし、直接ユニットテスト対象)

公開

npm publish

ライセンス

MIT

Available Tools

2 tools
query_go_usageA

Query OpenCode Go subscription quota: rolling (5h) / weekly / monthly usage percent, estimated USD spent and reset countdown. No arguments needed; credentials are provided at startup via CLI args (--workspace-id / --auth-cookie) or env vars.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A4.2/5.0
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It adds value by disclosing that credentials are pre-configured via CLI args or env vars, which prevents unnecessary auth handling. However, it does not mention potential error conditions, whether the action is read-only (though implied by 'query'), or any rate limits. It neither contradicts nor fully discloses behavior.

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

Conciseness5/5

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

Two sentences with no wasted words. The first sentence states purpose and outputs; the second clarifies argument and credential requirements. Information is front-loaded and every word serves a purpose.

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?

For a zero-parameter query tool with no output schema, the description covers the essential details: what it returns and that no arguments are needed. It does not specify the exact format of the reset countdown (e.g., seconds, minutes), which could cause minor ambiguity, but overall the tool is simple enough that the description is nearly complete.

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?

The tool has zero parameters, so baseline is 4. The description reinforces this by explicitly stating 'No arguments needed,' which adds clarity beyond the empty schema. Since there are no parameters to document, this is fully adequate.

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

Purpose5/5

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

The description clearly states the tool queries OpenCode Go subscription quota and enumerates specific outputs (usage percent, estimated USD spent, reset countdown). It uses a specific verb 'query' and resource 'Go subscription quota,' making it distinguishable from the sibling tool query_zen_balance.

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

Usage Guidelines4/5

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

It explicitly states 'No arguments needed' and explains how credentials are provided, which tells the agent it doesn't need to pass authentication. It does not explicitly name the sibling or contrast usage, but the purpose is clear enough that the agent can infer when to use it. Lacks an explicit 'when not to use' but provides sufficient context.

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

query_zen_balanceA

Query OpenCode Zen prepaid balance (pay-as-you-go): balance in 1e-8 USD units (negative = credit), formatted USD, and auto-reload settings. No arguments needed; credentials are provided at startup via CLI args (--workspace-id / --auth-cookie) or env vars.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A4.5/5.0
Behavior4/5

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

With no annotations, the description carries the full burden and discloses useful behavioral details: balance units in 1e-8 USD, negative values meaning credit, formatted USD output, and auto-reload settings. It also clarifies credential sourcing, which is important operational behavior.

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

Conciseness5/5

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

Two efficiently written sentences convey the purpose, output, required arguments, and credential mechanism with no filler. Every clause earns its place and the core subject is front-loaded.

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

Completeness5/5

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

For a zero-parameter read-only query tool with no output schema, the description is complete: it names the resource, details the returned data, explains the unit semantics, states no arguments are needed, and tells where credentials come from. Nothing necessary for correct invocation is missing.

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?

There are zero parameters and schema coverage is 100%, so the baseline is 4. The description reinforces that no arguments are needed and goes further by explaining how authentication is already handled, which adds meaning beyond the empty schema.

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

Purpose5/5

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

The description names a specific verb (Query), a specific resource (OpenCode Zen prepaid balance), and the scope (pay-as-you-go balance). It lists the exact data returned, which distinguishes it from the sibling query_go_usage without needing to compare schemas.

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

Usage Guidelines4/5

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

The description clearly states that no arguments are needed and explains how credentials are supplied, which is essential contextual guidance for invoking the tool. It does not explicitly name the sibling as an alternative, but the resource and data scope make the intended use clear.

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

TDQS

A4.4/5.0
Disambiguation5/5

The two tools query distinct resources: one for Go subscription quota and one for Zen prepaid balance. Their descriptions clearly differentiate the data returned (usage percentages vs. balance in USD units), making confusion unlikely.

Naming Consistency5/5

Both tool names follow the exact same pattern: 'query_' prefix followed by the resource type ('go_usage' and 'zen_balance'). This is fully consistent and predictable.

Tool Count4/5

With only two tools, the surface is minimal, but the server's scope is narrowly defined as querying two distinct balance types. The count feels appropriate given the focused purpose, though slightly thin if broadenability was expected.

Completeness4/5

The server covers the two core balance query operations for its domain. Missing a combined query or historical data are minor gaps that agents can work around, but the essential read operations are present.

Maintenance

ActivityMaintained
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gralliry/opencode-balance-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server