Anthropic + Grantex

Authorization for Anthropic SDK Tool Use

Enforce scoped permissions on Claude tool calls. JWKS-backed JWT verification, scope enforcement, and audit logging for Anthropic SDK apps.

The Problem

Without Grantex

Your Claude-powered agents call tools with no authorization layer. Any tool can be invoked with full access. No scoping, no consent, no audit trail of what the agent did.

With Grantex

Configured tool wrappers verify the agent JWT and required scope against JWKS before execution. Optional callbacks can record selected tool events.

How Grantex Works with the Anthropic SDK

Install the integration

npm install @grantex/anthropic — wraps Anthropic tool definitions with authorization.

Create scoped tools

Use createGrantexTool() to define tools with required scopes and JSON Schema input.

Pass tools to Claude

tool.definition is type-compatible with client.messages.create({ tools }).

Dispatch tool_use blocks

Use GrantexToolRegistry or handleToolCall() at configured tool boundaries, and attach an audit callback when records are required.

Record configured tool calls

Optional audit callbacks record tool calls; grant lifecycle remains centrally managed.

Quick Start

npm install @grantex/anthropic @grantex/sdk
import Anthropic from '@anthropic-ai/sdk';
import { createGrantexTool, GrantexToolRegistry } from '@grantex/anthropic';

const client = new Anthropic();

const readFile = createGrantexTool({
  name: 'read_file',
  description: 'Read a file from disk',
  inputSchema: {
    type: 'object',
    properties: { path: { type: 'string' } },
    required: ['path'],
  },
  grantToken,
  requiredScope: 'file:read',
  execute: async ({ path }) => fs.readFile(path, 'utf-8'),
});

const response = await client.messages.create({
  model: 'claude-sonnet-4-6',
  max_tokens: 1024,
  tools: [readFile.definition],
  messages,
});

Why Grantex for Anthropic SDK

Anthropic SDK Native

Type-compatible with client.messages.create(). tool.definition drops in directly.

Verified Scope Checks

The JWT signature and claims are verified with JWKS before the scp claim is enforced.

Tool Registry

GrantexToolRegistry manages multiple tools and dispatches tool_use blocks by name.

Audit Logging

When configured, withAuditLogging() and handleToolCall() can record success and failure events with grant context.

GrantexScopeError

Typed error with requiredScope and grantedScopes for clean error handling.

Budget Controls

Enforce per-agent spending limits in the trusted service before executing a metered action.

Verification, revocation, and audit boundary

This integration enforces authorization only where its wrapper or middleware is installed. Local JWT verification checks signatures and claims after JWKS retrieval; it does not prove current revocation unless the verifier performs an online state check or synchronizes revocation data.

Token verification does not create a consent record or prove that a tool executed. Use the configured authorization flow for grant decisions and add an audit integration at the execution boundary when action records are required.

Ready to secure your Anthropic SDK agents?

Follow the integration guide and verify the package version before deployment. Apache 2.0.