RiskboundDocs

Examples

MCP gateway example

An ordinary MCP tool server for a fake payments API (payments-server.ts), with the Riskbound gateway in front of it. The tool server has no Riskbound code. The only change is in the MCP client's config: it starts the gateway, and the gateway starts the tool server.

 MCP client  --stdio-->  gateway  --stdio-->  payments-server.ts
                            |
                            +--> Riskbound: allow, ask a human, or block

gateway.json says how:

  • upstream starts the tool server and hands it PAYMENTS_API_KEY. The agent never holds that credential.
  • readOnlyTools lets list_orders through without a check.
  • tools.refund_payment checks the tool under the policy name refund and copies amount_cents into the amount_minor param the policy reads.

Run it#

Start the local stack and get a gateway key first: see ../README.md.

Build the SDK and the gateway once, from the repo root:

bash
cd sdk && npm install && npm run build && cd ..
cd gateway && npm install && npm run build && cd ..

Then, from this folder. client.ts plays the part of the agent's MCP client:

bash
cd examples/mcp-gateway
npm install
PAYMENTS_API_KEY=demo RISKBOUND_API_KEY=$RISKBOUND_GATEWAY_KEY npm start

You see:

[riskbound-gateway] ready: agent "support-bot", upstream "node"
Tools the agent sees: [ 'list_orders', 'refund_payment' ]
Lookup (read-only, not checked): cus_42: ord_1001, ord_1002, ord_1003
$40 refund: Refunded 40.00 USD on ord_1001
$900 refund: refused - Riskbound blocked this action (refund-hard-cap). The tool was not called.

To see a refund wait for a person, run this and approve it as ../README.md shows:

bash
ASK_FOR_APPROVAL=1 PAYMENTS_API_KEY=demo RISKBOUND_API_KEY=$RISKBOUND_GATEWAY_KEY npm start

Use it from a real MCP client#

Point the client at the gateway instead of the tool server. For Claude Desktop, Cursor and most clients, the server entry looks like this. Use absolute paths:

json
{
  "mcpServers": {
    "payments": {
      "command": "node",
      "args": [
        "/path/to/riskbound/gateway/dist/main.js",
        "--config",
        "/path/to/riskbound/examples/mcp-gateway/gateway.json"
      ],
      "env": { "RISKBOUND_API_KEY": "rb_gateway_...", "PAYMENTS_API_KEY": "demo" }
    }
  }
}

gateway.json starts the tool server with a relative path, which works when the gateway runs from this folder, as client.ts does. A client may start it from anywhere, so in a copy for a real client add "cwd": "/path/to/riskbound/examples/mcp-gateway" to upstream.

More about the gateway, including HTTP mode for remote agents, is in ../../gateway/README.md.