RiskboundDocs

Reference

Riskbound gateway

An MCP server that wraps your agent's real MCP tool server and asks Riskbound before every tool call. The agent's code does not change: its MCP configuration starts the gateway instead of the tool server.

 agent  --MCP-->  gateway  --MCP-->  real tool server
                     |
                     +--> Riskbound: allow, ask a human, or block
OutcomeWhat the agent sees
allowThe tool's real result
ask a humanThe call is held until someone approves or rejects it in the dashboard. Progress is reported while it waits
blockAn error result saying why. The tool is never called

Lists, resources and prompts pass straight through. The design is in ../docs/adr/0006-the-gateway-is-an-mcp-proxy.md.

The one rule that makes it a control#

Move the tool server's credentials out of the agent's environment and into the gateway's. The gateway passes them to the tool server through upstream.env. If the agent can still reach the tool with its own copy of the key, the gateway is a suggestion, not a control.

The gateway's own key#

The gateway decides with its own Riskbound key, a gateway key. An admin makes one and names the agents it may act for:

bash
curl -X POST "$RISKBOUND_URL/v1/gateway-keys" \
  -H "authorization: Bearer $ADMIN_KEY" -H 'content-type: application/json' \
  -d '{"name": "edge gateway", "agents": ["support-bot"]}'

The answer holds the key once. Only a gateway key can mark a decision as made through the gateway, which is what Watch gives credit for, and only for the agents it is bound to. An agent key that says it is the gateway is blocked (via_not_trusted). To change the agents, make a new key and revoke the old one (POST /v1/gateway-keys/:id/revoke). See ../docs/adr/0012-gateway-keys.md.

At start-up the gateway asks Riskbound about its key. It refuses to start if the key is revoked, is not a gateway key, is not bound to every agent in the config, or if Riskbound cannot say.

Configure#

json
{
  "agent": "support-bot",
  "riskbound": { "baseUrl": "http://localhost:8200" },
  "upstream": {
    "command": "node",
    "args": ["payments-server.js"],
    "env": { "PAYMENTS_API_KEY": "${PAYMENTS_API_KEY}" }
  },
  "readOnlyTools": ["list_orders"],
  "tools": {
    "refund_payment": { "tool": "refund", "params": { "amount_minor": "amount_cents" } }
  }
}
FieldMeaning
agentThe registered agent this gateway acts for over stdio. Not used over HTTP
riskbound.baseUrlThe Riskbound backend
riskbound.apiKeyEnvEnvironment variable holding the gateway key, in both modes. Default RISKBOUND_API_KEY. Never put the key in the file
riskbound.failModeclosed (default): if Riskbound cannot be reached, the tool is not called
upstreamHow to start the real tool server. ${NAME} in env is read from the gateway's environment
readOnlyToolsTools forwarded without a check. Keep it to lookups
allowedToolsOptional. The only tools the agent sees and may call. Read-only tools must be listed too. Any other tool is refused by the gateway, without asking Riskbound or calling the tool
listenOptional. Serve MCP over HTTP instead of stdio. See below
toolsOptional per tool: the name policy sees, and params copied from arguments (dot paths work)

With no mapping, a tool is checked under its own name and its arguments are the params.

Then point the agent at the gateway, for example in an MCP client config:

json
{
  "command": "riskbound-gateway",
  "args": ["--config", "/path/to/gateway.json"],
  "env": { "RISKBOUND_API_KEY": "rb_gateway_..." }
}

Serve remote agents over HTTP#

Add a listen block and the gateway serves MCP Streamable HTTP instead of stdio. One gateway can serve several agents.

json
{
  "riskbound": { "baseUrl": "http://localhost:8200" },
  "upstream": { "command": "node", "args": ["payments-server.js"] },
  "readOnlyTools": ["list_orders"],
  "listen": {
    "host": "127.0.0.1",
    "port": 8310,
    "path": "/mcp",
    "agents": [
      { "agent": "support-bot", "keySha256": "<sha256 of its agent key>" },
      { "agent": "billing-bot", "keySha256": "<...>", "allowedTools": ["list_orders"] }
    ]
  }
}

Each agent sends its own Riskbound agent key as a Bearer token on every request (Authorization: Bearer rb_agent_...). That key says who is calling. Decisions are made with the gateway's own key. The gateway:

  • refuses a request with no key, or with a key whose SHA-256 is not in listen.agents, with 401. No MCP session opens;
  • ties each MCP session to the key that opened it, and refuses that session with any other key (403);
  • asks Riskbound with the gateway key and the agent name from its entry. The agent cannot pick its own name;
  • refuses an agent key from another tenant than the gateway key (401), and an agent the gateway key is not bound to (503);
  • uses the entry's allowedTools if it has one, else the top-level one.

The gateway never stores keys, only their hashes. Print the hash of a key:

bash
printf %s "$AGENT_KEY" | riskbound-gateway hash-key

Revoked keys and idle sessions#

A hash in the config is not enough on its own: a revoked key still has the same hash. So the gateway also asks Riskbound (GET /v1/auth/key) whether the key is live:

  • before it opens a session. A revoked key gets 401. If Riskbound cannot be reached, or does not give a clear yes, the session is refused with 503. This is fail-closed whatever failMode says;
  • again for every open session every listen.keyCheckIntervalMs. A key that is revoked, or that Riskbound cannot vouch for, loses its sessions. Its running calls are aborted and read-only tools stop working too.

The gateway's own key is checked at the same times. While it fails, no session opens (503), and at the next interval every open session closes.

A session with no request for listen.idleTimeoutMs is closed. A call that is still running, such as one waiting for approval, keeps it open. The agent opens a new session when it comes back, and its key is checked again.

FieldDefaultMeaning
listen.keyCheckIntervalMs60000How often each open session's key is checked again. A revoked key keeps working for at most this long, plus one request timeout
listen.idleTimeoutMs900000 (15 minutes)Close a session with no request for this long

Health#

GET /health needs no key. It answers 200 {"status":"ok","upstream":"connected"} while the gateway serves and its upstream tool server is connected, and 503 otherwise. It says nothing else. Use it for container and reverse proxy health checks. listen.path cannot be /health.

host defaults to 127.0.0.1. Keys travel in a header, so put TLS in front of the gateway before it listens anywhere but loopback. In HTTP mode RISKBOUND_API_KEY holds the gateway key, as over stdio. The agents' keys are never in the gateway's environment.

Try it#

With the backend running and seeded (npm run db:seed:dev prints an agent key and a gateway key bound to support-bot):

bash
npm install
npm run build
PAYMENTS_API_KEY=demo RISKBOUND_API_KEY=<gateway key> npx tsx examples/agent.ts

It lists tools, runs a lookup, sends a $40 refund (allowed) and a $900 refund (blocked), then times calls with and without the gateway. Add ASK_FOR_APPROVAL=1 to send a $480 refund that waits for you to approve it in the dashboard. Set RISKBOUND_GATEWAY_DEBUG=1 to log each decision's timing.

The HTTP version starts the gateway on port 8310 (set PORT to change it), shows a request with no key being refused, then connects with the agent key:

bash
PAYMENTS_API_KEY=demo RISKBOUND_AGENT_KEY=<agent key> RISKBOUND_GATEWAY_KEY=<gateway key> npx tsx examples/agent-http.ts

What it costs#

The gateway answers the agent as soon as the tool returns. It reports the result to Riskbound after that, in the background (the SDK's reportResult: "background"). A failed report is logged and never changes the agent's result.

Measured on a laptop against a local Postgres and API (2026-12-01, 20 small refunds after warm-up, median):

PathWithout the checkWith the checkAdded
stdio0.2 ms (direct to the tool)5.4 ms5.3 ms
HTTP0.7 ms (read-only call)6.1 ms5.4 ms

Before the report moved to the background, the check added about 8 ms. The rest is the decision round trip. Measure again on your own setup; these are not production numbers.

Not built yet#

Dry runs (MCP has no standard way to ask a tool for one), and policy checks inside the gateway without a round trip.

Develop#

bash
(cd ../sdk && npm install && npm run build)   # the gateway uses the local SDK
npm install
npm run lint && npm run format:check && npm run typecheck && npm test && npm run build