Working code for agents that call tools and models through Magertron™ — every call authorized against the agent and the person it acts for, metered, and audited. Your agent holds no vendor API keys.
Swipe to see the full diagram →
Trade your agent's token for a five-minute Magertron™ token. Cache it; refresh before it expires.
Ask what may be called. Each tool comes with the platform's verdict for the principal asking.
JSON-RPC over HTTP, with an Idempotency-Key so a retry is never billed twice.
mc, _ := magertron.New(magertron.Options{GatewayURL: "https://mcp.acme.com"}) // 1 · a credential: your agent's token, exchanged for five-minute ones agent := &magertron.Exchange{Client: mc, Subject: magertron.StaticToken(saToken)} // 2 · what may you call? tools, err := mc.Catalog(ctx, agent) // 3 · call it — authorized, metered, audited, and retried safely out, err := mc.CallTool(ctx, agent, tools[0], json.RawMessage(`{"timezone":"UTC"}`)) var r *magertron.Refusal if errors.As(err, &r) && r.Kind == magertron.KindSpendLimit { // a human must lift the limit — tell someone, do not retry }
# 1 · trade the long-lived token for a five-minute one TOKEN=$(curl -s -X POST "$GW/api/v1/token/exchange" -H 'Content-Type: application/json' \ -d "{\"grant_type\":\"urn:ietf:params:oauth:grant-type:token-exchange\", \"subject_token\":\"$SA_TOKEN\", \"subject_token_type\":\"urn:ietf:params:oauth:token-type:jwt\"}" \ | python3 -c 'import sys,json; print(json.load(sys.stdin)["access_token"])') # 2 · what may you call? curl -s "$GW/api/v1/portal/catalog" -H "Authorization: Bearer $TOKEN" # 3 · call a tool (after initialize — see the guide, §3) curl -s -X POST "$GW/mcp/mcp-prod/time/" \ -H "Authorization: Bearer $TOKEN" -H "Idempotency-Key: $(uuidgen)" \ -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' \ -d '{"jsonrpc":"2.0","id":2,"method":"tools/call", "params":{"name":"get_system_time","arguments":{"timezone":"UTC"}}}'
// Acting for a person: the subject is the PERSON, the actor is YOUR agent. forJane := &magertron.Exchange{ Client: mc, Subject: magertron.StaticToken(janeToken), // who it is FOR Actor: magertron.StaticToken(saToken), // who is ACTING } // "What can Jane do?" — asked with Jane's credential alone tools, err := mc.Catalog(ctx, &magertron.Exchange{Client: mc, Subject: magertron.StaticToken(janeToken)}) // Allowed only where BOTH Jane and the agent are permitted. // Billed to Jane, with the agent shown alongside: "jane · via support-agent". out, err := mc.CallTool(ctx, forJane, tool, args)
No identity provider needed. An administrator creates the service account — in the console, through SCIM or with Terraform — and Magertron™ signs its token.
Already on Auth0, Entra ID or another OIDC directory? Your agent gets a token from it with client credentials, and Magertron™ exchanges it.