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
| Parameter | Type | Required | Description |
|---|---|---|---|
grant_token | str | Yes | The JWT grant token issued by Grantex. Decoded and verified inline. |
connector | str | Yes | The connector name to check against (e.g., "salesforce", "s3"). Must match a loaded manifest. |
tool | str | Yes | The tool name to check (e.g., "delete_contact", "create_lead"). Must be declared in the connector’s manifest. |
amount | float | None | No | 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
| Field | Type | Description |
|---|---|---|
allowed | bool | True if the tool call is permitted by the token’s scopes. |
reason | str | Human-readable reason when allowed is False. Empty string when allowed. |
grant_id | str | The grant ID extracted from the JWT grnt (or jti) claim. |
agent_did | str | The agent DID extracted from the JWT agt claim. |
scopes | list[str] | All scopes from the JWT scp claim. |
permission | str | The resolved permission level for this tool from the manifest ("read", "write", "delete", or "admin"). |
connector | str | The connector name that was checked. |
tool | str | The tool name that was checked. |
Example
Capped Scopes
When a token includes a capped scope, pass theamount to enforce against the cap:
load_manifest()
Load a single tool manifest into the client. Must be called beforeenforce() for the corresponding connector.
Example
load_manifests()
Load multiple tool manifests at once.Example
ToolManifest
A manifest declares the permission level required for each tool on a connector.Constructor
get_permission()
Look up the required permission for a tool. ReturnsNone if the tool is not in the manifest.
add_tool()
Add a tool to an existing manifest. Useful for extending pre-built manifests with custom tools.from_file()
Create a manifest from a JSON file on disk:from_dict()
Create a manifest from a Python dictionary:Permission
A class representing the four permission levels in the hierarchy.admin > delete > write > read.
covers()
Check whether this permission level covers a required permission level:is_valid()
Check whether a string is a valid permission level:wrap_tool()
Wrap a LangChainStructuredTool so that enforcement runs automatically before every invocation.
Example
FastAPI Integration
UseGrantexAuth from grantex_fastapi as a FastAPI dependency for automatic enforcement on tool execution routes:
Related
- Scope Enforcement guide — end-to-end walkthrough with framework integrations
- TypeScript SDK enforce() — TypeScript API reference
- Tool Manifests concept — permission hierarchy and scope format
- CLI enforce test — dry-run enforcement from the command line