Install
Scope-Enforced Tools
Create Anthropic tool definitions with built-in Grantex scope enforcement:execute() verifies the token signature and claims with verifyGrantToken() before checking its verified scp claim. The verifier may contact its configured JWKS endpoint to resolve keys, so that endpoint must be reachable. Invalid tokens and missing scopes fail 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 without verification. Use this only for display or debugging; authorization decisions must use the verified tool wrapper:Audit Logging
Wrap a tool
Handle a tool_use block directly
API Reference
createGrantexTool(options)
Returns
{ definition, execute }.
GrantexToolRegistry
withAuditLogging(tool, client, options)
Returns a wrapped GrantexTool that automatically logs success/failure to the audit trail on every execute() call.
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.
Requirements
- Node.js 18+
@grantex/sdk>= 0.1.0@anthropic-ai/sdk>= 0.30.0