opencode-balance-mcp
opencode-balance-mcp
OpenCode 구독 데이터를 도구로 노출하는 MCP 서버(stdio)입니다 — Go 할당량과 Zen 선불 잔액을 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와 인증 쿠키가 필요합니다. 우선 순위:
CLI 인자:
--workspace-id/--auth-cookie환경 변수:
OPENCODE_GO_WORKSPACE_ID/OPENCODE_GO_AUTH_COOKIE
⚠️
authCookie는 OpenCode 세션 쿠키입니다(Fe26.2**로 시작). 만료되므로 https://opencode.ai에 로그인 → DevTools → Application → Cookies →auth에서 갱신하세요.
도구
query_go_usage
인자 없음. 세 기간 모두에 대한 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는 현재 사용 비율에 대한 예상 지출 범위를 나타냅니다.resetsIn은resetsInSeconds에서 파생된 사람이 읽기 쉬운 카운트다운입니다.
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
}balanceRaw는 1e-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를 통해 서버를 실행하고 initialize, tools/list, tools/call, 그리고 tools/call 오류 처리를 검증합니다. 자격 증명이 없으면 두 도구 호출이 예상대로 isError 결과로 실패합니다.
아키텍처
src/index.mjs— MCP stdio 프로토콜, 자격 증명(CLI/환경 변수), 페이지 가져오기 접착 코드src/http.mjs— 네트워크 정책: 타임아웃, 백오프 재시도, 429/Retry-After처리src/parse.mjs— 순수 파싱/포맷팅 헬퍼(I/O 없음, 직접 단위 테스트됨)
배포
npm publish라이선스
MIT
Available Tools
2 toolsquery_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.
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
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.
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.
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.
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.
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.
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.
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
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.
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.
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.
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.
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.
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
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.
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.
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.
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
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
A paid remote MCP for AI SDK data query MCP, built to return verdicts, receipts, usage logs, and aud
A paid remote MCP for OpenAI Codex agent coordination MCP, built to return verdicts, receipts, usage
Query OneLens cloud-cost data in natural language: breakdowns, trends, cost centers. Read-only.
Governed MCP gateway: one endpoint for your tools, with credential custody and audit log.
Related MCP Servers
- AlicenseAqualityFmaintenanceAn MCP server that retrieves current GitHub Copilot usage data, including quotas, limits, and usage statistics. It allows AI agents to monitor premium interaction status and detailed account usage via raw or formatted summaries.316MIT
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to query Kite Passport user info, sessions, wallet balance, and backend health via read-only MCP tools.MIT
- AlicenseNot gradedqualityDmaintenanceExposes GitHub Copilot premium request usage as an MCP tool, providing a breakdown by model and cost.MIT
- AlicenseAqualityAmaintenanceQueries real-time AI subscription quota for Claude Code Max, Kimi, and Z.ai. Tokens are read from environment variables and never stored.3MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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