Onboarding guide
4. Quickstart with the gateway
Use the gateway when your agent calls its tools over MCP (Model Context Protocol). You do not change the agent's code. You change one entry in its MCP configuration.
agent --MCP--> gateway --MCP--> your real tool server
|
+--> Riskbound: allow, ask a human, or blockThe gateway is an MCP server that starts your real tool server and stands in front of it. Before each tool call, it asks Riskbound:
| Answer | What the agent sees |
|---|---|
| allow | The tool's real result |
| ask a human | The call waits until a person approves or rejects it |
| block | An error result that says why. The tool is never called |
Listing tools, resources and prompts passes straight through. The gateway runs in your systems, next to your agent.
Before you begin#
- Steps 1 to 3 of the SDK quickstart: keys, agent and policy. They are the same for the gateway.
- Node.js 22 or later.
- The shared Riskbound code. The gateway is not on npm yet.
Build the SDK first, because the gateway uses it, then the gateway:
cd /path/to/riskbound/sdk && npm install && npm run build
cd /path/to/riskbound/gateway && npm install && npm run buildThe gateway is now at /path/to/riskbound/gateway/dist/main.js.
Step 1. Write the gateway config#
This guide uses a small stand-in payments tool server that comes with the
gateway, examples/payments-server.ts. It has two tools:
list_orders, a lookup, and refund_payment, which takes order_id,
amount_cents and currency. In real use, put your own tool server's
command in upstream.
Save this as gateway.json:
{
"agent": "support-bot",
"riskbound": {
"baseUrl": "http://localhost:8200",
"approvalTimeoutMs": 300000
},
"upstream": {
"command": "node",
"args": ["--import", "tsx", "examples/payments-server.ts"],
"cwd": "/path/to/riskbound/gateway",
"env": { "PAYMENTS_API_KEY": "${PAYMENTS_API_KEY}" }
},
"readOnlyTools": ["list_orders"],
"allowedTools": ["list_orders", "refund_payment"],
"tools": {
"refund_payment": {
"tool": "refund",
"params": { "amount_minor": "amount_cents" }
}
}
}Set baseUrl to your Riskbound URL. What each part does:
| Field | What it does |
|---|---|
agent | The registered agent the gateway asks for |
riskbound.baseUrl | Your Riskbound URL. The agent key is read from the RISKBOUND_API_KEY environment variable, never from this file |
riskbound.approvalTimeoutMs | How long a call waits for a person. Default 15 minutes |
upstream | How to start your real tool server. ${NAME} is read from the gateway's own environment |
readOnlyTools | Tools passed through with no check, and not sent to Riskbound. Keep this to lookups |
allowedTools | Optional. The only tools the agent can see and call. List read-only tools here too. The gateway refuses any other tool without calling it |
tools | Optional. Renames a tool for policy and copies arguments to the param names your policy uses |
The tools entry above is why one policy serves both the SDK and the
gateway. The MCP tool is called refund_payment and takes
amount_cents. Policy sees the tool refund with amount_minor. Without
an entry, a tool is checked under its own name, with its arguments as the
params.
Step 2. Check it before you connect the agent#
This small script connects to the gateway the same way your agent will.
Save it as check-gateway.mjs in the gateway folder, because it uses the
MCP library installed there:
// Connects to the gateway the way your agent will, and makes three calls.
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
const client = new Client({ name: "gateway-check", version: "1.0.0" });
await client.connect(
new StdioClientTransport({
command: "node",
args: ["dist/main.js", "--config", process.argv[2]],
env: {
PATH: process.env.PATH,
RISKBOUND_API_KEY: process.env.RISKBOUND_API_KEY,
PAYMENTS_API_KEY: process.env.PAYMENTS_API_KEY,
},
stderr: "inherit",
}),
);
const text = (r) => r.content.map((c) => c.text).join(" ");
console.log("Tools:", (await client.listTools()).tools.map((t) => t.name));
console.log("Lookup:", text(await client.callTool({ name: "list_orders", arguments: { customer: "cus_42" } })));
for (const cents of [4000, 90000]) {
const r = await client.callTool({
name: "refund_payment",
arguments: { order_id: "ord_3001", amount_cents: cents, currency: "USD" },
});
console.log(`${cents} cents:`, r.isError ? "refused:" : "ok:", text(r));
}
await client.close();Run it with your agent key. PAYMENTS_API_KEY stands in for the tool's
real credential:
cd /path/to/riskbound/gateway
PAYMENTS_API_KEY=demo node check-gateway.mjs /path/to/gateway.jsonYou will see:
[riskbound-gateway] ready: agent "support-bot", upstream "node"
Tools: [ 'list_orders', 'refund_payment' ]
Lookup: cus_42: ord_1001, ord_1002, ord_1003
4000 cents: ok: Refunded 40.00 USD for ord_3001
90000 cents: refused: Riskbound blocked this action (refund-hard-cap). The tool was not called.The lookup was not checked, because it is read-only. The $40 refund was allowed. The $900 refund was blocked, and the tool never ran. Both refunds are in the dashboard under Decisions.
Step 3. Point your agent at the gateway#
In your agent's MCP configuration, replace the entry that starts your tool server with one that starts the gateway. Most MCP clients take an entry like this:
{
"mcpServers": {
"payments": {
"command": "node",
"args": ["/path/to/riskbound/gateway/dist/main.js", "--config", "/path/to/gateway.json"],
"env": {
"RISKBOUND_API_KEY": "rb_agent_...",
"PAYMENTS_API_KEY": "..."
}
}
}
}The agent sees the same tools as before. Nothing else changes.
Step 4. Move the tool credentials into the gateway#
This step is what makes the gateway a control and not a suggestion.
- Find every place the agent can read the tool's credential: its environment, its config files, its secret store access.
- Remove the credential from all of them.
- Give it only to the gateway: in the gateway entry's
env, as above, or in the environment of the service that runs the gateway. - Name it in
upstream.envingateway.json. The gateway starts the tool server with a small environment plus only whatupstream.envnames, so nothing else leaks through. - Check: the agent should now fail if it tries to call the tool's API directly.
If the agent can still reach the tool with its own copy of the key, it can go around Riskbound.
Step 5. Decide which tools are read-only#
Calls to readOnlyTools are passed through with no check and are not
sent to Riskbound. That is fast, and it keeps lookup data with you. But a
read-only tool has no rules, no limits and no record.
- List only tools that cannot change anything: lookups, searches, reads.
- If a "read" can return data the agent should not see, leave it checked.
- Use
allowedToolsto hide every tool you have not thought about yet.
Approvals through the gateway#
For ask_human, the gateway holds the call while it waits. If the agent's
MCP client asks for progress updates, the gateway sends "Waiting for
approval" each time it checks. When a person approves, the tool runs and the agent
gets the real result. A rejection, or no answer within
approvalTimeoutMs, gives the agent an error result, and the tool is not
called. MCP clients have their own request timeouts. Set
approvalTimeoutMs below your client's timeout, or the client may give up
first.
Remote agents: the gateway over HTTP#
The gateway can also run as a service that remote agents reach over MCP
Streamable HTTP. One gateway can serve several agents. Start from the same
config, remove the top-level agent, and add a listen block:
{
"riskbound": { "baseUrl": "http://localhost:8200" },
"upstream": {
"command": "node",
"args": ["--import", "tsx", "examples/payments-server.ts"],
"cwd": "/path/to/riskbound/gateway",
"env": { "PAYMENTS_API_KEY": "${PAYMENTS_API_KEY}" }
},
"readOnlyTools": ["list_orders"],
"tools": {
"refund_payment": {
"tool": "refund",
"params": { "amount_minor": "amount_cents" }
}
},
"listen": {
"host": "127.0.0.1",
"port": 8310,
"path": "/mcp",
"agents": [{ "agent": "support-bot", "keySha256": "<hash of the agent key>" }]
}
}Each agent sends its own agent key as Authorization: Bearer rb_agent_....
The gateway stores only a hash of each key. Print the hash with:
printf %s "$RISKBOUND_API_KEY" | node /path/to/riskbound/gateway/dist/main.js hash-keyA request with an unknown key gets 401. The gateway also asks Riskbound
whether each key is still live, before it opens a session and every minute
after, so a revoked key stops working. GET /health needs no key and says
whether the gateway and its tool server are up:
curl -s http://127.0.0.1:8310/health{"status":"ok","upstream":"connected"}Put TLS in front of the gateway before it listens on anything other than
127.0.0.1. The full list of options is in the
gateway README.
Good to know#
- Coming soon: a separate gateway key. Today the gateway asks Riskbound with an agent key. With a gateway key, Riskbound will know for certain that a call came through the gateway, which the risk score counts.
- Dry runs do not work through the gateway. MCP has no standard way to ask a tool for one.
- The gateway answers the agent as soon as the tool returns, and reports the result to Riskbound just after. A failed report is logged and never changes the agent's result.
Next: 5. Approvals.