USBGuard-MCP
<p align="center">
<img src="https://raw.githubusercontent.com/0x5t4l1n/USBGuard-MCP/main/docs/assets/banner.png" alt="USBGuard-MCP: secure, read-only USB security for AI agents" width="100%">
</p>
# USBGuard-MCP
Intelligent USB security through the Model Context Protocol.
[](https://github.com/0x5t4l1n/USBGuard-MCP/actions/workflows/ci.yml)
[](https://github.com/0x5t4l1n/USBGuard-MCP/actions/workflows/security.yml)
[](https://pypi.org/project/usbguard-mcp/)
[](https://pypi.org/project/usbguard-mcp/)
[](LICENSE)
[](https://registry.modelcontextprotocol.io/v0.1/servers?search=io.github.0x5t4l1n/usbguard-mcp)
mcp-name: io.github.0x5t4l1n/usbguard-mcp
USBGuard-MCP is an **independent, read-only** [MCP](https://modelcontextprotocol.io/) server that
lets AI agents inspect [USBGuard](https://usbguard.github.io/): 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](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](docs/tools.md)).
- **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
```mermaid
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](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](docs/threat-model.md) and [docs/permissions.md](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
```bash
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](docs/installation.md).
## Official MCP Registry
Listed on the [official MCP Registry](https://registry.modelcontextprotocol.io/) as
`io.github.0x5t4l1n/usbguard-mcp` (PyPI package, STDIO). Registry data for this server:
[`/v0.1/servers?search=io.github.0x5t4l1n/usbguard-mcp`](https://registry.modelcontextprotocol.io/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](docs/permissions.md), then run `uvx usbguard-mcp` and call
`check_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/`](examples/). For instance, with a local checkout:
```bash
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](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`:
```json
{"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](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](CONTRIBUTING.md). Report vulnerabilities per [SECURITY.md](SECURITY.md).
## License and acknowledgment
MIT, see [LICENSE](LICENSE) and [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md). Thanks to the
[USBGuard](https://github.com/USBGuard/usbguard) project (GPL-2.0-or-later). This project invokes
its CLI and copies none of its code.
TDQS
Scored across 32 tools
Tools divide into recognizable families (device listing, policy analysis, event handling, reporting), but several overlap heavily: analyze_security_policy already reports permissive/duplicate/shadowed/conflicting rules that detect_permissive_rules, detect_duplicate_rules and detect_policy_conflicts expose separately, and assess_usb_security vs generate_security_report is a fuzzy split. The four list_* device tools also largely duplicate list_usb_devices with filters. Descriptions do help separate them, but an agent could easily misselect among the analysis tools.
Every tool follows a clean snake_case verb_noun pattern (get_, list_, inspect_, detect_, analyze_, assess_, generate_, collect_, preview_, search_, classify_, compare_), including the check_ and health_ style status verbs. No camelCase or arbitrary-name deviations.
32 tools is heavy for a read-only audit integration and exceeds the comfortable 3-15 range. While there is genuine depth (device inspection, policy analysis, event buffering, reporting), several granular detect_*/analyze_* tools could be consolidated without losing capability.
For a deliberately read-only server, coverage is strong: version/health/permission checks, device listing/inspection/classification/comparison, policy inspection and analysis, event collection and statistics, plus reporting. Write operations (allow/block/apply rules) are intentionally absent by design, and a couple of analyses are constrained by redaction, but there are no unintended dead ends for the stated purpose.