latchkey
Capability-token gate for AI agents. Mint time-boxed, scope-limited grants that authorize specific tool calls.
README
latchkey
Capability-token gate for AI agents. Mint time-boxed, scope-limited grants ("latchkeys") that authorize specific tool calls. Agents present a key; the gate verifies TTL, scopes, audience, and spend limits before allowing the call.
Full MCP surface for mint / revoke / introspect / authorize — plus CLI and a hash-chained audit log.
Why
Agent tool access is often all-or-nothing. Latchkey lets you hand an agent a narrow, expiring, use-capped credential instead of ambient authority — including delegation chains (A mints a tighter key for B) and an emergency kill-switch.
Features
- HMAC-signed tokens (
lk1.…) viaLATCHKEY_SECRET— no external KMS required - Scopes:
tool:http_request,tool:file_write:path=/tmp/**,risk:irreversible - Use-once keys (
maxUses: 1) and spend limits - Delegation with narrow-only MintPolicy
- Revocation list + revoke-all kill-switch
- Hash-chained audit log + Mermaid grant-graph export
- MCP tools + CLI
Packages
| Package | Role |
|---|---|
@latchkey/core |
LatchKey, KeyStore, MintPolicy, Authorizer, RevocationList, AuditLog |
@latchkey/mcp-server |
Stdio MCP server |
@latchkey/cli |
latchkey CLI |
Quick start
git clone https://github.com/SanjoyDat1/latchkey.git
cd latchkey
npm install
cp .env.example .env # set LATCHKEY_SECRET
export LATCHKEY_SECRET="$(openssl rand -hex 32)"
npm run build
npm test
npm run typecheck
CLI
export LATCHKEY_SECRET="$(openssl rand -hex 32)"
npx latchkey mint \
--audience coding-agent \
--scope 'tool:file_write:path=/tmp/**' \
--scope 'tool:http_request' \
--ttl-ms 3600000 \
--max-uses 20
npx latchkey authorize --token "$TOKEN" --tool file_write --param path=/tmp/out.txt --audience coding-agent
npx latchkey export --format mermaid
npx latchkey revoke --all # emergency kill-switch
Use LATCHKEY_STORE_PATH so mint/authorize share state across CLI processes.
Cursor MCP config
Add to your Cursor MCP settings (stdio; logs go to stderr only):
{
"mcpServers": {
"latchkey": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/latchkey/packages/mcp-server/dist/index.js"],
"env": {
"LATCHKEY_SECRET": "replace-with-long-random-secret-32chars-min",
"LATCHKEY_ADMIN_TOKEN": "replace-with-admin-token-16chars-min",
"LATCHKEY_STORE_PATH": "/ABSOLUTE/PATH/TO/latchkey/.latchkey/store.json",
"LATCHKEY_AUDIT_PATH": "/ABSOLUTE/PATH/TO/latchkey/.latchkey/audit.json"
}
}
}
}
Admin tools (lk_mint, lk_revoke, lk_list_active, lk_audit_query, lk_export) require adminToken matching LATCHKEY_ADMIN_TOKEN. lk_authorize / lk_introspect only need a latchkey token (authorize also requires audience).
MCP tools
| Tool | Purpose |
|---|---|
lk_mint |
Mint a latchkey (optional parentToken for delegation) |
lk_revoke |
Revoke by id/token, or all kill-switch |
lk_introspect |
Status without consuming a use |
lk_authorize |
Gate a tool call (consumes a use on allow) |
lk_list_active |
List live keys |
lk_audit_query |
Query hash-chained audit events |
lk_export |
Mermaid grant graph or JSON snapshot |
Token format
lk1.<base64url(payload)>.<base64url(hmac_sha256)>
Signed with HMAC-SHA256(LATCHKEY_SECRET, "lk1." + payload). Verification uses constant-time comparison.
Secret: set LATCHKEY_SECRET (min 32 characters). Set LATCHKEY_ADMIN_TOKEN for MCP admin tools. Never commit secrets. Rotate by minting new keys and revoking old ones.
Architecture
See docs/ARCHITECTURE.md and docs/PLAN.md.
flowchart LR
Host[Agent Host] -->|MCP| Server[latchkey-mcp]
Server --> Core[Authorizer / MintPolicy]
Core --> Store[KeyStore]
Core --> Rev[RevocationList]
Core --> Audit[AuditLog]
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。