Pre-action authorization for AI agents: intent classification, risk scoring, rule engine, audit trail. Zero dependencies.
Project description
MCP Permission Guard — Pre-Action Authorization for AI Agents
Intent-based permission system with risk scoring, rule engine, and audit trail. 11 tools, 14 intent categories. Zero dependencies.
Install
pip install mcp-permission-guard
Requirements: Python 3.10+. Zero runtime dependencies (stdlib only).
Type checking: Ships with py.typed marker (PEP 561). Compatible with mypy, pyright, and pyrefly.
The Problem
Agents execute destructive actions without guardrails. Binary allow/deny prompts don't work (93% auto-approved). The "lethal trifecta" — private data + untrusted content + external communication — creates risks no single tool can detect.
The Solution
MCP Permission Guard classifies tool calls into 14 intent categories, scores risk 0-100, evaluates rules, and produces deterministic allow/deny/ask decisions with full audit trail.
Quick Start
from src.permission_engine import PermissionGuard
guard = PermissionGuard()
# Evaluate a tool call
decision = guard.evaluate(
tool="terminal",
args={"command": "rm -rf /tmp/build"},
context={"user": "agent", "session": "abc"}
)
print(decision)
# {'decision': 'deny', 'risk': 80, 'intent': 'filesystem_delete', 'reason': '...'}
# Register a custom rule
guard.register_rule(
intent="shell_command",
action="ask",
condition={"command_matches": "git push.*--force"}
)
# Query audit log
log = guard.audit_log(limit=20)
for entry in log:
print(f"{entry['timestamp']} | {entry['decision']} | {entry['tool']}")
14 Intent Categories (with base risk)
| Intent | Risk | Example |
|---|---|---|
credentials_access |
90 | Reading .env, API keys |
filesystem_delete |
80 | rm, rmdir |
user_management |
85 | Creating/deleting users |
package_install |
75 | pip install, apt |
shell_command |
70 | Arbitrary shell execution |
database_write |
65 | INSERT, UPDATE, DELETE |
service_restart |
60 | systemctl restart |
code_execution |
60 | eval(), exec() |
config_change |
55 | Modifying config files |
network_outbound |
50 | curl, HTTP requests |
network_inbound |
30 | Opening a port |
filesystem_write |
40 | write_file, patch |
database_read |
20 | SELECT queries |
filesystem_read |
10 | read_file, cat |
11 Tools
| Tool | What it does |
|---|---|
classify_intent |
Map tool call to intent category |
risk_assess |
Score 0-100 with lethal trifecta detection |
register_rule |
Add allow/deny/ask rule by intent |
evaluate |
Full pipeline: classify + risk + rules |
audit_log |
Query decision history |
list_rules |
Show all registered rules |
remove_rule |
Delete a rule |
set_policy |
Global: allow_all / deny_all / ask_all / rules_based |
get_policy |
Read current policy |
get_stats |
Decision statistics |
reset |
Clear all state |
MCP Server Setup
{
"mcpServers": {
"permission-guard": {
"command": "python3",
"args": ["-m", "src.server"]
}
}
}
Rule Patterns
# Deny all credential access
guard.register_rule(intent="credentials_access", action="deny")
# Ask before package install
guard.register_rule(intent="package_install", action="ask")
# Allow filesystem reads
guard.register_rule(intent="filesystem_read", action="allow")
# Conditional: allow git push to feature branches only
guard.register_rule(
intent="shell_command",
action="deny",
condition={"command_matches": "git push origin (main|master)"}
)
Tests
python -m pytest tests/ -v # 38 tests, all passing
Inspiration
- nah — Intent-level permission guards
- Open Agent Passport — Pre-action authorization
- Beyond Permission Prompts
License
MIT — see LICENSE
Links
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 mcp_permission_guard-1.2.1.tar.gz.
File metadata
- Download URL: mcp_permission_guard-1.2.1.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1817873b1db94e19743d5e84dd6605369498f8f09f15a88cfdf6b7d1ed363d82
|
|
| MD5 |
0a1599319a05a5a266c09f26e576e7e7
|
|
| BLAKE2b-256 |
4a505c85c79704711321346eeddf78cd0db1b8d7049c47dacc57ee58150d5e9a
|
File details
Details for the file mcp_permission_guard-1.2.1-py3-none-any.whl.
File metadata
- Download URL: mcp_permission_guard-1.2.1-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae255a065e03d23dad68998b7be6fe70df8de21376030ae2ee288f78605c1569
|
|
| MD5 |
7f4d0ab99593b706cb8e3e640f21f4de
|
|
| BLAKE2b-256 |
fa42faf0a3befe5d25e1d3be97b42996fe05a6d096d616230019c52538a1d592
|