createGrantexTool()for an exact required-scope check on one configured function.Grantex.wrapTool()for manifest-basedread,write,delete, andadminpermission levels.
Implementation snapshot, updated July 12, 2026: these examples target
@grantex/langchain@0.1.7, @grantex/sdk@0.3.13, and the repository’s
resolved @langchain/core@1.2.2. The adapter declares
@langchain/core >=0.3.0, but that range is not a promise of compatibility
with every future LangChain package or agent runtime.Does LangChain have permissions for agent tools?
A LangChain agent can choose among the tools its host application registers. LangChain also offers callbacks, tracing, and extension points that applications can use to build controls. LangChain does not, by itself, understand a Grantex grant token, principal, scope, or revocation state. In a typical unwrapped tools array:- Availability: which tools the application exposes.
- Authorization: which exposed calls a verified grant permits.
- Audit: which configured execution events are recorded.
Install the tested package snapshot
Add the integration to an existing LangChain application with exact versions:langchain packages separately for the agent runtime you use.
Add an exact scope check with createGrantexTool
createGrantexTool() returns a LangChain DynamicTool. On invocation it verifies the configured grant token and requires one exact scope string before calling func.
contacts:read but not contacts:delete causes the delete wrapper to throw before deleteContact() runs.
The wrapper delegates to verifyGrantToken() in @grantex/sdk. It checks:
- RS256 signature against the configured JWKS.
- Expected issuer and JWT expiry.
- Optional
audienceand clock tolerance. - Exact membership of
requiredScopein the verifiedscpclaim.
Configured-tool boundary
createGrantexTool() protects only its configured func. It does not discover or rewrite other tools. Wrap each protected function and pass the protected instances, not unwrapped equivalents, to the agent.
The grantToken option is a string captured by the tool. Build request-, principal-, or session-specific tools when different users need different grants. Do not share one token-bearing tool instance across unrelated principals.
This path uses exact scope strings. It does not apply the manifest hierarchy below.
Add manifest-based permissions with wrapTool
For connector-style tools, @grantex/sdk maps tool names to permission levels. loadManifest() stores a mapping, and wrapTool() applies it when the returned object’s invoke() runs.
gx.enforce() or the object returned by gx.wrapTool(). Keep original unwrapped tools out of the executable tool list.
The token getter is synchronous. If the application refreshes a token, update the state read by the getter before the next invocation.
Permission hierarchy for manifest enforcement
For connector
crm, tool:crm:write can cover search_contacts and create_contact, but not delete_contact or export_all.
Unknown connectors and tools are denied in the default strict mode. This hierarchy applies to gx.enforce() and gx.wrapTool(), not to createGrantexTool().
Use the pre-built manifests that exist
@grantex/sdk@0.3.13 exports 53 manifests. Salesforce, HubSpot, Jira, and Stripe are included:
Define a custom manifest
Add the optional Grantex audit callback
GrantexAuditHandler writes through client.audit.log() only where the callback is attached.
0.1.7 behavior is specific:
handleToolStart()writestool:<toolName>withstatus: "success"when invocation starts. That is not completion proof.handleToolError()writes generictool:errorwithstatus: "failure".- The constructor decodes
grnt, falling back tojti, for attribution. That decode is not authorization. - Tool input and error text enter audit metadata. Apply an appropriate sensitive-data logging policy.
- Calls outside the callback-enabled executor or chain are not recorded by this handler.
Put the controls into a LangChain agent safely
For the agent-construction API used by your pinned LangChain application:- Obtain a grant for the correct principal, agent, audience, and scopes.
- Build
createGrantexTool()orwrapTool()protected instances. - Pass only protected instances for actions requiring Grantex authorization.
- Attach
GrantexAuditHandleronly if its current event and metadata behavior fits your policy. - Test permitted, missing-scope, malformed, expired, and bypass cases.
- Add current revocation-state handling if expiry alone is insufficient.
Which LangChain permission approach should you use?
Validation checklist
- The agent receives protected tool objects, not originals.
- Each protected function has the intended exact scope or manifest entry.
- Token issuer and audience match the receiving service.
- Missing, expired, malformed, and wrongly scoped tokens fail before the underlying function.
- Manifest names match the actual LangChain tool names.
- Audit callbacks do not capture prohibited data.
- Revocation freshness and key rotation meet the threat model.
- The pinned LangChain and Grantex versions pass application integration tests.