How suryanshu-singh/capbroker works
Purpose and Entry Points
capbroker is a local, self-hosted authorization broker for AI-agent tool calls. Agents hold only signing keys and scoped, short-lived capability tokens; the broker alone accesses provider credentials and executes allowed actions.
Primary entry points:
• CLI/service lifecycle: src/capbroker/cli.py, src/capbroker/server.py
• Agent-side submission API: src/capbroker/agent.py, src/capbroker/client.py
• Core authorization boundary: src/capbroker/broker.py
Capability and Signing Model
Capabilities bind an agent public key to permitted operations/resources, expiry, call limits, revocation state, and optional approval requirement. The broker signs issued capabilities; agents create signed action requests whose parameters are hashed into the signed payload.
• src/capbroker/capability.py
• src/capbroker/action.py
• src/capbroker/identity.py
• src/capbroker/canonical.py
Shared signing models are intentionally available on both sides of the process boundary. Broker internals and credentials are not agent dependencies.
Deterministic Broker Enforcement Pipeline
Broker.handle() is the security-critical pipeline. It retrieves and verifies the stored capability, enforces expiry/revocation/call limits, validates the agent signature and parameter hash, rejects replayed or stale nonce/timestamp pairs, and evaluates operation/resource policy. Only an allowed request can acquire a credential and invoke a connector.
• src/capbroker/broker.py
• src/capbroker/policy.py
• src/capbroker/replay.py
• src/capbroker/store.py
The HTTP service is localhost-only. Agents submit SignedAction payloads to it through BrokerClient, creating a real process boundary rather than relying only on module conventions.
• src/capbroker/server.py
• src/capbroker/client.py
Execution, Credentials, and GitHub
The direct-connector path obtains a credential only after authorization, then dispatches to an upstream connector. GitHub is the implemented provider.
• src/capbroker/credential_provider.py
• src/capbroker/credentials.py
• src/capbroker/connectors/github.py
Static credentials use the OS keyring. Optional dynamic GitHub credentials mint per-call GitHub App installation tokens, with fail-closed operation-to-permission mapping and local private-key-file storage.
• src/capbroker/github_app.py
• src/capbroker/credential_provider.py
External services: GitHub REST API, OS credential store, and optionally GitHub App token endpoints.
Approval and Audit Boundary
Capabilities may require an operator decision after deterministic authorization but before execution. Prompts run in the broker’s terminal and deny when stdin is unavailable, so an agent or proxy cannot approve its own requests.
• src/capbroker/approval.py
• src/capbroker/broker.py
Every issuance, decision, approval outcome, and screening event is append-only audited. Audit logging rejects credential-shaped fields, and the service exposes the event stream via GET /audit.
• src/capbroker/audit.py
• src/capbroker/server.py
MCP Proxy Integration
The proxy wraps an existing MCP server without changing it. At startup it obtains the upstream tool list; it filters exposed tools to those mapped and granted by the capability. Each tools/call is mapped through a hand-written policy map, checked by the broker, then forwarded only on ALLOW.
• src/capbroker/mcp_proxy.py
• policies/fake_github.json
• policies/filesystem.json
This is a distinct trust model: the wrapped MCP server retains and uses its own credential; capbroker only provides the authorization decision. Unknown tool mappings deny by default.
Advisory Screening and Dashboard
Optional TypeSafe Jev integration screens MCP text responses and provides risk context at approval prompts. It is explicitly downstream/advisory: it cannot alter ALLOW/DENY decisions.
• src/capbroker/screener.py
• src/capbroker/jev_client.py
• src/capbroker/approval.py
The separate Vite/React dashboard polls the existing audit endpoint every two seconds; it introduces no backend state or control path.
• frontend/src/App.tsx
• frontend/src/main.tsx
• frontend/package.json
Components 19
Agent side
Holds signing keys and submits signed calls.
- Agent API
src/capbroker/agent.py - Broker client
src/capbroker/client.py - Signed capability models · Capabilities, actions, identities, and canonical payloads.
src/capbroker/capability.py
Broker security boundary
Local authorization and execution service.
- CLI lifecycle
src/capbroker/cli.py - Localhost HTTP service · Accepts signed actions and exposes the audit stream.
src/capbroker/server.py - Broker.handle() · Verifies, enforces, authorizes, approves, then executes.
src/capbroker/broker.py - Policy, replay, capability store · Expiry, revocation, limits, signatures, nonces, and resource policy.
src/capbroker/policy.py - Terminal approval · Fails closed when stdin is unavailable.
src/capbroker/approval.py
Provider execution
Credentials are acquired only after authorization.
- Credential provider
src/capbroker/credential_provider.py - OS credential store · Static credentials reside in the OS keyring.
src/capbroker/credentials.py - GitHub App token minting · Maps operations to GitHub App permissions fail-closed.
src/capbroker/github_app.py - GitHub connector
src/capbroker/connectors/github.py - GitHub APIs · REST API and optional App installation-token endpoints.
MCP proxy path
A separate authorization-only trust model.
- MCP proxy · Filters tools and forwards only broker-allowed calls.
src/capbroker/mcp_proxy.py - MCP policy maps · Unknown tools deny by default.
policies/fake_github.json - Wrapped MCP server · Retains and uses its own credentials.
Audit and dashboard
Append-only events and read-only UI.
- Append-only audit · Rejects credential-shaped fields.
src/capbroker/audit.py - Advisory response screening · Cannot change authorization decisions.
src/capbroker/screener.py - React dashboard · Polls the audit endpoint every two seconds.
frontend/src/App.tsx
Connections 21
- CLI lifecycle → Localhost HTTP service: starts
- Agent API → Signed capability models: creates signed actions
- Agent API → Broker client: submits through
- Broker client → Localhost HTTP service: localhost signed action
- Localhost HTTP service → Broker.handle(): dispatches
- Broker.handle() → Signed capability models: verifies capability and action
- Broker.handle() → Policy, replay, capability store: runs deterministic checks
- Broker.handle() → Terminal approval: requests approval when required
- Broker.handle() → Credential provider: allowed requests only
- Credential provider → OS credential store: reads static credential
- Credential provider → GitHub App token minting: or mints dynamic token
- GitHub App token minting → GitHub APIs: installation token
- Credential provider → GitHub connector: supplies credential
- GitHub connector → GitHub APIs: provider calls
- Broker.handle() → Append-only audit: records issuance and decisions
- Localhost HTTP service → Append-only audit: GET /audit
- React dashboard → Localhost HTTP service: polls audit endpoint
- MCP proxy → MCP policy maps: maps granted tools
- MCP proxy → Broker.handle(): checks mapped tools/calls
- MCP proxy → Wrapped MCP server: forwards ALLOW only
- Advisory response screening → Terminal approval: advisory risk context