@grantex/anthropic
v0.1.0
Published
Anthropic SDK integration for the Grantex delegated authorization protocol
Maintainers
Readme
@grantex/anthropic
Anthropic SDK integration for the Grantex delegated authorization protocol.
Enforce scopes, log audit trails, and inspect grant tokens when using Claude models with tool use.
Install
npm install @grantex/anthropic @grantex/sdk @anthropic-ai/sdkQuick Start
import Anthropic from '@anthropic-ai/sdk';
import { createGrantexTool } from '@grantex/anthropic';
const client = new Anthropic();
const readFileTool = createGrantexTool({
name: 'read_file',
description: 'Read a file from disk',
inputSchema: {
type: 'object',
properties: { path: { type: 'string' } },
required: ['path'],
},
grantToken: process.env.GRANT_TOKEN!,
requiredScope: 'file:read',
execute: async ({ path }) => fs.readFile(path as string, 'utf-8'),
});
const response = await client.messages.create({
model: 'claude-sonnet-4-6',
max_tokens: 1024,
tools: [readFileTool.definition],
messages: [{ role: 'user', content: 'Read config.json' }],
});
for (const block of response.content) {
if (block.type === 'tool_use') {
const result = await readFileTool.execute(block.input as { path: string });
}
}Features
createGrantexTool()— Wrap any Anthropic tool definition with offline scope enforcementGrantexToolRegistry— Manage multiple tools and dispatchtool_useblocks by namewithAuditLogging()— Wrap tools to automatically log success/failure to the Grantex audit trailhandleToolCall()— Execute a tool from atool_useblock with audit logging in one stepgetGrantScopes()— Decode scopes from a grant token offline
Documentation
Full docs at grantex.dev/integrations/anthropic.
License
Apache-2.0
