platform-mcp-stub

platform-mcp-stub

Demonstrates agent-native platform onboarding with human-in-the-loop API key provisioning, plus live usage and rate-limit queries via Anthropic Admin APIs.

Category
访问服务器

README

platform-mcp-stub

A minimal MCP server (TypeScript, stdio transport, official @modelcontextprotocol/sdk) that demonstrates agent-native platform onboarding with human-in-the-loop provisioning: an agent can discover its usage and limits on its own, but getting a credential always routes through a visible human approval gate.

Tools

Tool What it does Real vs fixture
request_api_key(scope, justification) Files a pending approval request in a local approvals.json ledger and returns pending human approval: <id>. Nothing is minted by the agent. A human runs the companion approve <id> CLI to flip it, which attaches a deliberately fake key (sk-ant-demo-...). The agent can poll with scope="status:<id>" and re-fetch an already-approved scope. The gate is real (ledger + CLI); the key is intentionally fake — this stub never touches real credential minting.
get_usage_summary() Last 7 days of org token usage, daily buckets grouped by model, via the Anthropic Usage Admin API (GET /v1/organizations/usage_report/messages). Live when ANTHROPIC_ADMIN_KEY is set (real HTTP call, real schema). Otherwise returns a fixture explicitly labeled _fixture: true whose shape mirrors the documented response.
get_limit_status() The org's configured rate-limit groups (per-model-group RPM / input-TPM / output-TPM, batch queue limits) via the Rate Limits Admin API (GET /v1/organizations/rate_limits). Same pattern: live with an admin key, labeled fixture without.

The human-approval gate is the whole point: the agent's request, the human's decision, and the resulting (fake) credential are all visible in one plain-JSON ledger.

What is real vs fixture

  • Real: the MCP protocol surface (official SDK, stdio JSON-RPC), the approvals ledger and CLI flow, and — when ANTHROPIC_ADMIN_KEY is present — the HTTP calls to the two Admin API endpoints above (correct headers: anthropic-version: 2023-06-01, x-api-key).
  • Fixture: without an admin key, get_usage_summary / get_limit_status return synthetic data labeled _fixture: true with a _note, matching the real response schemas so downstream handling is identical.
  • Always fake: issued keys. Format sk-ant-demo-<hex>; they mint nothing and authenticate nowhere.

Note: the Admin API requires an Admin API key (sk-ant-admin01-...), which is a different credential from a regular Claude API key, and is only available on organization (not individual) accounts.

Run it

npm install
npm run build
npm start            # MCP server on stdio (Ctrl-C to stop)

Demo the approval flow end to end:

# 1. In an MCP client (or via raw JSON-RPC — see below), call:
#    request_api_key(scope="usage:read", justification="dashboard prototype")
#    -> "pending human approval: apprq_xxxxxxxx"

# 2. As the human operator:
npm run approve -- list
npm run approve -- apprq_xxxxxxxx
#    -> approved; prints the FAKE sk-ant-demo-... key
#    (to reject instead: npm run approve -- deny apprq_xxxxxxxx)

# 3. Agent re-calls request_api_key (same scope, or scope="status:apprq_xxxxxxxx")
#    -> gets the demo key

No MCP client handy? Drive the server with raw JSON-RPC over stdio. Pipe into node dist/server.js directly — not npm start, because npm prints its script banner to stdout, which pollutes the JSON-RPC stream:

printf '%s\n' \
  '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"0.0.1"}}}' \
  '{"jsonrpc":"2.0","method":"notifications/initialized"}' \
  '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"request_api_key","arguments":{"scope":"usage:read","justification":"dashboard prototype"}}}' \
  | node dist/server.js

The same pattern works for get_usage_summary and get_limit_status (empty arguments).

To exercise the live Admin API paths:

export ANTHROPIC_ADMIN_KEY=sk-ant-admin01-...
npm start

Wire into Claude Code

claude mcp add platform-stub -- node /absolute/path/to/platform-mcp-stub/dist/server.js

Optionally pass the admin key through:

claude mcp add platform-stub -e ANTHROPIC_ADMIN_KEY=sk-ant-admin01-... -- \
  node /absolute/path/to/platform-mcp-stub/dist/server.js

Then in a Claude Code session: "Request an API key for scope messages:write and check our current usage and limits." Approve from a second terminal with npm run approve -- <id>.

Honest scope notes (v1)

  • Evening-sized prototype, not a provisioning product: single-file JSON ledger, no auth on the approve CLI, no expiry/rotation, no real key minting (by design — the Admin API does support key management, which a v2 could gate behind the same approval flow).
  • Usage summary is a fixed query (7 days, 1d buckets, group_by[]=model); the real endpoint supports much richer filtering/grouping.
  • approvals.json lives at the repo root by default; override with APPROVALS_FILE.

Requirements

  • Node 20+
  • ANTHROPIC_ADMIN_KEY (admin key, sk-ant-admin01-...) only for live usage/limit data — everything else works offline.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选