Skip to main content

Overview

The enforce API verifies that an agent’s grant token includes sufficient scope to call a specific tool on a specific connector. It combines JWT verification with manifest-based permission resolution in a single call.

enforce()

Check whether a grant token permits a tool call.

Parameters: EnforceOptions

string
required
The JWT grant token issued by Grantex. Decoded and verified inline.
string
required
The connector name to check against (e.g., "salesforce", "s3", "jira"). Must match a loaded manifest.
string
required
The tool name to check (e.g., "delete_contact", "create_lead"). Must be declared in the connector’s manifest.
number
Optional amount for capped scopes. When the token includes a capped scope like tool:stripe:write:*:capped:500, pass the transaction amount to check against the cap.

Response: EnforceResult

boolean
true if the tool call is permitted by the token’s scopes.
string
Human-readable reason when allowed is false. Empty string when allowed.
string
The grant ID extracted from the JWT grnt (or jti) claim.
string
The agent DID extracted from the JWT agt claim.
string[]
All scopes from the JWT scp claim.
string
The resolved permission level for this tool from the manifest ("read", "write", "delete", or "admin").
string
The connector name that was checked.
string
The tool name that was checked.

Example

Capped Scopes

When a token includes a capped scope, pass the amount to enforce against the cap:

loadManifest()

Load a single tool manifest into the client. Must be called before enforce() for the corresponding connector.

Example


loadManifests()

Load multiple tool manifests at once.

Example


ToolManifest

A manifest declares the permission level required for each tool on a connector.

Constructor

getPermission()

Look up the required permission for a tool. Returns undefined if the tool is not in the manifest.

addTool()

Add a tool to an existing manifest. Useful for extending pre-built manifests with custom tools.

fromJSON()

Create a manifest from a plain JSON object (e.g., loaded from a file):

Permission

An enum representing the four permission levels in the hierarchy.
Higher levels subsume all lower levels: admin > delete > write > read.

permissionCovers()

Check whether a granted permission level covers a required permission level.

Example


wrapTool()

Wrap a LangChain StructuredTool so that enforcement runs automatically before every invocation.

Example


enforceMiddleware()

Express middleware that enforces scope on every request to a route.

Example


Last modified on April 4, 2026