Commit Graph

94 Commits

Author SHA1 Message Date
Jacob Magar
cdab970c12 refactor(guards): migrate array/keys/plugins to gate_destructive_action
Replace 7-11 line inline guard blocks in array.py, keys.py, and plugins.py
with single await gate_destructive_action(...) calls. Also fix guards.py to
raise unraid_mcp.core.exceptions.ToolError (project subclass) instead of
fastmcp.exceptions.ToolError so pytest.raises catches it correctly in tests.
2026-03-15 23:33:07 -04:00
Jacob Magar
80d2dd39ee refactor(guards): remove elicit_destructive_confirmation from setup.py (moved to guards.py)
Update array, keys, and plugins tool imports to source elicit_destructive_confirmation from core.guards instead of core.setup.
2026-03-15 23:29:22 -04:00
Jacob Magar
aa5fa3e177 feat(guards): add core/guards.py with gate_destructive_action helper 2026-03-15 23:25:39 -04:00
Jacob Magar
4b43c47091 fix(tools): remove 10 dead actions referencing mutations absent from live API
settings.py: drop update_temperature, update_time, update_api,
connect_sign_in, connect_sign_out, setup_remote_access,
enable_dynamic_remote_access, update_ssh — all 8 reference mutations
confirmed absent from Unraid API v4.29.2. Keep update + configure_ups.

info.py: drop update_server (updateServerIdentity not in Mutation type)
and update_ssh (duplicate of removed settings action). MUTATIONS is now
empty; DESTRUCTIVE_ACTIONS is now an empty set.

notifications.py: drop create_unique (notifyIfUnique not in Mutation type).

Tests: remove corresponding test classes, add parametrized regression
tests asserting removed actions are not in each tool's Literal type,
update KNOWN_DESTRUCTIVE and _DESTRUCTIVE_TEST_CASES in safety audit,
update schema coverage assertions. 858 tests passing, 0 failures.
2026-03-15 23:21:25 -04:00
Jacob Magar
c37d4b1c5a fix(subscriptions): use x-api-key connectionParams format for WebSocket auth
The Unraid graphql-ws server expects the API key directly in connectionParams
as `x-api-key`, not nested under `headers`. The old format caused the server
to fall through to cookie auth and crash on `undefined.csrf_token`.

Fixed in snapshot.py (×2), manager.py, diagnostics.py, and updated the
integration test assertion to match the correct payload shape.
2026-03-15 22:56:58 -04:00
Jacob Magar
16bb5a6146 fix(storage): remove unassigned action (unassignedDevices not in live API) 2026-03-15 21:59:06 -04:00
Jacob Magar
83df768135 fix(notifications): remove warnings action (warningsAndAlerts not in live API) 2026-03-15 21:58:56 -04:00
Jacob Magar
569956ade0 fix(docker): remove 19 stale actions absent from live API v4.29.2
Only list, details, start, stop, restart, networks, network_details
remain. Removed logs, port_conflicts, check_updates from QUERIES and all
organizer mutations + pause/unpause/remove/update/update_all from
MUTATIONS. DESTRUCTIVE_ACTIONS is now an empty set.
2026-03-15 21:58:50 -04:00
Jacob Magar
f5978d67ec feat(resources): add unraid://live/{action} MCP resources for 9 snapshot subscriptions
Registers cpu, memory, cpu_telemetry, array_state, parity_progress,
ups_status, notifications_overview, owner, and server_status as MCP
resources under unraid://live/{action}. Each opens a transient WebSocket
via subscribe_once() and returns JSON; exceptions degrade gracefully to
an error JSON dict rather than raising. Skips log_tail and
notification_feed (require params, not suitable as resources).
2026-03-15 21:51:20 -04:00
Jacob Magar
7c99fe1527 refactor(subscriptions): extract SNAPSHOT_ACTIONS/COLLECT_ACTIONS to subscriptions/queries.py
Moves the subscription query dicts out of tools/live.py into a new
subscriptions/queries.py module so subscriptions/resources.py can
import them without creating a cross-layer subscriptions→tools dependency.
2026-03-15 21:43:18 -04:00
Jacob Magar
389b88f560 feat(settings): add update_ssh action with confirm=True guard
Enables/disables SSH and sets port via updateSshSettings mutation
(UpdateSshInput: enabled: Boolean!, port: Int!). Changing SSH config
can lock users out of the server — requires confirm=True.

- Add update_ssh to MUTATIONS, DESTRUCTIVE_ACTIONS, SETTINGS_ACTIONS
- Add ssh_enabled/ssh_port parameters to unraid_settings
- Add TestSshSettings class (4 tests: require ssh_enabled, require ssh_port, success, disable+verify vars)
- Update safety test KNOWN_DESTRUCTIVE + _DESTRUCTIVE_TEST_CASES + positive confirm test
- Update schema completeness test

757 tests passing
2026-03-15 20:13:51 -04:00
Jacob Magar
94850333e8 fix(safety): add stop_array to DESTRUCTIVE_ACTIONS, add error propagation test
stop_array can cause data loss for running containers/VMs that depend on
array shares — requires confirm=True like other destructive mutations.

- Add stop_array to DESTRUCTIVE_ACTIONS and desc_map in array.py
- Update safety audit KNOWN_DESTRUCTIVE[array] to include stop_array
- Add stop_array negative/positive tests (test_array.py, safety tests)
- Add test_snapshot_wraps_bare_exception to test_live.py (bare Exception
  from subscribe_once is wrapped by tool_error_handler into ToolError)

748 tests passing
2026-03-15 20:02:33 -04:00
Jacob Magar
252ec520d1 fix(lint): remove __future__ annotations from new tools, fix 4 failing tests
- Remove `from __future__ import annotations` from array.py, live.py,
  oidc.py, plugins.py to match existing tool pattern and resolve TC002
  ruff errors (fastmcp imports only needed in annotations under PEP 563)
- Add `# noqa: ASYNC109` to live.py timeout parameter (asyncio.timeout
  already used internally)
- Fix test_network_sends_correct_query: query name is GetNetworkInfo
- Fix test_delete_requires_confirm: match "not confirmed" not "destructive"
- Fix test_destructive_set_matches_audit[settings]: add setup_remote_access
  and enable_dynamic_remote_access to KNOWN_DESTRUCTIVE
- Fix test_logs: update mock to dict format {lines: [{timestamp, message}]}

742 tests passing, ruff clean
2026-03-15 19:57:46 -04:00
Jacob Magar
1f35c20cdf chore: update schema tests, docs, bump version to 0.5.0
- Add schema validation tests for new tools (customization, plugins, oidc)
  and expanded array/keys actions (13 array, 7 keys)
- Update TestSchemaCompleteness to include new modules with KNOWN_SCHEMA_ISSUES
  exclusion list for 4 tool-level schema mismatches (tracked for later fix)
- Fix missing register_oidc_tool import in server.py (was causing NameError)
- Update CLAUDE.md Tool Categories section: 11 → 15 tools, ~103 actions
- Update Destructive Actions section with array/plugins additions
- Bump version 0.4.8 → 0.5.0 in pyproject.toml and .claude-plugin/plugin.json
- Schema tests: 84 passing → 119 passing (35 new tests)
- Full suite: 618 passing → 738 passing (120 net new passing)
2026-03-15 19:42:05 -04:00
Jacob Magar
6eafc16af7 feat(oidc): add unraid_oidc tool with providers, provider, configuration, public_providers, validate_session 2026-03-15 19:30:22 -04:00
Jacob Magar
ebba60c095 fix(types): suppress ty union-attr false positives on elicitation result.data access 2026-03-15 19:27:43 -04:00
Jacob Magar
2b4b1f0395 feat(plugins): add unraid_plugins tool with list, add, remove actions
Implements the unraid_plugins MCP tool (3 actions, 1 destructive) and adds
elicit_destructive_confirmation() to core/setup to support all tools that
gate dangerous mutations behind confirm=True with optional MCP elicitation.
2026-03-15 19:26:42 -04:00
Jacob Magar
d26467a4d0 feat(customization): add unraid_customization tool with theme, public_theme, is_initial_setup, sso_enabled, set_theme 2026-03-15 19:19:06 -04:00
Jacob Magar
76391b4d2b feat(keys): add add_role and remove_role actions for API key role management
Adds two new mutation actions to unraid_keys:
- add_role: calls apiKey.addRole with apiKeyId + role, requires key_id and roles
- remove_role: calls apiKey.removeRole with apiKeyId + role, requires key_id and roles

Updates safety audit to explicitly exempt remove_role from the delete/remove
heuristic (reversible action — role can be re-added). Updates schema coverage
test and adds schema validation tests for both new mutations.
2026-03-15 19:13:03 -04:00
Jacob Magar
0d4a3fa4e2 fix(live): validate log_tail path against allowlist, move guards before error handler
Add _ALLOWED_LOG_PREFIXES allowlist check to log_tail (mirrors storage.py pattern)
to prevent path traversal attacks. Move path/required guards before tool_error_handler
context so validation errors raise cleanly. Add two tests: ToolError propagation and
invalid path rejection.
2026-03-15 19:08:43 -04:00
Jacob Magar
3a72f6c6b9 feat(array): add parity_history, start/stop array, disk add/remove/mount/unmount/clear_stats
Expands unraid_array from 5 to 13 actions: adds parity_history query,
start_array/stop_array state mutations, and disk operations (add_disk,
remove_disk, mount_disk, unmount_disk, clear_disk_stats). Destructive
actions remove_disk and clear_disk_stats require confirm=True. Safety
audit tests updated to cover the new DESTRUCTIVE_ACTIONS registry entry.
2026-03-15 19:03:01 -04:00
Jacob Magar
675a466d02 feat(live): add unraid_live tool with 11 subscription snapshot actions
Creates unraid_mcp/tools/live.py with SNAPSHOT_ACTIONS (9 one-shot reads)
and COLLECT_ACTIONS (2 streaming collectors), plus tests/test_live.py
with 6 passing tests. Registers register_live_tool in server.py, bringing
the total to 12 tools.
2026-03-15 18:56:14 -04:00
Jacob Magar
5a3e8e285b fix(subscriptions): bound snapshot loops with asyncio.timeout, raise on collect errors
- Wrap async-for loops in asyncio.timeout() so both subscribe_once and subscribe_collect
  cannot hang indefinitely when no messages arrive after the handshake
- subscribe_once: TimeoutError → ToolError("Subscription timed out after Xs")
- subscribe_collect: TimeoutError → pass (return events collected so far)
- Remove manual deadline checks inside the loops (now redundant)
- subscribe_collect now raises ToolError on GraphQL payload errors instead of silently dropping them
- subscribe_collect handshake now distinguishes connection_error (auth) from unexpected type
2026-03-15 18:52:27 -04:00
Jacob Magar
181ad53414 feat(subscriptions): add subscribe_once and subscribe_collect snapshot helpers 2026-03-15 18:48:42 -04:00
Jacob Magar
a3754e37c3 feat(creds): setup declined message includes manual path and variable names 2026-03-14 14:45:35 -04:00
Jacob Magar
c80ab0ca6b refactor(creds): remove per-tool elicitation from unraid_info 2026-03-14 14:20:20 -04:00
Jacob Magar
08afdcc50e refactor(creds): remove per-tool elicitation from unraid_settings 2026-03-14 14:19:42 -04:00
Jacob Magar
ba7b8dfaa6 refactor(creds): remove per-tool elicitation from unraid_keys 2026-03-14 14:18:20 -04:00
Jacob Magar
23e70e46d0 refactor(creds): remove per-tool elicitation from unraid_users 2026-03-14 14:17:14 -04:00
Jacob Magar
fe66e8742c refactor(creds): remove per-tool elicitation from unraid_rclone 2026-03-14 14:16:34 -04:00
Jacob Magar
77f3d897a3 refactor(creds): remove per-tool elicitation from unraid_notifications 2026-03-14 14:16:07 -04:00
Jacob Magar
8c67145bcc refactor(creds): remove per-tool elicitation from unraid_vm 2026-03-14 14:14:22 -04:00
Jacob Magar
9fc85ea48c refactor(creds): remove per-tool elicitation from unraid_storage 2026-03-14 14:13:52 -04:00
Jacob Magar
d99855973a refactor(creds): remove per-tool elicitation from unraid_docker 2026-03-14 14:13:14 -04:00
Jacob Magar
9435a8c534 refactor(creds): remove per-tool elicitation from unraid_array 2026-03-14 14:09:14 -04:00
Jacob Magar
81f1fe174d feat(creds): tool_error_handler converts CredentialsNotConfiguredError to ToolError with path
Converts the CredentialsNotConfiguredError sentinel to a user-facing ToolError
in tool_error_handler, including the exact CREDENTIALS_ENV_PATH so users know
where to create the .env file. Removes the now-invalid per-tool elicitation
test (replaced by 2 new tests for the handler conversion behavior).
2026-03-14 14:05:59 -04:00
Jacob Magar
e930b868e4 feat(creds): write to ~/.unraid-mcp/.env with 700/600 permissions, seed from .env.example
- _write_env now creates CREDENTIALS_DIR (mode 700) and writes credentials
  to CREDENTIALS_ENV_PATH (mode 600) instead of PROJECT_ROOT/.env
- On first run (no .env yet), seeds file content from .env.example to
  preserve comments and structure
- elicit_and_configure catches NotImplementedError from ctx.elicit() so
  clients that don't support elicitation return False gracefully instead
  of propagating the exception
- Updated test_elicit_and_configure_writes_env_file to patch CREDENTIALS_DIR
  and CREDENTIALS_ENV_PATH instead of PROJECT_ROOT
- Added 5 new tests covering dir/file permissions, .env.example seeding,
  in-place credential update, and NotImplementedError guard
2026-03-14 14:00:57 -04:00
Jacob Magar
d8ce45c0fc feat(creds): add CREDENTIALS_DIR and CREDENTIALS_ENV_PATH to settings
Introduce a version-agnostic credential directory (~/.unraid-mcp, overridable
via UNRAID_CREDENTIALS_DIR env var) and surface it as CREDENTIALS_DIR and
CREDENTIALS_ENV_PATH module-level constants. Prepend the canonical .env path to
dotenv_paths so all runtimes (plugin, uv, Docker) resolve credentials from the
same stable location without relying on versioned plugin cache paths.
2026-03-14 13:54:14 -04:00
Jacob Magar
85cd173449 fix(elicitation): guard ctx=None in elicit_and_configure, cover all settings/docker/notifications actions
- setup.py: elicit_and_configure now accepts Context | None; returns False
  immediately when ctx is None instead of crashing with AttributeError
- settings.py: added CredentialsNotConfiguredError try/except guard around
  make_graphql_request calls in all 8 previously-unguarded actions
  (update_temperature, update_time, configure_ups, update_api, connect_sign_in,
  connect_sign_out, setup_remote_access, enable_dynamic_remote_access)
- docker.py: added guards to all 20 previously-unguarded make_graphql_request
  calls (details, logs, networks, network_details, port_conflicts, check_updates,
  restart, update_all, all 11 organizer mutations, and single-container fallback)
- notifications.py: added guards to all 11 previously-unguarded calls
  (list, warnings, create, archive/unread, delete, delete_archived, archive_all,
  archive_many, create_unique, unarchive_many, unarchive_all, recalculate)
2026-03-14 04:28:34 -04:00
Jacob Magar
e1c80cf1da feat(elicitation): add ctx + credential elicitation to unraid_settings 2026-03-14 04:19:08 -04:00
Jacob Magar
ba14a8d341 feat(elicitation): add ctx + credential elicitation to unraid_keys 2026-03-14 04:18:06 -04:00
Jacob Magar
cec254b432 feat(elicitation): add ctx + credential elicitation to unraid_users 2026-03-14 04:17:17 -04:00
Jacob Magar
dec80832ea feat(elicitation): add ctx + credential elicitation to unraid_rclone 2026-03-14 04:16:54 -04:00
Jacob Magar
4b4c8ddf63 feat(elicitation): add ctx + credential elicitation to unraid_notifications 2026-03-14 04:16:08 -04:00
Jacob Magar
dfcaa37614 feat(elicitation): add ctx + credential elicitation to unraid_vm 2026-03-14 04:14:43 -04:00
Jacob Magar
060acab239 feat(elicitation): add ctx + credential elicitation to unraid_storage 2026-03-14 04:14:15 -04:00
Jacob Magar
be186dc2d7 feat(elicitation): add ctx + credential elicitation to unraid_docker 2026-03-14 04:13:34 -04:00
Jacob Magar
13f85bd499 feat(elicitation): add ctx + credential elicitation to unraid_array 2026-03-14 04:11:38 -04:00
Jacob Magar
49264550b1 feat(elicitation): auto-elicit credentials on CredentialsNotConfiguredError in unraid_info 2026-03-14 04:07:51 -04:00
Jacob Magar
9be46750b8 feat(elicitation): add setup action to unraid_health 2026-03-14 04:02:15 -04:00