CrewAI integration for the Grantex delegated authorization protocol — scope-enforced, audited agent tools
Project description
grantex-crewai
CrewAI integration for the Grantex delegated authorization protocol — scope-enforced, audited agent tools.
Wrap any CrewAI tool with Grantex grant token verification so your agents can only use tools they've been authorized for, with a full audit trail.
Homepage | Docs | Sign Up Free | GitHub
Install
pip install grantex-crewai
You also need CrewAI installed (it's a peer dependency):
pip install crewai
Quick start
from grantex_crewai import create_grantex_tool
from pydantic import BaseModel
# Define the tool's input schema
class FetchParams(BaseModel):
url: str
# Create a scope-enforced tool
tool = create_grantex_tool(
name="fetch_data",
description="Fetches data from the given URL.",
grant_token="eyJhbGciOiJSUzI1NiIs...", # Grantex JWT
required_scope="data:read",
func=lambda url: requests.get(url).text,
args_schema=FetchParams,
)
# Use it in a CrewAI agent — if the token doesn't have
# the "data:read" scope, create_grantex_tool raises immediately
The tool performs an offline scope check at creation time by decoding the JWT's scp claim. No network call is needed — if the required scope is missing, a PermissionError is raised before the tool is ever used.
Audit logging
Wrap any Grantex tool with audit logging to record every invocation to the Grantex audit trail:
from grantex import Grantex
from grantex_crewai import create_grantex_tool, with_audit_logging
client = Grantex(api_key="YOUR_API_KEY")
tool = create_grantex_tool(
name="send_email",
description="Sends an email.",
grant_token=token,
required_scope="email:send",
func=send_email_fn,
)
# Wrap with audit logging — every call is recorded
tool = with_audit_logging(
tool, client,
agent_id="ag_01HXYZ...",
grant_id="grnt_01HXYZ...",
)
# Now use the tool in your crew
# Successful calls log status="success", failures log status="failure"
API reference
create_grantex_tool
create_grantex_tool(
*,
name: str,
description: str,
grant_token: str,
required_scope: str,
func: Callable[..., str],
args_schema: type[BaseModel] | None = None,
) -> BaseTool
Creates a CrewAI BaseTool with Grantex scope enforcement.
| Parameter | Description |
|---|---|
name |
Tool name (used in audit log entries) |
description |
Human-readable description shown to the LLM |
grant_token |
Grantex grant token (RS256 JWT) |
required_scope |
Scope that must be present in the token's scp claim |
func |
The function to execute when the tool is called |
args_schema |
Optional Pydantic BaseModel describing tool inputs |
Raises:
PermissionError— if the grant token doesn't containrequired_scopeValueError— if the grant token can't be decodedImportError— ifcrewaiis not installed
with_audit_logging
with_audit_logging(
tool: BaseTool,
client: Grantex,
*,
agent_id: str,
grant_id: str,
) -> BaseTool
Patches the tool's _run method to log audit entries via the Grantex client.
| Parameter | Description |
|---|---|
tool |
A CrewAI BaseTool (from create_grantex_tool) |
client |
A grantex.Grantex client instance |
agent_id |
Grantex agent ID to attribute the action to |
grant_id |
Grant ID authorizing this tool invocation |
get_tool_scopes
get_tool_scopes(grant_token: str) -> list[str]
Returns the scopes embedded in a grant token. Purely offline — no network call, no signature check.
Requirements
Links
Grantex Ecosystem
This package is part of the Grantex ecosystem. See also:
grantex— Core Python SDK@grantex/sdk— TypeScript SDKgrantex-openai-agents— OpenAI Agents SDK integrationgrantex-adk— Google ADK integration@grantex/mcp— MCP server for Claude Desktop / Cursor / Windsurf
License
Apache 2.0
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file grantex_crewai-0.1.3.tar.gz.
File metadata
- Download URL: grantex_crewai-0.1.3.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46c654c7c2a32c528a07135c338896218ee4baa9f16effffce648928e604e836
|
|
| MD5 |
670069a9cb810a0da9f60884d8d4cb87
|
|
| BLAKE2b-256 |
2ec6541379dee401ba29d751fef7db91e56da1bc64725c21a94681dc3eb51d6d
|
File details
Details for the file grantex_crewai-0.1.3-py3-none-any.whl.
File metadata
- Download URL: grantex_crewai-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
199078ae1d58fe93e5c461434aedc2047fab0730b9bd575af0f615401c2b37f7
|
|
| MD5 |
51fab476f3884c991f42a8ad264d7dde
|
|
| BLAKE2b-256 |
9132d9317904cd9430c0ad94c4e5b9deb4c9f182d2ab77e07b1a3a9e764495d1
|