Install
Scope-Enforced Tools
Create Vercel AI SDK tools with Grantex authorization. Scope is checked at construction time — if the token is missing the required scope,createGrantexTool throws immediately:
Inspect Grant Scopes
UsegetGrantScopes to check what scopes a token has before creating tools:
Audit Logging
Wrap tools withwithAuditLogging to log every invocation to the Grantex audit trail:
API Reference
createGrantexTool(options)
| Option | Type | Description |
|---|---|---|
name | string | Tool name |
description | string | Tool description |
parameters | z.ZodTypeAny | Zod schema for tool arguments |
grantToken | string | Grantex JWT from token exchange |
requiredScope | string | Scope required — checked at construction time |
execute | (args, options) => Promise<Result> | Tool implementation |
GrantexScopeError if scope is missing.
getGrantScopes(grantToken)
Returns string[] of scopes from the token’s scp claim (offline).
withAuditLogging(tool, client, options)
| Option | Type | Description |
|---|---|---|
agentId | string | Agent ID for audit attribution |
grantId | string | Grant ID for the session |
toolName | string? | Override tool name in audit entries |
GrantexScopeError
| 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.0ai>= 4.0.0 (Vercel AI SDK)zod>= 3.0.0