USBGuard-MCP
Intelligent USB security through the Model Context Protocol.
mcp-name: io.github.0x5t4l1n/usbguard-mcp
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-rulesandwatch. Nothing can authorize, block, reject, or edit policy. - Policy analysis that respects USBGuard semantics: first-match-wins ordering, set operators
(
equalsis 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
From a checkout: uv sync && uv run usbguard-mcp. See docs/installation.md.
Quick start
- Try it on synthetic data:
uvx usbguard-mcp --mock(an MCP client speaks to it over STDIO). - For real data, ask an administrator for the minimal read-only ACL in
docs/permissions.md, then run
uvx usbguard-mcpand callcheck_permissions.
MCP client configuration
| Client | Status (live, real daemon, 2026-12-06) |
|---|---|
| Claude Code | Tested: tool call returned the real USBGuard version |
| Codex CLI | Tested: same |
| OpenCode | Tested 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 Code | Config 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.
| Group | Tools |
|---|---|
| System | get_usbguard_version, get_system_status, check_permissions, get_server_info, health_check |
| Devices | list_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 |
| Policy | list_policy_rules, inspect_policy_rule, analyze_security_policy, detect_duplicate_rules, detect_permissive_rules, detect_policy_conflicts, recommend_policy_improvements, preview_policy_rule |
| Security | assess_usb_security, detect_suspicious_interfaces, detect_composite_devices, analyze_device_risk, detect_identity_changes, generate_security_report |
| Monitoring | collect_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_ERRORrather than guessing, so other versions may need fixes. - Event timestamps are collection time, not occurrence time (USBGuard
watchgives none); only order is reliable. USBGuard device IDs change when a device is replugged. ImplicitPolicyTargetand other settings inusbguard-daemon.confare 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.
Metadata
Release files for usbguard-mcp 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| usbguard_mcp-0.1.0.tar.gz | 1.8 MB | With provenance | Details for usbguard_mcp-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| usbguard_mcp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for usbguard_mcp-0.1.0-py3-none-any.whl |
Total release size: 1.9 MB
Release files / usbguard_mcp-0.1.0.tar.gz
| Download URL | usbguard_mcp-0.1.0.tar.gz |
|---|---|
| Size | 1.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2322b1796278dc7a2b6362bfacead593e76e4d1d401d8d7d20deb2dc145ce6ca
|
|
BLAKE2b-256 checksum How to use checksums |
314ec66ee061446d79a43ceb3d1704b6e2073f954608cb280844cd13aeea19d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Transparency logRelease files / usbguard_mcp-0.1.0-py3-none-any.whl
| Download URL | usbguard_mcp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 52.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9e1126ed99a53c079e103a4c16e5eafa57ff3e7a5f443719ed64aba92b57be93
|
|
BLAKE2b-256 checksum How to use checksums |
e5e3d381562c9fbd65e6725a8011f6b589b664d17e5750bc71a4afee7bceea6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Transparency logSecurity for usbguard-mcp 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for usbguard_mcp-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.