Skip to main content

Permission guard: tool call allow/deny rules for AI agents

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

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.0.1.tar.gz (10.4 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.0.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcp_permission_guard-1.0.1.tar.gz
  • Upload date:
  • Size: 10.4 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.0.1.tar.gz
Algorithm Hash digest
SHA256 711fbd3486ae7c1e795a9466eae0e81c747be9651b4bc71a2364713bdf8de086
MD5 80213c19534ffb84e9d4bb42930054c1
BLAKE2b-256 47ac424b6cc7f5ed8648d1b5cc7e46ca552a7f3040ff3e7db23ad3fe71e2edfb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_permission_guard-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7da4bef619546bbd7517d07b114405df09eb1d92ab6a90dd629166952b7e5636
MD5 c902a64e9941c33d6e30a1a74dcd1c6b
BLAKE2b-256 8fa51f528acaaea8b70d43621aca46cdb9c9b7bdd54bd774a93521521ed1e8a9

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