# suryanshu-singh/capbroker architecture

> Architecture diagram of the GitHub repository suryanshu-singh/capbroker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/suryanshu-singh/capbroker
- Repository: https://github.com/suryanshu-singh/capbroker

## Overview

#### 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`

Main entry points: [`src/capbroker/broker.py`](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/broker.py) (Broker.handle()), [`src/capbroker/server.py`](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/server.py) (Localhost HTTP service), [`src/capbroker/credential_provider.py`](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/credential_provider.py) (Credential provider), [`src/capbroker/mcp_proxy.py`](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/mcp_proxy.py) (MCP proxy)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_agent["Agent side"]
  node_agent_api["Agent API<br/>agent submission<br/>[agent.py]"]
  node_client["Broker client<br/>HTTP client<br/>[client.py]"]
  node_signing_models["Signed capability models<br/>shared signing<br/>[capability.py]"]
end

subgraph group_broker["Broker security boundary"]
  node_cli["CLI lifecycle<br/>service launcher<br/>[cli.py]"]
  node_server{{"Localhost HTTP service<br/>process boundary<br/>[server.py]"}}
  node_broker_core{{"Broker.handle&#40;&#41;<br/>authorization pipeline<br/>[broker.py]"}}
  node_enforcement["Policy, replay, capability store<br/>deterministic checks<br/>[policy.py]"]
  node_approval["Terminal approval<br/>operator gate<br/>[approval.py]"]
end

subgraph group_execution["Provider execution"]
  node_credential_provider["Credential provider<br/>post-authorization credentials"]
  node_credential_store[("OS credential store<br/>external secret store<br/>[credentials.py]")]
  node_github_app["GitHub App token minting<br/>dynamic credentials<br/>[github_app.py]"]
  node_github["GitHub connector<br/>upstream connector<br/>[github.py]"]
  node_github_api(("GitHub APIs<br/>external service"))
end

subgraph group_proxy["MCP proxy path"]
  node_mcp_proxy{{"MCP proxy<br/>authorization proxy<br/>[mcp_proxy.py]"}}
  node_policy_maps["MCP policy maps<br/>tool mappings<br/>[fake_github.json]"]
  node_upstream_mcp["Wrapped MCP server<br/>upstream tool server"]
end

subgraph group_observability["Audit and dashboard"]
  node_audit[("Append-only audit<br/>event log<br/>[audit.py]")]
  node_screener["Advisory response screening<br/>risk context<br/>[screener.py]"]
  node_dashboard["React dashboard<br/>read-only audit UI<br/>[App.tsx]"]
end

node_cli -->|"starts"| node_server
node_agent_api -->|"creates signed actions"| node_signing_models
node_agent_api -->|"submits through"| node_client
node_client -->|"localhost signed action"| node_server
node_server -->|"dispatches"| node_broker_core
node_broker_core -->|"verifies capability and action"| node_signing_models
node_broker_core -->|"runs deterministic checks"| node_enforcement
node_broker_core -->|"requests approval when required"| node_approval
node_broker_core -->|"allowed requests only"| node_credential_provider
node_credential_provider -->|"reads static credential"| node_credential_store
node_credential_provider -->|"or mints dynamic token"| node_github_app
node_github_app -->|"installation token"| node_github_api
node_credential_provider -->|"supplies credential"| node_github
node_github -->|"provider calls"| node_github_api
node_broker_core -->|"records issuance and decisions"| node_audit
node_server -->|"GET /audit"| node_audit
node_dashboard -->|"polls audit endpoint"| node_server
node_mcp_proxy -->|"maps granted tools"| node_policy_maps
node_mcp_proxy -->|"checks mapped tools/calls"| node_broker_core
node_mcp_proxy -->|"forwards ALLOW only"| node_upstream_mcp
node_screener -.->|"advisory risk context"| node_approval

click node_agent_api "https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/agent.py"
click node_client "https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/client.py"
click node_signing_models "https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/capability.py"
click node_cli "https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/cli.py"
click node_server "https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/server.py"
click node_broker_core "https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/broker.py"
click node_enforcement "https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/policy.py"
click node_approval "https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/approval.py"
click node_credential_provider "https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/credential_provider.py"
click node_credential_store "https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/credentials.py"
click node_github_app "https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/github_app.py"
click node_github "https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/connectors/github.py"
click node_mcp_proxy "https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/mcp_proxy.py"
click node_policy_maps "https://github.com/suryanshu-singh/capbroker/blob/main/policies/fake_github.json"
click node_audit "https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/audit.py"
click node_screener "https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/screener.py"
click node_dashboard "https://github.com/suryanshu-singh/capbroker/blob/main/frontend/src/App.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_agent_api,node_client,node_signing_models toneBlue
class node_cli,node_server,node_broker_core,node_enforcement,node_approval toneAmber
class node_credential_provider,node_credential_store,node_github_app,node_github,node_github_api toneMint
class node_mcp_proxy,node_policy_maps,node_upstream_mcp toneRose
class node_audit,node_screener,node_dashboard toneIndigo
```

## Components

### Agent side

Holds signing keys and submits signed calls.

- [Agent API](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/agent.py): agent submission · `src/capbroker/agent.py`
- [Broker client](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/client.py): HTTP client · `src/capbroker/client.py`
- [Signed capability models](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/capability.py): shared signing · Capabilities, actions, identities, and canonical payloads. · `src/capbroker/capability.py`

### Broker security boundary

Local authorization and execution service.

- [CLI lifecycle](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/cli.py): service launcher · `src/capbroker/cli.py`
- [Localhost HTTP service](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/server.py): process boundary · Accepts signed actions and exposes the audit stream. · `src/capbroker/server.py`
- [Broker.handle()](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/broker.py): authorization pipeline · Verifies, enforces, authorizes, approves, then executes. · `src/capbroker/broker.py`
- [Policy, replay, capability store](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/policy.py): deterministic checks · Expiry, revocation, limits, signatures, nonces, and resource policy. · `src/capbroker/policy.py`
- [Terminal approval](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/approval.py): operator gate · Fails closed when stdin is unavailable. · `src/capbroker/approval.py`

### Provider execution

Credentials are acquired only after authorization.

- [Credential provider](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/credential_provider.py): post-authorization credentials · `src/capbroker/credential_provider.py`
- [OS credential store](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/credentials.py): external secret store · Static credentials reside in the OS keyring. · `src/capbroker/credentials.py`
- [GitHub App token minting](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/github_app.py): dynamic credentials · Maps operations to GitHub App permissions fail-closed. · `src/capbroker/github_app.py`
- [GitHub connector](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/connectors/github.py): upstream connector · `src/capbroker/connectors/github.py`
- **GitHub APIs**: external service · REST API and optional App installation-token endpoints.

### MCP proxy path

A separate authorization-only trust model.

- [MCP proxy](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/mcp_proxy.py): authorization proxy · Filters tools and forwards only broker-allowed calls. · `src/capbroker/mcp_proxy.py`
- [MCP policy maps](https://github.com/suryanshu-singh/capbroker/blob/main/policies/fake_github.json): tool mappings · Unknown tools deny by default. · `policies/fake_github.json`
- **Wrapped MCP server**: upstream tool server · Retains and uses its own credentials.

### Audit and dashboard

Append-only events and read-only UI.

- [Append-only audit](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/audit.py): event log · Rejects credential-shaped fields. · `src/capbroker/audit.py`
- [Advisory response screening](https://github.com/suryanshu-singh/capbroker/blob/main/src/capbroker/screener.py): risk context · Cannot change authorization decisions. · `src/capbroker/screener.py`
- [React dashboard](https://github.com/suryanshu-singh/capbroker/blob/main/frontend/src/App.tsx): read-only audit UI · Polls the audit endpoint every two seconds. · `frontend/src/App.tsx`

## Connections

- 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
