Skip to main content

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

PyPI Tests Dependencies License

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

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

mcp_permission_guard-1.2.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_permission_guard-1.2.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file mcp_permission_guard-1.2.0.tar.gz.

File metadata

  • Download URL: mcp_permission_guard-1.2.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for mcp_permission_guard-1.2.0.tar.gz
Algorithm Hash digest
SHA256 e9319233e282edce32cfd54fd5b290215c973cbdafb3a4bcb301281200def88c
MD5 179105f249004fb22402504c8c096bb6
BLAKE2b-256 2049c20eca68545ce5afb929a5e8f1af18bc00ed465cee274189bdd3de4fe71e

See more details on using hashes here.

File details

Details for the file mcp_permission_guard-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_permission_guard-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0bb42dc8666e79dfd0dc7896e90cc292317222f8217730b38a8e568a22405af
MD5 952cdd54f940d042bd377a5c4b97b2ef
BLAKE2b-256 5d3d8265f5b6f1492b0a9fe693ca10ab02a2907b2e6f2d4b527ee90d1ba95606

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page