Skip to main content

What it does

This example demonstrates the @grantex/anthropic integration by building scope-enforced tools for Claude:
  1. Register an agent and obtain a grant token via the sandbox flow
  2. Create scoped tools using createGrantexTool with JSON Schema (calendar:read, email:send)
  3. Use GrantexToolRegistry to manage tools and dispatch tool_use blocks
  4. Invoke tools via client.messages.create() (if ANTHROPIC_API_KEY is set) or directly
  5. Demonstrate GrantexScopeError — attempting to execute a tool with storage:delete (a scope not in the grant) throws a GrantexScopeError with requiredScope and grantedScopes properties
  6. Inspect scopes offline using getGrantScopes() to decode the JWT without a network call
  7. Inspect the audit trail to see the logged actions

Prerequisites

  • Node.js 18+
  • Docker (Docker Desktop or Docker Engine with Compose)

Run

Start the local Grantex stack from the repository root:
In a separate terminal, run the example:
To use Claude for real tool use instead of direct invocation, set ANTHROPIC_API_KEY:

Expected output

Without ANTHROPIC_API_KEY (direct invocation):

Environment variables

Source code

The full source is in examples/anthropic-tool-use/src/index.ts.
Last modified on March 30, 2026