Architecture
ADR 0006: The gateway is an MCP proxy
Date: 2026-12-01. Status: accepted.
Context#
The SDK guard only works when the agent calls it and reports the amount truthfully (threat model rows 1 and 2). Phase 2 removes that dependency: the check has to happen on the real call, outside the agent's code.
Most agent frameworks now reach their tools over MCP. An agent is pointed at an MCP server by configuration, not by code.
Decision#
The gateway is an MCP server that wraps the real MCP server. The agent is configured to start the gateway instead of the tool server. The gateway starts the real server itself and passes everything through, except tool calls:
- Read the tool name and arguments of the real call.
- Ask the control plane for a decision, using the agent's key.
allow: forward the call and report the result.ask_human: hold the call until a person answers, then forward or refuse.block: return an error result to the agent. The real tool is never called.- Tools listed as read-only in the gateway config are forwarded without a check, so lookups do not need a policy.
The first version speaks MCP over stdio, the transport local agents use. Streamable HTTP, for remote agents, comes next.
The gateway carries out decisions with the SDK's guard(), the same code an
SDK user runs. It does not decide anything itself (ADR 0005 still holds).
Why#
- No code change for the agent. One line of its MCP configuration changes.
- It sees the real call. The amount the policy checks is the amount the tool receives, because the gateway forwards the exact arguments it checked.
- The credentials can move. The real server's API keys go in the gateway's environment, not the agent's. An agent without them cannot go around the gateway.
- One implementation of the outcome rules. Reusing
guard()means approvals, timeouts and fail-closed behave the same in both paths.
Consequences#
- The gateway only enforces anything if the agent cannot reach the tool another way. Moving the tool credentials into the gateway is part of setting it up, and the docs say so.
- Each guarded call costs one round trip to the control plane, which writes the decision before it answers. That cost is measured, not assumed. Policy evaluation inside the gateway is the known way to cut it, and needs policy sync and revocation first.
- Mapping MCP arguments to policy params is configuration: a tool can be
renamed for policy, and an argument can be copied to a param such as
amount_minor. With no mapping, the arguments are the params. dry_runis not offered through the gateway yet. MCP has no standard way to ask a tool for a dry run.
Addendum, 2026-12-01: HTTP and agent keys#
The gateway now also speaks MCP Streamable HTTP, so remote agents can use it.
Decision: each HTTP client sends its own Riskbound agent key as a Bearer token
on every request, and that key is used for its decisions. The gateway config
lists the agents it serves as { agent, keySha256 }. A request whose key is
missing or not on the list is refused with 401 before any MCP session opens.
A session belongs to the key that opened it. The agent name comes from the
config entry, never from the request.
Why:
- The name is not the agent's to choose. Backend agent keys belong to a tenant, not to one agent name. If the name came from a header, one agent could act as another agent of the same tenant. Over stdio the config fixes the name; the HTTP mode keeps that property.
- Read-only tools need a gate too. They never reach Riskbound, so the gateway must reject unknown callers itself. Checking the hash locally does that without a round trip.
- No secrets in the file. Only hashes of keys are stored, in line with "never read secrets from config files".
Consequences:
- A revoked key still matches its hash. Its checked calls fail at once, because Riskbound rejects the key, but it can list and call read-only tools until it is removed from the config. A backend route that confirms a key is live would close this at session start.
- An operator adds an agent by adding a line to the config and restarting.
- Keys travel in a header. The default host is loopback, and anything wider needs TLS in front.
Addendum, 2026-12-01: live keys and idle sessions#
The first addendum left a gap: a revoked key still matched its hash, so it could list and call read-only tools until someone removed it from the config.
Decision:
- The backend has
GET /v1/auth/key. Any live key may call it. It returns the key's tenant id and role and nothing else. A revoked or unknown key gets 401. - The HTTP gateway calls it before it opens a session. A revoked key is
refused with 401. If Riskbound cannot be reached, or answers anything but a
clear yes, the session is refused with 503. This holds whatever
failModesays: fail-open is a choice about one checked action, not about who may use the gateway. - It checks each open session's key again every
listen.keyCheckIntervalMs(default 60 seconds). A key that is revoked, or that Riskbound cannot vouch for, loses its sessions. Closing a session aborts its running calls: the upstream tool call is cancelled and a wait for approval stops. - A session with no request for
listen.idleTimeoutMs(default 15 minutes) is closed the same way. A call still running, such as one waiting for approval, keeps its session open. An open GET stream does not.
Why:
- Read-only tools are still tools. A lookup can leak customer data. A revoked key should lose it as fast as it loses checked calls.
- Fail closed. A check that cannot reach a clear yes is a no, as for decisions.
- Idle sessions are standing access. Each one holds a key in memory and a slot in the gateway. An agent that comes back opens a new session, and its key is checked again.
Consequences:
- A revoked key keeps working for at most one interval plus one request timeout. Lower the interval to shorten that. Each check is one small request per key, not per session.
- A Riskbound outage now closes HTTP sessions within one interval. Checked calls would fail anyway; read-only calls now stop too.
- Stdio mode does not check the key: the operator who starts the gateway holds the key, and its checked calls fail at once when it is revoked.
Addendum, 2026-12-02: the gateway's own key#
The gateway no longer asks for decisions with an agent's key. It uses its
own gateway key, in both modes, and Riskbound trusts via: "gateway" only
from such a key. Over HTTP each agent still sends its own key, which is
checked as above and says who is calling. The gateway also checks its own
key at start-up, before each session, and on every key check interval. See
ADR 0012.