Repository avatar
Security
v0.1.0
active

usbguard-mcp

io.github.0x5t4l1n/usbguard-mcp

Read-only MCP server for Linux USB security: inspect USBGuard devices, audit policy, watch events.

Documentation

USBGuard-MCP: secure, read-only USB security for AI agents

USBGuard-MCP

Intelligent USB security through the Model Context Protocol.

CI Security Release GHCR Docker publish PyPI Python License: MIT MCP Registry

USBGuard-MCP is an independent, read-only MCP server that lets AI agents inspect USBGuard: list devices, analyze the authorization policy, observe authorization events, and produce evidence-based security findings. It is not affiliated with or endorsed by the USBGuard project.

Status: 0.1.0, first release. Validated against a running USBGuard 1.1.4 daemon, a real USB flash drive and three MCP clients on one Fedora KDE laptop. Other distributions and USBGuard versions are untested. Full record: docs/validation.md.

Why

USBGuard answers "may this device be used?" but its CLI output is text meant for humans. An agent asked to "audit my USB policy" would otherwise have to run raw shell commands. USBGuard-MCP gives it a narrow, typed, read-only interface instead: no arbitrary command execution, no write access, structured results, and findings that state their evidence and limits.

Key features

  • 32 read-only tools, 6 resources and 5 prompts (reference).
  • Read-only by construction: the backend can only run usbguard --version, list-devices, list-rules and watch. Nothing can authorize, block, reject, or edit policy.
  • Policy analysis that respects USBGuard semantics: first-match-wins ordering, set operators (equals is the default), wildcards, and conditions. It reports duplicates, shadowed or conflicting rules and permissive rules only when set logic proves them, and states what it cannot evaluate.
  • Explainable heuristics: every finding has evidence, severity, confidence, limitations and remediation. It never calls a device "malicious" and does not detect malware or firmware attacks.
  • Untrusted-metadata handling: device names, serials and rule text are sanitized, kept out of finding prose, and flagged as untrusted in every response.
  • Privacy by default: serials, hashes, ports, host identifiers and audit metadata are redacted. No telemetry; runs fully offline.
  • Explicit mock mode with synthetic scenarios, so development needs no root or hardware.

Architecture

flowchart TD
    A[MCP client] -->|STDIO| B[FastMCP server]
    B --> C[Tools / resources / prompts]
    C --> D[Input validation]
    D --> E[Services: devices, policy, audit, events]
    E --> F[Redaction layer]
    E --> G[Backend interface]
    G --> H[CLI backend<br/>command guard + bounded subprocess]
    G --> M[Mock backend<br/>explicit opt-in]
    H --> I[usbguard CLI] --> J[usbguard daemon<br/>source of truth]

Details: docs/architecture.md.

Security model

Read-only, least privilege, no sudo, no shell=True, absolute root-owned executable path, minimal environment, timeouts, output and concurrency limits, redaction on by default. See docs/threat-model.md and docs/permissions.md.

Supported platforms

Linux only. Fedora is the development platform; Fedora, RHEL, CentOS Stream, Rocky, AlmaLinux, Ubuntu, Debian, Arch and openSUSE are recognized and receive install hints. Recognized does not mean tested: only Fedora has been exercised, and only up to the point of an inactive daemon. USBGuard versions differ between distributions; this was developed against USBGuard 1.1.4.

Requirements

Python 3.11+, USBGuard installed and its daemon running (not needed for --mock). USBGuard-MCP never installs or configures USBGuard for you.

Installation

uvx usbguard-mcp --version      # run without installing (needs uv)
pip install usbguard-mcp        # or install into an environment
usbguard-mcp --mock             # try synthetic data, no USBGuard needed

Docker (GHCR)

docker pull ghcr.io/0x5t4l1n/usbguard-mcp:0.1.0
docker run --rm -i --network none --read-only --cap-drop ALL \
  --security-opt no-new-privileges ghcr.io/0x5t4l1n/usbguard-mcp:0.1.0 --mock

Talking to the real daemon needs --network host --ipc host and a non-root --user that has a read-only USBGuard IPC ACL entry, because USBGuard uses an abstract socket plus /dev/shm instead of a socket file. That is a real isolation trade-off; read docs/docker.md before using it. Never use --privileged, never mount the Docker socket or host directories, and never give the ACL entry modify.

From a checkout: uv sync && uv run usbguard-mcp. See docs/installation.md.

Official MCP Registry

Listed on the official MCP Registry as io.github.0x5t4l1n/usbguard-mcp (PyPI package, STDIO). Registry data for this server: /v0.1/servers?search=io.github.0x5t4l1n/usbguard-mcp. The registry documents no official badge, so the badge above is a generic shields.io badge that reads the registry API live. The registry stores metadata only; the package is installed from PyPI.

Quick start

  1. Try it on synthetic data: uvx usbguard-mcp --mock (an MCP client speaks to it over STDIO).
  2. For real data, ask an administrator for the minimal read-only ACL in docs/permissions.md, then run uvx usbguard-mcp and call check_permissions.

MCP client configuration

ClientStatus (live, real daemon, 2026-12-06)
Claude CodeTested: tool call returned the real USBGuard version
Codex CLITested: same
OpenCodeTested with caveats: use a project-level opencode.json; small models may need the server named in the prompt
MCP Inspector (CLI)Tested: tools/list, tools/call
Claude Desktop, VS CodeConfig shape follows vendor docs; untested

Examples live in examples/. For instance, with a local checkout:

claude mcp add --scope user --transport stdio usbguard -- uvx usbguard-mcp
codex mcp add usbguard -- uvx usbguard-mcp

Tools

Full generated reference: docs/tools.md.

GroupTools
Systemget_usbguard_version, get_system_status, check_permissions, get_server_info, health_check
Deviceslist_usb_devices, list_allowed_devices, list_blocked_devices, list_rejected_devices, inspect_usb_device, search_usb_devices, get_device_statistics, classify_usb_device, compare_usb_devices
Policylist_policy_rules, inspect_policy_rule, analyze_security_policy, detect_duplicate_rules, detect_permissive_rules, detect_policy_conflicts, recommend_policy_improvements, preview_policy_rule
Securityassess_usb_security, detect_suspicious_interfaces, detect_composite_devices, analyze_device_risk, detect_identity_changes, generate_security_report
Monitoringcollect_usb_events, get_recent_usb_events, get_event_statistics, analyze_usb_activity

Resources: usbguard://system/status, usbguard://devices, usbguard://policies, usbguard://events/recent, usbguard://security/summary, usbguard://documentation. Prompts: audit_usb_security, investigate_usb_device, review_usb_policy, analyze_recent_usb_activity, generate_usb_security_report.

Example prompts

  • "List all authorized USB devices."
  • "Are there any blocked USB devices?"
  • "Audit my current USB authorization policy."
  • "Explain which devices expose multiple USB interfaces."
  • "Review my USBGuard configuration for security weaknesses."
  • "Generate a USB security assessment report."

Example (synthetic data) from detect_policy_conflicts:

{"code": "CONFLICTING_RULE", "severity": "medium", "confidence": "high",
 "summary": "A later rule has a different target but is unreachable: an earlier unconditional rule always matches first.",
 "evidence": {"earlier_rule_id": 1, "later_rule_id": 3, "earlier_target": "allow", "later_target": "block"},
 "limitations": ["Rule conditions (if ...) are evaluated by the daemon at runtime, not here.", "..."],
 "remediation": "Decide which target is intended, then fix the rule order or remove the unreachable rule."}

Troubleshooting

See docs/troubleshooting.md. Start with check_permissions.

Known limitations

  • Validated on one laptop, one USBGuard version (1.1.4) and one distribution (Fedora); parsers are strict and report PARSE_ERROR rather than guessing, so other versions may need fixes.
  • Event timestamps are collection time, not occurrence time (USBGuard watch gives none); only order is reliable. USBGuard device IDs change when a device is replugged.
  • ImplicitPolicyTarget and other settings in usbguard-daemon.conf are root-only and not read.
  • Rule conditions (if ...) are not evaluated. Policy analysis is sound but incomplete.
  • Rejected/disconnected devices are only visible via the live list or events seen this session.
  • Events come from a bounded in-memory buffer; there is no historical journal source.
  • No native IPC backend, HTTP transport or write operations.

Roadmap

0.x: more distributions and USBGuard versions, MCP Registry submission. Later, each needing its own security review: native IPC backend, persistent local event storage, authenticated localhost HTTP, carefully controlled administrative functions. None may weaken the read-only default.

Contributing

See CONTRIBUTING.md. Report vulnerabilities per SECURITY.md.

License and acknowledgment

MIT, see LICENSE and THIRD_PARTY_NOTICES.md. Thanks to the USBGuard project (GPL-2.0-or-later). This project invokes its CLI and copies none of its code.

PYPI
usbguard-mcp
Install Command
pip install usbguard-mcp
Runtime: uvx