Enforce scoped permissions on Claude tool calls. JWKS-backed JWT verification, scope enforcement, and audit logging for Anthropic SDK apps.
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.
Configured tool wrappers verify the agent JWT and required scope against JWKS before execution. Optional callbacks can record selected tool events.
npm install @grantex/anthropic — wraps Anthropic tool definitions with authorization.
Use createGrantexTool() to define tools with required scopes and JSON Schema input.
tool.definition is type-compatible with client.messages.create({ tools }).
Use GrantexToolRegistry or handleToolCall() at configured tool boundaries, and attach an audit callback when records are required.
Optional audit callbacks record tool calls; grant lifecycle remains centrally managed.
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,
});
Type-compatible with client.messages.create(). tool.definition drops in directly.
The JWT signature and claims are verified with JWKS before the scp claim is enforced.
GrantexToolRegistry manages multiple tools and dispatches tool_use blocks by name.
When configured, withAuditLogging() and handleToolCall() can record success and failure events with grant context.
Typed error with requiredScope and grantedScopes for clean error handling.
Enforce per-agent spending limits in the trusted service before executing a metered action.
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.
Follow the integration guide and verify the package version before deployment. Apache 2.0.