feat(mcp): automation tools — playbooks, runs, schedules, alert actions, docker prune
CI / lint (push) Successful in 3s
CI / integration (push) Successful in 57s
CI / unit (push) Failing after 1m8s
CI / publish (push) Skipped

MCP-6 #4970 "Automation tools: playbooks, runs, schedules, alert actions".

Viewer: list_playbooks, get_playbook (secret defaults masked), list_inventory
(variable names only), list_ansible_runs, get_ansible_run (log tail + grep),
list_schedules, wait_for_run (polls, 120s cap).

Operator: run_playbook (check mode unless check=false; a steward:confirm
playbook applies only with confirmed=true; secret variables reach the run
but are never stored, audited or returned), cancel_ansible_run, and
create/update/delete_schedule (secrets refused, check by default).

Admin: set_alert_action, and the docker plugin's prune_docker, which
previews from the disk report unless check=false (Ansible's check mode
skips the prune commands, so a check run would show nothing).

Every write is audited as "<user> via MCP" with the token id; the audit
tool's user filter includes those rows. prune_extra_vars moves to the
docker service so the page and the tool share it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 08:06:15 -04:00
co-authored by Claude Opus 5.5
parent 21338dbcd9
commit 680a6bf3b6
13 changed files with 1124 additions and 32 deletions
+21
View File
@@ -1,8 +1,11 @@
"""The docker plugin's MCP tools: what counts as a problem, and how it is reported."""
import inspect
from datetime import datetime, timedelta, timezone
from types import SimpleNamespace as NS
from unittest.mock import MagicMock
import pytest
import plugins.docker as docker_plugin
from plugins.docker import mcp_tools as t
@@ -78,3 +81,21 @@ def test_plugin_exposes_the_mcp_hooks():
for call in reg.call_args_list:
assert call.kwargs["read_only"] is True
assert callable(docker_plugin.mcp_overview)
def test_prune_preview_sizes_what_each_target_removes():
usage = NS(images_reclaimable=3000, build_cache_size=70)
assert t.prune_preview("containers", usage, 4) == {"stopped_containers": 4}
assert t.prune_preview("images", usage, 4) == {"unused_images_bytes": 3000}
system = t.prune_preview("system", usage, 4)
assert system["stopped_containers"] == 4 and system["build_cache_bytes"] == 70
assert t.prune_preview("images", None, 0) == {"unused_images_bytes": None}
async def test_prune_docker_refuses_an_unknown_target_before_reading_anything(monkeypatch):
def _no_db():
raise AssertionError("touched the database")
monkeypatch.setattr(t, "db_session", _no_db)
with pytest.raises(ValueError, match="'volumes' is not one of containers, images, system"):
await t.prune_docker("nas", "volumes")
assert inspect.signature(t.prune_docker).parameters["check"].default is True