Skip to content

Connect over MCP

This page connects a real MCP client to the sandbox. The commands run each client in a container, so you need only Docker. Start the sandbox first and work in its directory.

Start from a clean sandbox, in its directory:

./sandbox destroy
./sandbox up
AGENT=$(./sandbox token agent)

Each intent the agent is granted becomes one tool, with the dot replaced by a hyphen: procurement.get_budget becomes procurement-get_budget. Three tools are always present:

Tool Purpose
sefra-get_execution Read the current result of one of your executions
sefra-cancel_execution Cancel one of your executions while it awaits approval
sefra-submit_plan Submit 2 to 16 steps that succeed or are undone together

A tool’s arguments are:

Argument Required Meaning
input Yes The intent’s input, checked against its schema
idempotency_key For writes One key per business action, reused on retry
rationale No Why the agent is asking. Shown to approvers as unverified, and never affects a decision

Save a small agent. It lists its tools, reads a budget and places an order:

cat > agent.py <<'EOF'
import asyncio, json, os, uuid

import httpx2
from mcp import Client
from mcp.client.streamable_http import streamable_http_client


def result_of(response):
    return response.structured_content or json.loads(response.content[0].text)


async def main():
    headers = {"Authorization": "Bearer " + os.environ["SEFRA_TOKEN"]}
    async with httpx2.AsyncClient(headers=headers, timeout=60) as http:
        async with Client(streamable_http_client(os.environ["SEFRA_MCP_URL"], http_client=http)) as client:
            tools = await client.list_tools()
            print("tools:", ", ".join(sorted(t.name for t in tools.tools)))

            budget = result_of(await client.call_tool(
                "procurement-get_budget", {"input": {"department": "it-ops"}}))
            print("budget:", budget["steps"][0]["output"])

            order = result_of(await client.call_tool("procurement-create_purchase_order", {
                "input": {"vendor_id": "v_1001", "sku": "MONITOR-27", "quantity": 2,
                          "unit_price_minor": 30000, "currency": "EUR", "department": "it-ops"},
                "idempotency_key": "agent-" + uuid.uuid4().hex,
                "rationale": "Monitors for two new hires",
            }))
            print("order:", order["status"], order["steps"][0].get("output"))


asyncio.run(main())
EOF

Run it on the sandbox’s network:

docker run --rm --network sefra-sandbox_default \
  -e SEFRA_MCP_URL=http://sefra:8080/mcp -e SEFRA_TOKEN="$AGENT" \
  -v "$PWD/agent.py:/app/agent.py:ro" python:3.14-slim \
  sh -c 'pip install -q --root-user-action=ignore --disable-pip-version-check mcp==2.3.0 && python -I /app/agent.py'
tools: procurement-create_purchase_order, procurement-create_vendor, procurement-get_budget, sefra-cancel_execution, sefra-get_execution, sefra-submit_plan
budget: {'currency': 'EUR', 'remaining_minor': 5000000}
order: succeeded {'po_id': 'po_1', 'total_minor': 60000}

From your own machine, install mcp==2.3.0 and use http://127.0.0.1:18180/mcp as the URL.

The TypeScript client needs one setting, versionNegotiation. Without it, the client uses an older handshake and cannot connect.

cat > agent.mjs <<'EOF'
import { randomUUID } from 'node:crypto';
import { Client, StreamableHTTPClientTransport } from '@modelcontextprotocol/client';

const client = new Client({ name: 'my-agent', version: '1.0.0' }, { versionNegotiation: { mode: 'auto' } });
await client.connect(new StreamableHTTPClientTransport(new URL(process.env.SEFRA_MCP_URL), {
  requestInit: { headers: { Authorization: `Bearer ${process.env.SEFRA_TOKEN}` } },
}));

const { tools } = await client.listTools();
console.log('tools:', tools.map((t) => t.name).sort().join(', '));

const order = await client.callTool({
  name: 'procurement-create_purchase_order',
  arguments: {
    input: { vendor_id: 'v_1001', sku: 'KEYBOARD', quantity: 3, unit_price_minor: 8000, currency: 'EUR', department: 'it-ops' },
    idempotency_key: `agent-${randomUUID()}`,
    rationale: 'Keyboards for the new office',
  },
});
console.log('order:', order.structuredContent.status);
await client.close();
EOF
docker run --rm --network sefra-sandbox_default \
  -e SEFRA_MCP_URL=http://sefra:8080/mcp -e SEFRA_TOKEN="$AGENT" \
  -v "$PWD/agent.mjs:/app/agent.mjs:ro" -w /app node:24-alpine \
  sh -c 'npm install --silent --no-audit --no-fund --ignore-scripts @modelcontextprotocol/client@2.4.0 && node agent.mjs'

The MCP Inspector’s command line is a quick way to see what a token can reach:

docker run --rm --network sefra-sandbox_default node:24-alpine \
  npx -y @modelcontextprotocol/inspector@2.16.0 --cli http://sefra:8080/mcp \
  --protocol-era modern --format json -q \
  --header "Authorization: Bearer $AGENT" --method tools/list \
  | jq -r '.result.tools[].name // .tools[].name'

Every tool returns the same structure in structuredContent, and again as JSON in a text block. When Sefra refuses a request or an execution fails, the MCP result has isError: true, so the model can read the reason and correct itself. See Handle every outcome.

A tool that the agent is not granted is reported as an unknown tool. Sefra does not reveal whether it exists.