quota-mcp

io.github.limitcool由 GitHub 账号 limitcool 发布v0.3.2更新于 Oct 24, 2026

Usage & quota tracker for AI subscription accounts (StepFun, Command Code)

已验证STDIO仅桌面金融数据与分析

概览

AI 生成的概览

本地只读 MCP 服务器,汇总 StepFun 与 Command Code 订阅账户的用量与额度,回答还剩多少额度。

可以做什么
列出账户的套餐、到期时间、剩余额度以及脱敏后的会话或密钥状态,并给出各平台正常、受限、失效或需重新登录的汇总和用于定时摘要的报告数据。对单个账户或全部账户向上游厂商实时探测并刷新缓存数据。检查已触发的告警:额度偏低、即将到期、会话失效、密钥被拒和速率窗口超限。账户录入、续期和删除不在 MCP 中提供,只存在于服务器单独的 REST 管理接口。
适用场景
当你持有 StepFun 或 Command Code 订阅,希望助手直接回答额度问题、提示余额不足或套餐即将到期,或定期生成用量摘要而无需逐个打开厂商控制台时适用。
运行要求
以本地进程运行(二进制或已发布的容器镜像),SQLite 数据库路径由 QUOTA_MCP_DB 指定。生产环境需设置 QUOTA_MCP_MASTER_KEY(64 位十六进制字符)以加密存储的凭据。账户须先通过 REST 接口录入厂商凭据:StepFun 的浏览器会话 Cookie 或套餐密钥,或 Command Code 的 API 密钥或会话 Cookie。探测需要访问厂商接口的网络。
安装前请注意
会将厂商会话 Cookie 和 API 密钥加密存入 SQLite;丢失 QUOTA_MCP_MASTER_KEY 会导致所有已存凭据无法读取,请备份。未设置主密钥时加密密钥由机器特征派生。REST 接口可录入、续期和删除账户,应仅绑定回环或私有网络。探测会访问第三方厂商接口。可选的告警 webhook 会把账户状态详情 POST 到配置的地址。

安装

在 SourceWeft 中

  1. 打开 控制台中的 quota-mcp,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

English | 简体中文

quota-mcp

A usage & quota tracker for AI subscription accounts. It pulls the balances, subscription expiry dates and rate-limit windows that are scattered across vendor dashboards into one place, and exposes them through both a REST management API and an MCP query surface — point your agent (Hermes, Claude Code, …) at it with one config line and it can answer "how much quota do I have left?" on its own.

Two platforms supported today:

PlatformData sourceCredentialWhat you can see
StepFun (阶跃星辰, .ai intl / .com China)platform.stepfun.{ai,com} console Connect RPCBrowser session (Oasis-Token, ~2 h, auto-renewed) + optional plan keyPlan & expiry, 5-hour / weekly / subscription credit windows, access keys under the account, session health
Command Code (commandcode.ai)Undocumented /alpha/* endpoints on api.commandcode.aiA single Bearer API keyPlan (GOAT/Pro/Max/…), 5-hour / weekly / monthly windows, balances, billing-period request stats

Highlights:

  • Encrypted at rest: credentials are AES-256-GCM encrypted into SQLite (pure-Go driver, no CGO); every endpoint returns masked views only
  • StepFun session auto-renewal: a background goroutine checks every 60 s and renews any session whose TTL drops below 20 min. Renewing an expired session gets you a degraded device token — there is a guard that detects this and refuses to persist it
  • Dual auth planes: StepFun's plan key (permanent) and console session (quota data) are managed and probed separately; the verdict is driven by the permanent plane
  • MCP is read-only: the query surface (list / probe / summarize) is safe to hand to agents; enrol / renew / delete live on the REST side only
  • Single binary, zero external services

Quick start

bash
go build -o quota-mcp ./cmd/quota-mcp

# In production set the master key explicitly (64 hex chars). Without it the key is
# derived from machine traits and old ciphertext becomes unreadable after a migration.
export QUOTA_MCP_MASTER_KEY=$(openssl rand -hex 32)

./quota-mcp -db data/quota-mcp.db -listen 127.0.0.1:8780

After startup:

  • http://127.0.0.1:8780/healthz health check
  • http://127.0.0.1:8780/api/stepfun/accounts REST list
  • http://127.0.0.1:8780/mcp MCP endpoint

Enrolling accounts

Command Code (two credential planes)

The alpha/API-key plane is the easy one — a permanent Bearer key:

bash
curl -X POST http://127.0.0.1:8780/api/commandcode/accounts \
  -H 'Content-Type: application/json' \
  -d '{"service":"cc-myname","api_key":"user_xxx","label":"primary"}'

Get the key from commandcode.ai/settings/keys (shown once at creation). The server validates it with whoami first and refuses to store a rejected key.

The internal/session plane mirrors the browser: pass session_text (the whole Cookie: header, a document.cookie dump, or the bare __Secure-commandcode_prod_.session_token value). It is validated against billing/credits and never stored unless it passes. Sessions expire, so refresh them from CookieCloud or by copying the cookie again from DevTools:

bash
curl -X POST http://127.0.0.1:8780/api/commandcode/accounts \
  -H 'Content-Type: application/json' \
  -d '{"service":"cc-myname","session_text":"__Secure-commandcode_prod_.session_token=eyJ..."}'

When both are stored the API key wins. Each enrol overwrites the credential planes it was given — re-enrolling with only api_key clears any stored session, and vice-versa, so a rotation is never silently skipped.

StepFun (browser session)

Oasis-Token is an HttpOnly cookie, so document.cookie cannot read it — copy it from a request header in DevTools. Paste the whole Cookie: header (or the bare token) to the server:

bash
curl -X POST http://127.0.0.1:8780/api/stepfun/accounts \
  -H 'Content-Type: application/json' \
  -d '{"service":"ai-412848664332275712","region":"ai","session_text":"Oasis-Token=eyJ...; Oasis-Webid=...","email":"[email protected]"}'

Protocol findings from real-world testing (all handled in code):

  • The .ai Oasis-Token cookie value is two JWTs concatenated (8 segments); the console only accepts the whole value — a single segment gets you token is illegal
  • Timestamp units differ per site: .ai returns second-level strings, .com returns milliseconds; the code infers by magnitude
  • .com device tokens live only 30 minutes and its RefreshToken returns a degraded token — .com sessions need periodic re-import
  • Renewing after expiry yields a device token (mode 1, data plane always token is illegal), so renewal must happen before expiry; a degradation guard refuses to store such tokens

REST API

GET    /api/stepfun/accounts                     List (masked view)
POST   /api/stepfun/accounts                     Enrol/update (stored only if at least one plane probes OK)
POST   /api/stepfun/accounts/{service}/probe     Probe (auto-renews once on console auth failure)
POST   /api/stepfun/accounts/{service}/renew     Force-renew the console session
POST   /api/stepfun/accounts/{service}/register?region=ai   Register an anonymous device slot (self-test)
DELETE /api/stepfun/accounts/{service}           Delete
POST   /api/stepfun/probe                        Probe all (cron-friendly)

GET    /api/commandcode/accounts                 List (masked view)
POST   /api/commandcode/accounts                 Enrol/update (api_key or session_text; stored only if it probes OK)
POST   /api/commandcode/accounts/{service}/probe Probe
DELETE /api/commandcode/accounts/{service}       Delete
POST   /api/commandcode/probe                    Probe all

MCP surface (for agents)

Two ways to connect — pick either:

1. Streamable HTTP (served on /mcp) — for always-on deployments:

yaml
mcp_servers:
  quota:
    url: http://<your-host>:8780/mcp

2. stdio — for clients that spawn the server themselves (Claude Code, containers, mcp-publisher-style registry installs):

bash
# local binary
quota-mcp -stdio

# or straight from the published image (works with zero setup)
docker run -i --rm -v quota-mcp-data:/data ghcr.io/limitcool/quota-mcp:latest

Works the same way from Claude Code or any other MCP client.

All tools are read-only:

ToolDescription
quota_list_accountsList every account: plan, expiry, remaining quota, session/key status (masked)
quota_probe_accountLive-probe one account (hits upstream, takes a few seconds)
quota_probe_allSerially probe all accounts and refresh the cache
quota_statusSummary: per-platform counts of serving / limited / invalid / needs-relogin, plus a one-line status per account
quota_check_alertsFiring alerts: low quota, upcoming expiry, dead session, rejected key, window exceeded
quota_reportThe scheduled-digest payload: all account numbers + current alerts

Alerts, expiry warnings & scheduled digest

quota-mcp owns condition detection (it holds the data and runs a 60 s background loop); scheduling and delivery belong to your agent platform. A hermes-style wiring:

1. Threshold & expiry alerts (event-driven, push)

A background evaluator refreshes stale probe data (>5 min), evaluates rules, keeps a firing/resolved state machine in SQLite (alert_events), and POSTs only the transitions to a webhook — the same alert never repeats until it clears and fires again.

Rules: credit_low (remaining share below threshold), expiring_soon (subscription/billing period ending within N days), session_dead (StepFun console session needs re-import), key_rejected (Command Code key got 401/403), window_limited (rate window exceeded).

bash
QUOTA_MCP_ALERT_WEBHOOK_URL=http://<hermes>:8642/webhooks/quota \
QUOTA_MCP_ALERT_CREDIT_PCT=0.2 \
QUOTA_MCP_ALERT_EXPIRY_DAYS=7 \
./quota-mcp -listen 0.0.0.0:8780

Payload pushed on each transition:

json
{
  "source": "quota-mcp",
  "at": "2026-09-21T15:52:30Z",
  "fired":    [{"kind":"credit_low","provider":"stepfun","service":"ai-…","severity":"warn","title":"订阅额度即将耗尽","detail":"剩余 13%(阈值 20%),2026-10-20 重置"}],
  "resolved": []
}

No webhook? No problem — hermes (or anything) can poll instead:

yaml
# hermes mcp_servers
mcp_servers:
  quota:
    url: http://<host>:8780/mcp

then have a hermes cron every 15–30 min call quota_check_alerts and hermes send anything new. Same for GET /api/alerts?history=20.

2. Scheduled digest (cron)

quota_report (or GET /api/report) returns a stable, agent-friendly payload: every account's plan / expiry / remaining quota / session state / window usage / request stats, plus current alerts. Point hermes's existing 09:30 cron at it: one turn calls the tool, composes the message, and delivers via hermes send. No scheduler is duplicated inside quota-mcp.

3. Environment variables

VariableDefaultMeaning
QUOTA_MCP_ALERT_CREDIT_PCT0.2Fires when remaining share drops below this
QUOTA_MCP_ALERT_EXPIRY_DAYS7Fires when subscription/billing period ends within N days
QUOTA_MCP_ALERT_WEBHOOK_URL—POST target for alert transitions; empty = record only (pull mode)

Example (quota_status output — what an agent would read to answer "how much quota is left?"):

json
{
  "stepfun": {
    "total": 2, "healthy": 2, "attention": 0,
    "accounts": ["ai-4128…: ok (10 models)", "com-3766…: ok (0 models)"]
  },
  "commandcode": {
    "total": 1, "serving": 1, "limited": 0, "key_rejected": 0,
    "accounts": ["cc-limitcool: serving GOAT"]
  }
}

Project layout

cmd/quota-mcp/        Entrypoint (flags/env config, one port serving both surfaces)
internal/store/       SQLite + AES-256-GCM encryption + schema
internal/stepfun/     StepFun protocol client + account registry + background renewer
internal/commandcode/ Command Code protocol client + account registry
internal/api/         REST management surface (net/http, no framework)
internal/mcpsrv/      MCP query surface (modelcontextprotocol/go-sdk)
internal/alerts/      Alert rules + firing/resolved state machine + webhook push
internal/digest/       Scheduled-digest payload for cron consumers

Security boundary

  • Ciphertext goes to the DB only — never to logs, never to responses; every endpoint returns masks
  • The REST surface contains writes: bind it to loopback or a private network. To expose it publicly, front it with a reverse proxy + auth and only publish the MCP path
  • Losing the master key means every stored credential becomes unreadable — back up QUOTA_MCP_MASTER_KEY

Releases

Binaries for Linux / macOS / Windows (amd64 + arm64) are attached to each GitHub Release. Grab the latest:

bash
# example: linux amd64
curl -LO https://github.com/limitcool/quota-mcp/releases/latest/download/quota-mcp_linux_amd64
chmod +x quota-mcp_linux_amd64

Docker

Image is published to ghcr.io/limitcool/quota-mcp (amd64 + arm64) on every main push (:main) and tag (:v1.0.0, :latest).

bash
docker run -d --name quota-mcp \
  -p 8780:8780 \
  -v quota-mcp-data:/data \
  -e QUOTA_MCP_MASTER_KEY=$(openssl rand -hex 32) \
  ghcr.io/limitcool/quota-mcp:latest

Or with the bundled compose file (QUOTA_MCP_MASTER_KEY is required, put it in .env):

bash
echo "QUOTA_MCP_MASTER_KEY=$(openssl rand -hex 32)" > .env
docker compose up -d

The database lives in the /data volume (QUOTA_MCP_DB=/data/quota-mcp.db). Back up the master key — losing it makes every stored credential unreadable.

License

MIT

来源:README.md,提交 4f8bc4f

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

2
  1. v0.3.2最新Sep 22, 2026
  2. v0.2.1Sep 21, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分