Install
Scope-Enforced Tools
Create Anthropic tool definitions with built-in Grantex scope enforcement:scp claim is decoded from the JWT without any network call. If the required scope is missing, execute() throws a GrantexScopeError before your function runs.
Tool Registry
UseGrantexToolRegistry to manage multiple tools and dispatch tool_use blocks by name:
Inspect Grant Scopes
Decode the scopes from a grant token offline:Audit Logging
Wrap a tool
Handle a tool_use block directly
API Reference
createGrantexTool(options)
| Option | Type | Description |
|---|---|---|
name | string | Tool name (matches ^[a-zA-Z0-9_-]+$) |
description | string | Description shown to the model |
inputSchema | JsonSchema | JSON Schema for tool input |
grantToken | string | Grantex JWT from token exchange |
requiredScope | string | Scope required to invoke this tool |
execute | (args: T) => Promise<unknown> | Tool implementation |
{ definition, execute }.
GrantexToolRegistry
| Method | Description |
|---|---|
register(tool) | Register a tool (chainable) |
definitions | All registered Anthropic tool definitions |
execute(block) | Execute a tool from a tool_use block |
withAuditLogging(tool, client, options)
Returns a wrapped GrantexTool that automatically logs success/failure to the audit trail on every execute() call.
| Option | Type | Description |
|---|---|---|
agentId | string | Agent ID for audit attribution |
agentDid | string | Agent DID (e.g. did:key:z6Mk...) |
grantId | string | Grant ID for the session |
principalId | string | Principal ID that granted authorization |
handleToolCall(tool, block, client, options)
Same options as withAuditLogging. Executes the tool with block.input and logs the result.
getGrantScopes(grantToken)
Returns string[] — the scopes from the token’s scp claim.
GrantexScopeError
Thrown when a grant token is missing a required scope.
| Property | Type | Description |
|---|---|---|
requiredScope | string | The scope that was required |
grantedScopes | string[] | The scopes the token actually has |
Requirements
- Node.js 18+
@grantex/sdk>= 0.1.0@anthropic-ai/sdk>= 0.30.0