Skip to content

Tutorials

One runnable example per aspect of the code. Each prints what it is doing, step by step, and ends with OK. The test suite runs all of them, so what you read here is what the code does today.

bash
node examples/01-keys-and-signing.ts

Suggested reading order is the numbering. Output lands in examples-out/, which is gitignored.

#aspectfileyou will seesource
01identities and signatures01-keys-and-signing.tskey generation, keyids, a DSSE envelope, verification with the public key, a tampered payload rejectedsrc/crypto.ts
02delegated authority02-delegation-grant.tsa principal signs a grant, a stranger's key is rejected, validity windows, scopessrc/delegation.ts
03policies03-policies.tsa Cedar policy evaluated against eight calls: reads, limits, gateway facts versus agent claims, forbid, floats, default deny, the policy digestsrc/policy.ts
04the transparency log04-merkle-log.tsappends, inclusion proofs, recomputing the root from the file, an edited line detectedsrc/log.ts
05the gateway05-gateway.tsan MCP client connects to the gateway over stdio, sees filtered tools, gets one execution and one denial with receipt idssrc/gateway.ts, src/cli.ts
06verification and auditing06-verify-and-audit.tsthe full check list, with and without a log copy, a tampered receipt, an untrusted key, checks as data for CIsrc/verify.ts
07the in-process SDK07-sdk-wrap.tswrap a function, allowed and denied and errored calls, the decide/record primitives, an SDK receipt's reportsrc/sdk/index.ts
08Claude Code and Agent SDK hooks08-claude-code-hook.tsthe settings.json entry, PreToolUse allow and deny, PostToolUse, the real command over stdin, Agent SDK hookssrc/sdk/claude.ts
09OpenAI Agents SDK09-openai-agents.tsa real Runner with a scripted model, enforcement via wrapped tools, what the model sees on deny, record-only via lifecycle eventssrc/sdk/openai-agents.ts
10Vercel AI SDK10-vercel-ai.tsa real generateText loop over the SDK's mock model, a denial as a tool-error partsrc/sdk/vercel-ai.ts
11LangChain11-langchain.tsthe callback handler, tool_call ids, enforcement by wrapping the functionsrc/sdk/langchain.ts
12inside a receipt12-read-a-receipt.tsthe bundle's three parts, the in-toto statement, every predicate field with its provenance, the tree headsrc/receipt.ts
13a log run by someone else13-remote-log.tsthe reference log server on a free port, an SDK config that logs to it, a tree head signed by the log's key, verification failing without that key and passing with it, the root endpoint, a refused tokensrc/log-sink.ts
14proving history was not rewritten14-audit-history.tsthree receipts and a kept tree head, a consistency proof that passes, the operator rewriting one leaf and appending a fourth call, the audit failing while the fourth receipt still verifies alonesrc/log.ts, src/verify.ts
15agents in other languages15-sidecar.tsthe sidecar on a free port, a client written as a Python or Go program would write it: decide, run, record; a denial recorded without running the tool; both receipts verifiedsrc/sidecar.ts
16consequential tools, committed first16-precommit.tsa refund named in precommit: the authorization leaf before the receipt leaf, the five authorization checks in the report, and the same call withheld when the log refusessrc/gateway.ts, src/issue.ts, src/verify.ts
17a REST API as an upstream17-rest-upstream.tsa stand-in payments API described as two tools, the token from the environment, a refund allowed on the gateway's own lookup and one denied before reaching the API, the receipt verifiedsrc/rest.ts, src/gateway.ts
18OpenTelemetry export18-opentelemetry.tsa stand-in OTLP collector, otel in the config, one span per receipt with the receipt id as trace id, the collector going away and the next receipt still issuedsrc/otel.ts, src/issue.ts

How policies are defined, in one paragraph

A policy is a Cedar file. The gateway turns each tool call into a Cedar request: the principal is Agent::"<agent id from the grant>", the action and resource are the tool name, and the context has three parts. context.args is what the agent sent and is only ever claimed. context.facts is what the gateway fetched itself before deciding, configured per tool in gateway.json, and is observed. context.grant is the signed delegation and is attested. Nothing matches means deny. A forbid beats every permit. An evaluation error, such as a missing attribute or a float, is a deny and is written into the receipt. The receipt also carries the sha256 of the policy text, so a verifier knows exactly which policy decided. Example 03 runs one; policies.md has nine more, each executed by the test suite.

Where each guide goes deeper

  • usage.md: gateway setup and wiring into hosts
  • sdk.md: the interceptor and every adapter
  • policies.md: the Cedar mapping, evaluation rules, tested examples, gotchas
  • verification.md: every check and what a verified receipt does and does not prove