agent-usage

agent-usage

Exposes rate-limit and usage data for AI coding agent CLIs as MCP tools, enabling querying of usage snapshots and reset times.

Category
访问服务器

README

agent-usage

Tracks rate-limit / usage data for AI coding agent CLIs (Claude Code, Codex CLI, Antigravity, GitHub Copilot CLI, ...) over time, tells you when each window next resets, and exposes the history over HTTP and MCP, plus a small dashboard.

Why

None of these CLIs currently expose their quota through a machine-readable flag — the only place the numbers show up is an interactive /usage or /status screen. This project drives that screen inside a disposable tmux session, parses it, and records it, so you get a queryable history instead of a number you have to read off a TUI by hand.

One exception: Copilot's /usage screen shows a percentage but never a reset time. GitHub's docs say the included AI-credit allowance always resets at 00:00 UTC on the 1st of the month regardless of subscription date, so that provider computes resetsAt directly instead of parsing it — see src/domain/reset-time.ts's nextUtcMonthStart.

Features

  • Periodic sampling of every registered provider, stored as a time series in SQLite (via Prisma) — not just the latest reading.
  • Resolves each provider's raw "resets in..." text into an absolute timestamp, so you can ask "when does this actually reset" instead of doing the math yourself.
  • HTTP API (/api/providers, /api/usage/latest, /api/usage/history, /api/usage/next-resets) and an MCP server exposing the same data as tools, so both scripts and agents can read it.
  • A dependency-free static dashboard (plain HTML/CSS/TS, hand-rolled SVG charts) served by the same HTTP server.
  • New providers are a config object + a parser function away — see docs/providers.md.

Quickstart

bun install
cp .env.example .env
bun run db:migrate:dev   # creates prisma/migrations + the local SQLite db
bun run build:frontend   # bundles frontend/main.ts -> frontend/main.js

bun run dev               # daemon: sampler loop + HTTP API + dashboard
# or, one-off:
bun run sample -- --provider claude
# or, for an MCP client:
bun run src/cli/index.ts mcp

The dashboard is served at http://localhost:7979/ by default (see HTTP_PORT / SAMPLE_INTERVAL_SECONDS in .env.example).

bun run dev shells out to the real claude/codex/agy/copilot CLIs on your machine (via tmux) — only run it where you actually want that.

Deployment modes

By default daemon is all-in-one: local SQLite database + HTTP API/dashboard

  • sampler, all in one process — this is what bun run dev runs.

It can also split into a central server (owns the database, serves read/write HTTP, no CLI dependencies of its own) and one or more standalone collectors (each just captures and pushes to the server, no database or HTTP server of its own). This is useful when you'd rather isolate the credential-bearing CLI processes from the server — e.g. one lightweight collector per provider, each only needing that one CLI's credentials.

# server: owns the database, accepts pushes, serves the dashboard.
# --no-sample makes it a pure server (no CLI/tmux use at all) for hosts
# with none of the agent CLIs installed; omit it to also sample locally.
INGEST_TOKEN=some-shared-secret bun run src/cli/index.ts daemon --no-sample

# collector: only samples codex, pushes to the server, no local database
INGEST_SERVER_URL=http://server-host:7979 \
INGEST_TOKEN=some-shared-secret \
bun run src/cli/index.ts daemon --provider codex

INGEST_TOKEN is an optional shared-secret bearer token — set it on both sides to require it, or leave it unset for an unauthenticated ingest endpoint (fine on a trusted network; put a real auth layer in front otherwise, which neither the server nor its collectors need to know about).

How it works

  1. Capture (src/capture/tmux.ts): launches a provider's CLI in a disposable tmux session, sends its usage slash-command, and captures the rendered pane text once it settles.
  2. Parse (src/providers/*/parse.ts): a small regex-based parser per provider turns that captured text into a provider-neutral UsageSnapshot (see src/domain/types.ts).
  3. Store (src/storage/sink.ts): each snapshot goes to a SnapshotSink — either a direct Prisma write (createLocalSink) or a push to a remote server's ingest endpoint (createRemoteSink, in src/daemon/), depending on the deployment mode (see below). Local writes persist a Sample with its Windows via src/storage/repository.ts.
  4. Serve: src/server/http.ts (REST) and src/mcp/server.ts (MCP tools) both read from the same repository layer, regardless of which collectors fed it.

See docs/architecture.md for more detail, and docs/providers.md for how to add a new agent CLI.

Development

bun run typecheck   # backend + frontend (two separate tsconfigs; the
                     # frontend one adds DOM lib for browser globals)
bun run lint
bun test

Tests that touch storage/HTTP/MCP spin up their own throwaway SQLite file via prisma db push in beforeAll — no shared or checked-in test database.

License

MIT — see LICENSE.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选