@mgcrea/mcp-unifi-drive
v0.1.0
Published
Model Context Protocol server for UniFi Drive
Maintainers
Readme
@mgcrea/mcp-unifi-drive
Model Context Protocol server for UniFi Drive on a UNAS: storage pools, RAID and disk health, shared and personal drives, snapshots, backups, the system log, and I/O history. Read-only by default: the tools that change anything are not registered at all unless you ask for them.
Features
- One health verdict.
unifi_drive_health_checkreads about ten endpoints and returns ranked findings in plain words: a full pool, degraded RAID, disks at risk or running hot, snapshot schedules that have quietly stopped, missing or failing remote backups, a waiting Drive update, and the high-severity log events of the last week, with repeats collapsed into counts. - Storage that reads like the dashboard. Sizes are in decimal units, as the web app shows them. Quotas, which the console stores in GB, are converted. A pool whose target RAID level is above its current one is described as what it is: a plan that adding disks completes, not a migration in progress.
- Logs you can read. Each entry is rendered from the console's own message templates, and sign-ins are excluded by default, because on a busy UNAS they are 99 out of every 100 lines.
- Shaped responses. Raw disk statistics arrive as hundreds of samples per disk. The I/O tool returns average, peak (with its time), and latest value instead, plus any bad sectors added during the window.
- Starts with no credentials, and
unifi_drive_auth_statussays what to configure, instead of the server exiting and showing up in your client as a bareConnection closed.
Setup
A UNAS is its own UniFi OS console with its own accounts. A user created on your gateway
(UDM, UCG, Cloud Key) does not exist on the UNAS, and logging in with it fails with
AUTHENTICATION_FAILED_INVALID_CREDENTIALS.
On the UNAS: UniFi OS → Admins & Users → Add Admin → Restrict to Local Access Only, without 2FA. Then:
UNIFI_DRIVE_HOST=192.168.1.2 # the UNAS, not the gateway
UNIFI_DRIVE_USERNAME=mcp
UNIFI_DRIVE_PASSWORD=…{
"mcpServers": {
"unifi-drive": {
"command": "npx",
"args": ["-y", "@mgcrea/mcp-unifi-drive"],
"env": {
"UNIFI_DRIVE_HOST": "192.168.1.2",
"UNIFI_DRIVE_USERNAME": "mcp",
"UNIFI_DRIVE_PASSWORD": ""
}
}
}
}TLS needs nothing extra. The console's self-signed certificate (CN=unifi.local, no IP SAN)
is pinned on the first request and checked on every later one. The fingerprint is printed at
startup; set UNIFI_DRIVE_FINGERPRINT to it if you want the trust stated explicitly instead
of learned on first contact.
Cloud mode (UNIFI_DRIVE_API_KEY + UNIFI_DRIVE_CONSOLE_ID) goes through api.ui.com's
Site Manager connector, the same way mcp-unifi-protect does. It has not been verified
against Drive yet; unifi_drive_auth_status makes a real call, so it will tell you.
Every setting can also go in ~/.config/unifi-drive/config.json (camelCase keys). The
environment takes precedence, setting by setting. See .env.example for the full
list.
Tools
| Tool | What it answers |
| ------------------------------------ | ----------------------------------------------------------------------------------- |
| unifi_drive_auth_status | Can the server reach the UNAS, which one answered, TLS and session state |
| unifi_drive_health_check | Is the NAS OK? Ranked findings plus recent high-severity events |
| unifi_drive_get_system | Model, UniFi OS and Drive versions, pending update, uptime, CPU, memory, links, fan |
| unifi_drive_get_storage | Pools, RAID current/target, usage breakdown, SSD cache, scrubbing, every disk |
| unifi_drive_get_io_stats | Throughput over 1h / 24h / 7d / 30d, per pool and per disk, with temperatures |
| unifi_drive_list_drives | Shared and personal drives: usage, quota, encryption, backup, snapshot state |
| unifi_drive_list_snapshots | The snapshots kept for one drive |
| unifi_drive_list_logs | The system log, rendered and filtered by severity, category, type and time |
| unifi_drive_list_users | Users, groups, and the size of each personal drive |
| unifi_drive_list_services | SMB, NFS, Time Machine, rsync, share links |
| unifi_drive_list_backups | Remote backup and Microsoft 365 backup tasks |
| unifi_drive_request | Escape hatch: any /proxy/drive/api path, raw (GET only unless writes are on) |
| unifi_drive_auth_login / _logout | Supply a 2FA code once / drop the cached session (local mode only) |
With UNIFI_DRIVE_ALLOW_WRITES=1, these are registered as well, and each one requires
confirm: true:
| Tool | Effect |
| ----------------------------- | ---------------------------------------------------------- |
| unifi_drive_create_snapshot | Snapshot a shared drive now (refused while under 10% free) |
| unifi_drive_delete_snapshot | Delete one snapshot of a shared drive. Irreversible. |
| unifi_drive_set_fan_mode | quiet, default (Balanced in the web app), cooling |
| unifi_drive_run_smart_test | Start a quick or extended SMART test on one disk |
| unifi_drive_run_backup_task | Run a remote backup task now |
Snapshot writes only work on shared drives. Drive lets an admin read a personal drive's snapshots, but only the drive's owner, signed in as themselves, can create or delete them.
The API
Drive has no documented API. This server uses the one its web app calls, which is mounted under
UniFi OS's proxy at /proxy/drive/api. It has two generations, and the web app uses both:
v1/...wraps every answer in{err, type, data, offset, limit, total}. A failure can arrive inside an HTTP 200, and the useful part of an error is usually inerr.metadata.error(for example, "bad interval value") rather than inerr.msg("Bad Request").v2/...returns the object directly.
Traps found while building it, each handled where it occurs in the code:
- Times are Unix seconds, not milliseconds as in Protect.
after,before,startandendall take seconds. - Quotas are gigabytes, and
-1means unlimited. - Stats need an interval the console accepts. The four used here (60, 900, 3600 and 21600 seconds) are the ones the web app uses. Any other value gets "bad interval value".
- Snapshot endpoints address shared drives by name (
v1/snapshots/shared/Shared_Drive), while everything else uses the id. A personal drive with no snapshots answers 404, not an empty list. - Every drive reports
paused: trueonce the pool is low on space, including drives that have no schedule. Only a pause on a scheduled drive means anything. - The pending Drive update is not available from the Drive API at all. It comes from UniFi
OS's
/api/system.
Ubiquiti moves these endpoints between releases. unifi_drive_get_system reports the running
Drive version, and unifi_drive_request can reach any endpoint without waiting for a new
release of this server. The traffic was mapped against Drive 4.4.31 on a UNAS Pro 4.
Login, CSRF handling, the cached session and certificate pinning come from
@mgcrea/unifi-protect. Despite the
name, that code is generic UniFi OS. Its ProtectClient hard-codes the Protect path, so Drive
has its own small client with the same retry rules.
Development
pnpm install
pnpm lint && pnpm format:check && pnpm typecheck && pnpm test && pnpm buildThe test fixtures in test/fixtures are real responses from a live UNAS, with personal details
replaced.
License
MIT
