AUD-04-02 — add write gate + confirm discipline (DD-385 Phase W)

The blade had no write gate and no confirm parameter anywhere — every
mutating tool (override, revert, restart, accept-device, replace-stignore,
…) fired ungated, unlike every sibling blade. This brings syncthing up to
the class baseline:

- All 13 mutating tools now require SYNCTHING_WRITE_ENABLED=true
  (models.require_write, env read at call time) and refuse with a clear
  message when the gate is off.
- Destructive/disruptive operations additionally require confirm=true:
  syncthing_override_folder, syncthing_revert_folder, syncthing_restart,
  syncthing_accept_device, syncthing_accept_folder, syncthing_set_ignores.
  Refusals explain what the operation would do. These six are now
  annotated destructiveHint: true.
- New ConfirmWriteParams / ConfirmFolderWriteParams models; confirm field
  added to AcceptDeviceInput, AcceptFolderInput, SetIgnoresInput.
- Server-level FastMCP instructions document the gate + confirm contract;
  README, SKILL.md, and stallari-plugin.yaml (setup field + env entry)
  updated to match.
- Regression suite tests/test_write_gate.py: gated-off refusal (all 13,
  unset + non-"true" value), gated-on-without-confirm refusal (all 6
  destructive), gated-on-with-confirm proceeds (mocked), and
  non-destructive-needs-no-confirm. Existing write-tool tests updated to
  enable the gate + pass confirm. 201 tests green.

Version 0.8.0 → 0.9.0 (behaviour-affecting safety gate).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
PiersandClaude Fable 5 committed 2026-06-11 23:20:48 +10:00
1 parent f63cba44cc
commit bf50002e8b
17 files changed
+389 -48

No files matched your search

+20
View File
@@ -4,6 +4,26 @@ All notable changes to `syncthing-blade-mcp` will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
## [0.9.0] - 2026-06-11
### Security
- **AUD-04-02 / DD-385 Phase W — write gate + confirm discipline (class baseline).**
All 13 mutating tools now require `SYNCTHING_WRITE_ENABLED=true` and refuse
with a clear error when the gate is off. Previously every mutating tool
(override, revert, restart, accept-device, replace-stignore, …) fired
ungated.
- **`confirm=true` required for destructive/disruptive operations:**
`syncthing_override_folder`, `syncthing_revert_folder`, `syncthing_restart`,
`syncthing_accept_device`, `syncthing_accept_folder`, `syncthing_set_ignores`.
The refusal message explains what the operation would do. These tools are
now annotated `destructiveHint: true`.
### Changed
- Server-level MCP instructions now document the write gate and confirm
requirements.
## [0.8.0] - 2026-05-24 ## [0.8.0] - 2026-05-24
### Changed ### Changed
+18
View File
@@ -8,6 +8,7 @@ Built to give AI assistants (Claude, etc.) read and control access to Syncthing'
- **Token-efficient output** — compact JSON by default; `concise=false` for full details - **Token-efficient output** — compact JSON by default; `concise=false` for full details
- **Multi-instance** — manage multiple Syncthing nodes from a single server - **Multi-instance** — manage multiple Syncthing nodes from a single server
- **Write-gated** — mutating tools require `SYNCTHING_WRITE_ENABLED=true`; destructive operations additionally require `confirm=true`
- **Replication analysis** — safe-to-remove flags and reclaimable space calculation - **Replication analysis** — safe-to-remove flags and reclaimable space calculation
- **Syncthing v2.x compatible** — tested against v2.0.x REST API - **Syncthing v2.x compatible** — tested against v2.0.x REST API
- **HTTP transport** — Streamable HTTP with bearer-token auth, Cloudflare Tunnel support - **HTTP transport** — Streamable HTTP with bearer-token auth, Cloudflare Tunnel support
@@ -98,6 +99,23 @@ Built to give AI assistants (Claude, etc.) read and control access to Syncthing'
| `syncthing_get_default_ignores` | Get default ignore patterns | No | | `syncthing_get_default_ignores` | Get default ignore patterns | No |
| `syncthing_set_default_ignores` | Set default ignore patterns | Yes | | `syncthing_set_default_ignores` | Set default ignore patterns | Yes |
## Write Safety
All mutating tools (the "Yes" rows above) refuse unless the environment variable
`SYNCTHING_WRITE_ENABLED=true` is set. The gate is off by default.
Destructive or disruptive operations additionally require `confirm=true` on the
call itself, with a refusal message explaining what the operation will do:
| Tool | Why confirm is required |
|------|------------------------|
| `syncthing_override_folder` | Pushes local state over remote edits — remote changes discarded cluster-wide |
| `syncthing_revert_folder` | Discards local changes on a receive-only folder |
| `syncthing_restart` | Stops the daemon and interrupts all active sync transfers |
| `syncthing_accept_device` | Admits a pending device into the cluster |
| `syncthing_accept_folder` | Starts syncing a remote folder's contents to local disk |
| `syncthing_set_ignores` | Replaces the folder's entire `.stignore` pattern set |
## Token Efficiency ## Token Efficiency
All read tools default to `concise=true`, producing compact JSON with minimal fields and All read tools default to `concise=true`, producing compact JSON with minimal fields and
+7
View File
@@ -103,6 +103,13 @@ replication analysis and safe disk-space reclamation.
`syncthing_accept_folder`, `syncthing_reject_folder`, `syncthing_set_ignores`, `syncthing_accept_folder`, `syncthing_reject_folder`, `syncthing_set_ignores`,
`syncthing_set_default_ignores` `syncthing_set_default_ignores`
All write tools require the environment variable `SYNCTHING_WRITE_ENABLED=true`
(off by default). Destructive/disruptive tools — `syncthing_override_folder`,
`syncthing_revert_folder`, `syncthing_restart`, `syncthing_accept_device`,
`syncthing_accept_folder`, `syncthing_set_ignores` — additionally require
`confirm=true` in the call; without it they return a refusal explaining what
the operation would do.
## Multi-Instance ## Multi-Instance
When multiple instances are configured, every tool accepts an `instance` parameter. When multiple instances are configured, every tool accepts an `instance` parameter.
+1 -1
View File
@@ -1,6 +1,6 @@
[project] [project]
name = "syncthing-blade-mcp" name = "syncthing-blade-mcp"
version = "0.8.0" version = "0.9.0"
description = "MCP server for Syncthing — token-efficient replication management, multi-instance, safe disk-space reclamation." description = "MCP server for Syncthing — token-efficient replication management, multi-instance, safe disk-space reclamation."
requires-python = ">=3.11" requires-python = ">=3.11"
dependencies = [ dependencies = [
+1 -1
View File
@@ -1,3 +1,3 @@
"""Syncthing MCP Server — manage Syncthing instances via MCP tools.""" """Syncthing MCP Server — manage Syncthing instances via MCP tools."""
__version__ = "0.8.0" __version__ = "0.9.0"
+37
View File
@@ -57,6 +57,28 @@ def _resolve_scope_folders(
return folder_ids, [] return folder_ids, []
# ---------------------------------------------------------------------------
# Write gate (AUD-04-02 / DD-385 Phase W)
# ---------------------------------------------------------------------------
def is_write_enabled() -> bool:
"""Check whether write operations are enabled."""
return os.environ.get("SYNCTHING_WRITE_ENABLED", "").strip().lower() == "true"
def require_write() -> str | None:
"""Return an error message if writes are disabled, else None."""
if is_write_enabled():
return None
return "Write operations are disabled. Set SYNCTHING_WRITE_ENABLED=true to enable."
_CONFIRM_DESCRIPTION = (
"Must be true to confirm — this operation is destructive or disruptive."
)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Read-oriented base models (include concise toggle for token efficiency) # Read-oriented base models (include concise toggle for token efficiency)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@@ -144,6 +166,18 @@ class DeviceWriteParams(WriteParams):
) )
class ConfirmWriteParams(WriteParams):
"""Write tool requiring explicit confirmation (destructive/disruptive)."""
confirm: bool = Field(False, description=_CONFIRM_DESCRIPTION)
class ConfirmFolderWriteParams(FolderWriteParams):
"""Folder write tool requiring explicit confirmation (destructive/disruptive)."""
confirm: bool = Field(False, description=_CONFIRM_DESCRIPTION)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Specialised input models # Specialised input models
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@@ -158,6 +192,7 @@ class AcceptDeviceInput(WriteParams):
None, None,
description="Friendly name to assign. If omitted, uses the name from the pending request.", description="Friendly name to assign. If omitted, uses the name from the pending request.",
) )
confirm: bool = Field(False, description=_CONFIRM_DESCRIPTION)
class AcceptFolderInput(WriteParams): class AcceptFolderInput(WriteParams):
@@ -169,6 +204,7 @@ class AcceptFolderInput(WriteParams):
None, None,
description="Local path for the folder. If omitted, uses Syncthing's default path.", description="Local path for the folder. If omitted, uses Syncthing's default path.",
) )
confirm: bool = Field(False, description=_CONFIRM_DESCRIPTION)
class RejectFolderInput(WriteParams): class RejectFolderInput(WriteParams):
@@ -189,6 +225,7 @@ class SetIgnoresInput(WriteParams):
..., ...,
description="List of ignore patterns (e.g. ['*.tmp', '.DS_Store', '// #include'])", description="List of ignore patterns (e.g. ['*.tmp', '.DS_Store', '// #include'])",
) )
confirm: bool = Field(False, description=_CONFIRM_DESCRIPTION)
class SetDefaultIgnoresInput(WriteParams): class SetDefaultIgnoresInput(WriteParams):
+9
View File
@@ -148,6 +148,15 @@ async def app_lifespan(app):
mcp = FastMCP( mcp = FastMCP(
"syncthing_mcp", "syncthing_mcp",
instructions=(
"Syncthing replication operations across one or more instances. "
"Monitor folders, devices, and sync health; manage pending devices/"
"folders, ignore patterns, and conflict resolution. Multi-instance: "
"pass instance= to target a specific node. Write operations require "
"SYNCTHING_WRITE_ENABLED=true. Destructive/disruptive operations "
"(override, revert, restart, accept device/folder, replace ignores) "
"also require confirm=true."
),
lifespan=app_lifespan, lifespan=app_lifespan,
stateless_http=True, stateless_http=True,
json_response=True, json_response=True,
+52 -9
View File
@@ -11,6 +11,7 @@ from syncthing_mcp.models import (
SetDefaultIgnoresInput, SetDefaultIgnoresInput,
SetIgnoresInput, SetIgnoresInput,
WriteParams, WriteParams,
require_write,
) )
from syncthing_mcp.registry import get_instance, handle_error_global from syncthing_mcp.registry import get_instance, handle_error_global
from syncthing_mcp.server import mcp from syncthing_mcp.server import mcp
@@ -72,13 +73,23 @@ async def syncthing_pending_folders(params: ReadParams) -> str:
annotations={ annotations={
"title": "Accept Pending Device", "title": "Accept Pending Device",
"readOnlyHint": False, "readOnlyHint": False,
"destructiveHint": False, "destructiveHint": True,
"idempotentHint": False, "idempotentHint": False,
"openWorldHint": False, "openWorldHint": False,
}, },
) )
async def syncthing_accept_device(params: AcceptDeviceInput) -> str: async def syncthing_accept_device(params: AcceptDeviceInput) -> str:
"""Accept a pending device by adding it to the Syncthing configuration.""" """Accept a pending device by adding it to the Syncthing configuration.
Requires SYNCTHING_WRITE_ENABLED=true and confirm=true."""
gate = require_write()
if gate:
return fmt({"error": gate})
if not params.confirm:
return fmt({"error": (
"Accepting a pending device admits it into the Syncthing cluster, "
"allowing it to connect and be offered folder shares. "
"Set confirm=true to proceed."
)})
try: try:
client = get_instance(params.instance) client = get_instance(params.instance)
pending = await client._get("/rest/cluster/pending/devices") pending = await client._get("/rest/cluster/pending/devices")
@@ -112,7 +123,11 @@ async def syncthing_accept_device(params: AcceptDeviceInput) -> str:
}, },
) )
async def syncthing_reject_device(params: DeviceWriteParams) -> str: async def syncthing_reject_device(params: DeviceWriteParams) -> str:
"""Dismiss a pending device connection request.""" """Dismiss a pending device connection request.
Requires SYNCTHING_WRITE_ENABLED=true."""
gate = require_write()
if gate:
return fmt({"error": gate})
try: try:
client = get_instance(params.instance) client = get_instance(params.instance)
await client._delete( await client._delete(
@@ -133,13 +148,23 @@ async def syncthing_reject_device(params: DeviceWriteParams) -> str:
annotations={ annotations={
"title": "Accept Pending Folder Offer", "title": "Accept Pending Folder Offer",
"readOnlyHint": False, "readOnlyHint": False,
"destructiveHint": False, "destructiveHint": True,
"idempotentHint": False, "idempotentHint": False,
"openWorldHint": False, "openWorldHint": False,
}, },
) )
async def syncthing_accept_folder(params: AcceptFolderInput) -> str: async def syncthing_accept_folder(params: AcceptFolderInput) -> str:
"""Accept a pending folder share offer. Uses default folder config as template.""" """Accept a pending folder share offer. Uses default folder config as template.
Requires SYNCTHING_WRITE_ENABLED=true and confirm=true."""
gate = require_write()
if gate:
return fmt({"error": gate})
if not params.confirm:
return fmt({"error": (
"Accepting a pending folder adds it to the configuration and "
"starts syncing its contents to local disk from the offering "
"device(s). Set confirm=true to proceed."
)})
try: try:
client = get_instance(params.instance) client = get_instance(params.instance)
pending = await client._get("/rest/cluster/pending/folders") pending = await client._get("/rest/cluster/pending/folders")
@@ -184,7 +209,11 @@ async def syncthing_accept_folder(params: AcceptFolderInput) -> str:
}, },
) )
async def syncthing_reject_folder(params: RejectFolderInput) -> str: async def syncthing_reject_folder(params: RejectFolderInput) -> str:
"""Dismiss a pending folder share offer.""" """Dismiss a pending folder share offer.
Requires SYNCTHING_WRITE_ENABLED=true."""
gate = require_write()
if gate:
return fmt({"error": gate})
try: try:
client = get_instance(params.instance) client = get_instance(params.instance)
delete_params: dict[str, str] = {"folder": params.folder_id} delete_params: dict[str, str] = {"folder": params.folder_id}
@@ -239,13 +268,23 @@ async def syncthing_get_ignores(params: FolderReadParams) -> str:
annotations={ annotations={
"title": "Set Folder Ignore Patterns", "title": "Set Folder Ignore Patterns",
"readOnlyHint": False, "readOnlyHint": False,
"destructiveHint": False, "destructiveHint": True,
"idempotentHint": True, "idempotentHint": True,
"openWorldHint": False, "openWorldHint": False,
}, },
) )
async def syncthing_set_ignores(params: SetIgnoresInput) -> str: async def syncthing_set_ignores(params: SetIgnoresInput) -> str:
"""Set .stignore patterns for a folder. Replaces all existing patterns.""" """Set .stignore patterns for a folder. Replaces all existing patterns.
Requires SYNCTHING_WRITE_ENABLED=true and confirm=true."""
gate = require_write()
if gate:
return fmt({"error": gate})
if not params.confirm:
return fmt({"error": (
"This REPLACES the folder's entire .stignore pattern set — "
"existing patterns are lost and the change alters which files "
"sync. Set confirm=true to proceed."
)})
try: try:
client = get_instance(params.instance) client = get_instance(params.instance)
await client._post( await client._post(
@@ -297,7 +336,11 @@ async def syncthing_get_default_ignores(params: ReadParams) -> str:
}, },
) )
async def syncthing_set_default_ignores(params: SetDefaultIgnoresInput) -> str: async def syncthing_set_default_ignores(params: SetDefaultIgnoresInput) -> str:
"""Set the default ignore patterns for newly created folders.""" """Set the default ignore patterns for newly created folders.
Requires SYNCTHING_WRITE_ENABLED=true."""
gate = require_write()
if gate:
return fmt({"error": gate})
try: try:
client = get_instance(params.instance) client = get_instance(params.instance)
await client._put( await client._put(
+43 -9
View File
@@ -15,6 +15,7 @@ from syncthing_mcp.formatters import (
) )
from syncthing_mcp.models import ( from syncthing_mcp.models import (
BrowseFolderInput, BrowseFolderInput,
ConfirmFolderWriteParams,
FileInfoInput, FileInfoInput,
FolderNeedInput, FolderNeedInput,
FolderReadParams, FolderReadParams,
@@ -22,6 +23,7 @@ from syncthing_mcp.models import (
ReadParams, ReadParams,
RemoteNeedInput, RemoteNeedInput,
_resolve_scope_folders, _resolve_scope_folders,
require_write,
) )
from syncthing_mcp.registry import get_instance, handle_error_global from syncthing_mcp.registry import get_instance, handle_error_global
from syncthing_mcp.server import mcp from syncthing_mcp.server import mcp
@@ -316,7 +318,11 @@ async def syncthing_replication_report(params: ReadParams) -> str:
) )
async def syncthing_pause_folder(params: FolderWriteParams) -> str: async def syncthing_pause_folder(params: FolderWriteParams) -> str:
"""Pause syncing for a folder. Does NOT delete data — only stops sync """Pause syncing for a folder. Does NOT delete data — only stops sync
so you can safely remove the local copy without propagating deletions.""" so you can safely remove the local copy without propagating deletions.
Requires SYNCTHING_WRITE_ENABLED=true."""
gate = require_write()
if gate:
return fmt({"error": gate})
try: try:
client = get_instance(params.instance) client = get_instance(params.instance)
folder_cfg = await client._get(f"/rest/config/folders/{params.folder_id}") folder_cfg = await client._get(f"/rest/config/folders/{params.folder_id}")
@@ -344,7 +350,11 @@ async def syncthing_pause_folder(params: FolderWriteParams) -> str:
async def syncthing_resume_folder(params: FolderWriteParams) -> str: async def syncthing_resume_folder(params: FolderWriteParams) -> str:
"""Resume syncing for a paused folder. WARNING: if local data was deleted """Resume syncing for a paused folder. WARNING: if local data was deleted
while paused, behaviour depends on folder type (sendreceive may propagate while paused, behaviour depends on folder type (sendreceive may propagate
deletions; receiveonly will re-download).""" deletions; receiveonly will re-download).
Requires SYNCTHING_WRITE_ENABLED=true."""
gate = require_write()
if gate:
return fmt({"error": gate})
try: try:
client = get_instance(params.instance) client = get_instance(params.instance)
folder_cfg = await client._get(f"/rest/config/folders/{params.folder_id}") folder_cfg = await client._get(f"/rest/config/folders/{params.folder_id}")
@@ -372,7 +382,11 @@ async def syncthing_resume_folder(params: FolderWriteParams) -> str:
}, },
) )
async def syncthing_scan_folder(params: FolderWriteParams) -> str: async def syncthing_scan_folder(params: FolderWriteParams) -> str:
"""Trigger an immediate rescan of a folder to refresh its status.""" """Trigger an immediate rescan of a folder to refresh its status.
Requires SYNCTHING_WRITE_ENABLED=true."""
gate = require_write()
if gate:
return fmt({"error": gate})
try: try:
client = get_instance(params.instance) client = get_instance(params.instance)
await client._post("/rest/db/scan", params={"folder": params.folder_id}) await client._post("/rest/db/scan", params={"folder": params.folder_id})
@@ -689,13 +703,23 @@ async def syncthing_remote_need(params: RemoteNeedInput) -> str:
annotations={ annotations={
"title": "Override Remote Changes (Send-Only)", "title": "Override Remote Changes (Send-Only)",
"readOnlyHint": False, "readOnlyHint": False,
"destructiveHint": False, "destructiveHint": True,
"idempotentHint": True, "idempotentHint": True,
"openWorldHint": False, "openWorldHint": False,
}, },
) )
async def syncthing_override_folder(params: FolderWriteParams) -> str: async def syncthing_override_folder(params: ConfirmFolderWriteParams) -> str:
"""Override remote changes on a send-only folder (make local authoritative).""" """Override remote changes on a send-only folder (make local authoritative).
Requires SYNCTHING_WRITE_ENABLED=true and confirm=true."""
gate = require_write()
if gate:
return fmt({"error": gate})
if not params.confirm:
return fmt({"error": (
"Override pushes this device's local state over remote edits on a "
"send-only folder — remote changes are discarded cluster-wide. "
"Set confirm=true to proceed."
)})
try: try:
client = get_instance(params.instance) client = get_instance(params.instance)
await client._post("/rest/db/override", params={"folder": params.folder_id}) await client._post("/rest/db/override", params={"folder": params.folder_id})
@@ -713,13 +737,23 @@ async def syncthing_override_folder(params: FolderWriteParams) -> str:
annotations={ annotations={
"title": "Revert Local Changes (Receive-Only)", "title": "Revert Local Changes (Receive-Only)",
"readOnlyHint": False, "readOnlyHint": False,
"destructiveHint": False, "destructiveHint": True,
"idempotentHint": True, "idempotentHint": True,
"openWorldHint": False, "openWorldHint": False,
}, },
) )
async def syncthing_revert_folder(params: FolderWriteParams) -> str: async def syncthing_revert_folder(params: ConfirmFolderWriteParams) -> str:
"""Revert local changes on a receive-only folder (pull remote state).""" """Revert local changes on a receive-only folder (pull remote state).
Requires SYNCTHING_WRITE_ENABLED=true and confirm=true."""
gate = require_write()
if gate:
return fmt({"error": gate})
if not params.confirm:
return fmt({"error": (
"Revert discards this device's local changes on a receive-only "
"folder and re-downloads the remote state — local edits are lost. "
"Set confirm=true to proceed."
)})
try: try:
client = get_instance(params.instance) client = get_instance(params.instance)
await client._post("/rest/db/revert", params={"folder": params.folder_id}) await client._post("/rest/db/revert", params={"folder": params.folder_id})
+25 -5
View File
@@ -6,7 +6,13 @@ from typing import Any
import httpx import httpx
from syncthing_mcp.formatters import append_meta, fmt, format_bytes, meta_envelope, truncate from syncthing_mcp.formatters import append_meta, fmt, format_bytes, meta_envelope, truncate
from syncthing_mcp.models import ReadParams, WriteParams, _resolve_scope_folders from syncthing_mcp.models import (
ConfirmWriteParams,
ReadParams,
WriteParams,
_resolve_scope_folders,
require_write,
)
from syncthing_mcp.registry import get_instance, handle_error_global from syncthing_mcp.registry import get_instance, handle_error_global
from syncthing_mcp.server import mcp from syncthing_mcp.server import mcp
@@ -93,7 +99,11 @@ async def syncthing_system_errors(params: ReadParams) -> str:
}, },
) )
async def syncthing_clear_errors(params: WriteParams) -> str: async def syncthing_clear_errors(params: WriteParams) -> str:
"""Clear the system error log.""" """Clear the system error log.
Requires SYNCTHING_WRITE_ENABLED=true."""
gate = require_write()
if gate:
return fmt({"error": gate})
try: try:
client = get_instance(params.instance) client = get_instance(params.instance)
await client._post("/rest/system/error/clear") await client._post("/rest/system/error/clear")
@@ -232,13 +242,23 @@ async def syncthing_restart_required(params: ReadParams) -> str:
annotations={ annotations={
"title": "Restart Syncthing", "title": "Restart Syncthing",
"readOnlyHint": False, "readOnlyHint": False,
"destructiveHint": False, "destructiveHint": True,
"idempotentHint": True, "idempotentHint": True,
"openWorldHint": False, "openWorldHint": False,
}, },
) )
async def syncthing_restart(params: WriteParams) -> str: async def syncthing_restart(params: ConfirmWriteParams) -> str:
"""Restart the Syncthing service. Temporarily stops all sync activity.""" """Restart the Syncthing service. Temporarily stops all sync activity.
Requires SYNCTHING_WRITE_ENABLED=true and confirm=true."""
gate = require_write()
if gate:
return fmt({"error": gate})
if not params.confirm:
return fmt({"error": (
"Restarting stops the Syncthing daemon and interrupts all active "
"sync transfers on this instance until it comes back up. "
"Set confirm=true to proceed."
)})
try: try:
client = get_instance(params.instance) client = get_instance(params.instance)
try: try:
+9
View File
@@ -76,6 +76,11 @@ setup:
required: false required: false
placeholder: '{"name": {"url": "...", "apiKey": "..."}}' placeholder: '{"name": {"url": "...", "apiKey": "..."}}'
help: "JSON object for multi-instance mode. Overrides API Key and URL above" help: "JSON object for multi-instance mode. Overrides API Key and URL above"
- key: SYNCTHING_WRITE_ENABLED
label: "Enable Write Operations"
required: false
placeholder: "true"
help: "Set to 'true' to allow mutating tools (pause/resume, accept, restart, override, ignores). Off by default; destructive operations also require confirm=true per call"
install: install:
runtime: uv runtime: uv
@@ -95,6 +100,10 @@ env:
secret: true secret: true
required: false required: false
description: "JSON object for multi-instance mode (overrides API_KEY/URL)" description: "JSON object for multi-instance mode (overrides API_KEY/URL)"
- name: SYNCTHING_WRITE_ENABLED
secret: false
required: false
description: "Set to 'true' to enable mutating tools; destructive/disruptive operations also require confirm=true (default: writes disabled)"
conformance: conformance:
required: "38" required: "38"
+6
View File
@@ -157,6 +157,12 @@ def single_instance_env(monkeypatch):
monkeypatch.delenv("SYNCTHING_INSTANCES", raising=False) monkeypatch.delenv("SYNCTHING_INSTANCES", raising=False)
@pytest.fixture
def write_enabled_env(monkeypatch):
"""Enable the AUD-04-02 write gate for tests exercising mutating tools."""
monkeypatch.setenv("SYNCTHING_WRITE_ENABLED", "true")
@pytest.fixture @pytest.fixture
def multi_instance_env(monkeypatch): def multi_instance_env(monkeypatch):
"""Set env vars for multi-instance mode.""" """Set env vars for multi-instance mode."""
+11 -11
View File
@@ -49,7 +49,7 @@ class TestPendingFolders:
class TestAcceptDevice: class TestAcceptDevice:
async def test_accept(self, mock_api): async def test_accept(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.config import syncthing_accept_device from syncthing_mcp.tools.config import syncthing_accept_device
mock_api.get("/rest/cluster/pending/devices").respond(json={ mock_api.get("/rest/cluster/pending/devices").respond(json={
@@ -60,14 +60,14 @@ class TestAcceptDevice:
}) })
mock_api.post("/rest/config/devices").respond(status_code=200, content=b"") mock_api.post("/rest/config/devices").respond(status_code=200, content=b"")
result = json.loads(await syncthing_accept_device( result = json.loads(await syncthing_accept_device(
AcceptDeviceInput(device_id=DEVICE_ID_REMOTE2) AcceptDeviceInput(device_id=DEVICE_ID_REMOTE2, confirm=True)
)) ))
assert result["status"] == "accepted" assert result["status"] == "accepted"
assert result["name"] == "new-device" assert result["name"] == "new-device"
class TestRejectDevice: class TestRejectDevice:
async def test_reject(self, mock_api): async def test_reject(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.config import syncthing_reject_device from syncthing_mcp.tools.config import syncthing_reject_device
mock_api.delete("/rest/cluster/pending/devices").respond(status_code=200, content=b"") mock_api.delete("/rest/cluster/pending/devices").respond(status_code=200, content=b"")
@@ -78,7 +78,7 @@ class TestRejectDevice:
class TestAcceptFolder: class TestAcceptFolder:
async def test_accept(self, mock_api): async def test_accept(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.config import syncthing_accept_folder from syncthing_mcp.tools.config import syncthing_accept_folder
mock_api.get("/rest/cluster/pending/folders").respond(json={ mock_api.get("/rest/cluster/pending/folders").respond(json={
@@ -94,22 +94,22 @@ class TestAcceptFolder:
}) })
mock_api.post("/rest/config/folders").respond(status_code=200, content=b"") mock_api.post("/rest/config/folders").respond(status_code=200, content=b"")
result = json.loads(await syncthing_accept_folder( result = json.loads(await syncthing_accept_folder(
AcceptFolderInput(folder_id="new-folder") AcceptFolderInput(folder_id="new-folder", confirm=True)
)) ))
assert result["status"] == "accepted" assert result["status"] == "accepted"
assert result["label"] == "Shared Docs" assert result["label"] == "Shared Docs"
async def test_not_pending(self, mock_api): async def test_not_pending(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.config import syncthing_accept_folder from syncthing_mcp.tools.config import syncthing_accept_folder
result = json.loads(await syncthing_accept_folder( result = json.loads(await syncthing_accept_folder(
AcceptFolderInput(folder_id="nonexistent") AcceptFolderInput(folder_id="nonexistent", confirm=True)
)) ))
assert "error" in result assert "error" in result
class TestRejectFolder: class TestRejectFolder:
async def test_reject(self, mock_api): async def test_reject(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.config import syncthing_reject_folder from syncthing_mcp.tools.config import syncthing_reject_folder
mock_api.delete("/rest/cluster/pending/folders").respond(status_code=200, content=b"") mock_api.delete("/rest/cluster/pending/folders").respond(status_code=200, content=b"")
@@ -132,12 +132,12 @@ class TestGetIgnores:
class TestSetIgnores: class TestSetIgnores:
async def test_set(self, mock_api): async def test_set(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.config import syncthing_set_ignores from syncthing_mcp.tools.config import syncthing_set_ignores
mock_api.post("/rest/db/ignores").respond(status_code=200, content=b"") mock_api.post("/rest/db/ignores").respond(status_code=200, content=b"")
result = json.loads(await syncthing_set_ignores( result = json.loads(await syncthing_set_ignores(
SetIgnoresInput(folder_id=FOLDER_ID, patterns=["*.log", "node_modules"]) SetIgnoresInput(folder_id=FOLDER_ID, patterns=["*.log", "node_modules"], confirm=True)
)) ))
assert result["status"] == "updated" assert result["status"] == "updated"
assert result["count"] == 2 assert result["count"] == 2
@@ -153,7 +153,7 @@ class TestGetDefaultIgnores:
class TestSetDefaultIgnores: class TestSetDefaultIgnores:
async def test_set(self, mock_api): async def test_set(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.config import syncthing_set_default_ignores from syncthing_mcp.tools.config import syncthing_set_default_ignores
mock_api.put("/rest/config/defaults/ignores").respond( mock_api.put("/rest/config/defaults/ignores").respond(
+12 -7
View File
@@ -7,6 +7,7 @@ import respx
from syncthing_mcp.models import ( from syncthing_mcp.models import (
BrowseFolderInput, BrowseFolderInput,
ConfirmFolderWriteParams,
EmptyInput, EmptyInput,
FileInfoInput, FileInfoInput,
FolderInput, FolderInput,
@@ -281,7 +282,7 @@ class TestReplicationReport:
class TestPauseFolder: class TestPauseFolder:
async def test_pause(self, mock_api): async def test_pause(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.folders import syncthing_pause_folder from syncthing_mcp.tools.folders import syncthing_pause_folder
mock_api.get(f"/rest/config/folders/{FOLDER_ID}").respond( mock_api.get(f"/rest/config/folders/{FOLDER_ID}").respond(
@@ -296,7 +297,7 @@ class TestPauseFolder:
class TestResumeFolder: class TestResumeFolder:
async def test_resume(self, mock_api): async def test_resume(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.folders import syncthing_resume_folder from syncthing_mcp.tools.folders import syncthing_resume_folder
mock_api.get(f"/rest/config/folders/{FOLDER_ID}").respond( mock_api.get(f"/rest/config/folders/{FOLDER_ID}").respond(
@@ -312,7 +313,7 @@ class TestResumeFolder:
class TestScanFolder: class TestScanFolder:
async def test_scan(self, mock_api): async def test_scan(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.folders import syncthing_scan_folder from syncthing_mcp.tools.folders import syncthing_scan_folder
mock_api.post("/rest/db/scan").respond(status_code=200, content=b"") mock_api.post("/rest/db/scan").respond(status_code=200, content=b"")
@@ -577,18 +578,22 @@ class TestRemoteNeed:
class TestOverrideFolder: class TestOverrideFolder:
async def test_override(self, mock_api): async def test_override(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.folders import syncthing_override_folder from syncthing_mcp.tools.folders import syncthing_override_folder
mock_api.post("/rest/db/override").respond(status_code=200, content=b"") mock_api.post("/rest/db/override").respond(status_code=200, content=b"")
result = json.loads(await syncthing_override_folder(FolderInput(folder_id=FOLDER_ID))) result = json.loads(await syncthing_override_folder(
ConfirmFolderWriteParams(folder_id=FOLDER_ID, confirm=True)
))
assert result["status"] == "override_requested" assert result["status"] == "override_requested"
class TestRevertFolder: class TestRevertFolder:
async def test_revert(self, mock_api): async def test_revert(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.folders import syncthing_revert_folder from syncthing_mcp.tools.folders import syncthing_revert_folder
mock_api.post("/rest/db/revert").respond(status_code=200, content=b"") mock_api.post("/rest/db/revert").respond(status_code=200, content=b"")
result = json.loads(await syncthing_revert_folder(FolderInput(folder_id=FOLDER_ID))) result = json.loads(await syncthing_revert_folder(
ConfirmFolderWriteParams(folder_id=FOLDER_ID, confirm=True)
))
assert result["status"] == "revert_requested" assert result["status"] == "revert_requested"
+4 -4
View File
@@ -6,7 +6,7 @@ import pytest
import respx import respx
from httpx import Response from httpx import Response
from syncthing_mcp.models import EmptyInput from syncthing_mcp.models import ConfirmWriteParams, EmptyInput
from syncthing_mcp.registry import reload_instances from syncthing_mcp.registry import reload_instances
from tests.conftest import ( from tests.conftest import (
BASE_URL, BASE_URL,
@@ -59,7 +59,7 @@ class TestSystemErrors:
class TestClearErrors: class TestClearErrors:
async def test_clear(self, mock_api): async def test_clear(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.system import syncthing_clear_errors from syncthing_mcp.tools.system import syncthing_clear_errors
mock_api.post("/rest/system/error/clear").respond(status_code=200, content=b"") mock_api.post("/rest/system/error/clear").respond(status_code=200, content=b"")
@@ -100,11 +100,11 @@ class TestRestartRequired:
class TestRestart: class TestRestart:
async def test_restart(self, mock_api): async def test_restart(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.system import syncthing_restart from syncthing_mcp.tools.system import syncthing_restart
mock_api.post("/rest/system/restart").respond(status_code=200, content=b"") mock_api.post("/rest/system/restart").respond(status_code=200, content=b"")
result = json.loads(await syncthing_restart(EmptyInput())) result = json.loads(await syncthing_restart(ConfirmWriteParams(confirm=True)))
assert result["status"] == "restart_initiated" assert result["status"] == "restart_initiated"
+133
View File
@@ -0,0 +1,133 @@
"""Regression tests for the write gate + confirm discipline (AUD-04-02 / DD-385 Phase W).
Every mutating tool must refuse when ``SYNCTHING_WRITE_ENABLED`` is not
``true``; destructive/disruptive tools must additionally refuse without
``confirm=true`` even when the gate is open.
"""
import json
import pytest
from syncthing_mcp.models import (
AcceptDeviceInput,
AcceptFolderInput,
ConfirmFolderWriteParams,
ConfirmWriteParams,
DeviceInput,
PauseFolderInput,
RejectFolderInput,
SetDefaultIgnoresInput,
SetIgnoresInput,
WriteParams,
)
from syncthing_mcp.registry import reload_instances
from syncthing_mcp.tools.config import (
syncthing_accept_device,
syncthing_accept_folder,
syncthing_reject_device,
syncthing_reject_folder,
syncthing_set_default_ignores,
syncthing_set_ignores,
)
from syncthing_mcp.tools.folders import (
syncthing_override_folder,
syncthing_pause_folder,
syncthing_resume_folder,
syncthing_revert_folder,
syncthing_scan_folder,
)
from syncthing_mcp.tools.system import syncthing_clear_errors, syncthing_restart
from tests.conftest import DEVICE_ID_REMOTE2, FOLDER_ID
WRITE_DISABLED_MSG = (
"Write operations are disabled. Set SYNCTHING_WRITE_ENABLED=true to enable."
)
@pytest.fixture(autouse=True)
def _setup(single_instance_env, monkeypatch):
monkeypatch.delenv("SYNCTHING_WRITE_ENABLED", raising=False)
reload_instances()
yield
reload_instances()
# Every mutating tool, with valid params. confirm=True so the gated-off test
# proves the env gate refuses even a fully-confirmed call.
ALL_MUTATING = [
pytest.param(syncthing_pause_folder, PauseFolderInput(folder_id=FOLDER_ID), id="pause_folder"),
pytest.param(syncthing_resume_folder, PauseFolderInput(folder_id=FOLDER_ID), id="resume_folder"),
pytest.param(syncthing_scan_folder, PauseFolderInput(folder_id=FOLDER_ID), id="scan_folder"),
pytest.param(syncthing_override_folder, ConfirmFolderWriteParams(folder_id=FOLDER_ID, confirm=True), id="override_folder"),
pytest.param(syncthing_revert_folder, ConfirmFolderWriteParams(folder_id=FOLDER_ID, confirm=True), id="revert_folder"),
pytest.param(syncthing_clear_errors, WriteParams(), id="clear_errors"),
pytest.param(syncthing_restart, ConfirmWriteParams(confirm=True), id="restart"),
pytest.param(syncthing_accept_device, AcceptDeviceInput(device_id=DEVICE_ID_REMOTE2, confirm=True), id="accept_device"),
pytest.param(syncthing_reject_device, DeviceInput(device_id=DEVICE_ID_REMOTE2), id="reject_device"),
pytest.param(syncthing_accept_folder, AcceptFolderInput(folder_id=FOLDER_ID, confirm=True), id="accept_folder"),
pytest.param(syncthing_reject_folder, RejectFolderInput(folder_id=FOLDER_ID), id="reject_folder"),
pytest.param(syncthing_set_ignores, SetIgnoresInput(folder_id=FOLDER_ID, patterns=["*.tmp"], confirm=True), id="set_ignores"),
pytest.param(syncthing_set_default_ignores, SetDefaultIgnoresInput(lines=[".DS_Store"]), id="set_default_ignores"),
]
# Destructive/disruptive tools requiring confirm=true, with confirm left False.
DESTRUCTIVE_NO_CONFIRM = [
pytest.param(syncthing_override_folder, ConfirmFolderWriteParams(folder_id=FOLDER_ID), id="override_folder"),
pytest.param(syncthing_revert_folder, ConfirmFolderWriteParams(folder_id=FOLDER_ID), id="revert_folder"),
pytest.param(syncthing_restart, ConfirmWriteParams(), id="restart"),
pytest.param(syncthing_accept_device, AcceptDeviceInput(device_id=DEVICE_ID_REMOTE2), id="accept_device"),
pytest.param(syncthing_accept_folder, AcceptFolderInput(folder_id=FOLDER_ID), id="accept_folder"),
pytest.param(syncthing_set_ignores, SetIgnoresInput(folder_id=FOLDER_ID, patterns=["*.tmp"]), id="set_ignores"),
]
class TestWriteGateOff:
@pytest.mark.parametrize("tool, params", ALL_MUTATING)
async def test_refuses_when_gate_unset(self, mock_api, tool, params):
result = json.loads(await tool(params))
assert result == {"error": WRITE_DISABLED_MSG}
@pytest.mark.parametrize("tool, params", ALL_MUTATING)
async def test_refuses_when_gate_not_true(self, mock_api, monkeypatch, tool, params):
monkeypatch.setenv("SYNCTHING_WRITE_ENABLED", "1")
result = json.loads(await tool(params))
assert result == {"error": WRITE_DISABLED_MSG}
class TestConfirmRequired:
@pytest.mark.parametrize("tool, params", DESTRUCTIVE_NO_CONFIRM)
async def test_refuses_without_confirm(self, mock_api, write_enabled_env, tool, params):
result = json.loads(await tool(params))
assert "error" in result
assert "confirm=true" in result["error"]
# Refusal must not be the gate message — the gate is open.
assert result["error"] != WRITE_DISABLED_MSG
class TestGatedOnProceeds:
async def test_restart_with_confirm(self, mock_api, write_enabled_env):
mock_api.post("/rest/system/restart").respond(status_code=200, content=b"")
result = json.loads(await syncthing_restart(ConfirmWriteParams(confirm=True)))
assert result["status"] == "restart_initiated"
async def test_override_with_confirm(self, mock_api, write_enabled_env):
mock_api.post("/rest/db/override").respond(status_code=200, content=b"")
result = json.loads(await syncthing_override_folder(
ConfirmFolderWriteParams(folder_id=FOLDER_ID, confirm=True)
))
assert result["status"] == "override_requested"
async def test_set_ignores_with_confirm(self, mock_api, write_enabled_env):
mock_api.post("/rest/db/ignores").respond(status_code=200, content=b"")
result = json.loads(await syncthing_set_ignores(
SetIgnoresInput(folder_id=FOLDER_ID, patterns=["*.tmp"], confirm=True)
))
assert result["status"] == "updated"
async def test_non_destructive_needs_no_confirm(self, mock_api, write_enabled_env):
mock_api.post("/rest/db/scan").respond(status_code=200, content=b"")
result = json.loads(await syncthing_scan_folder(
PauseFolderInput(folder_id=FOLDER_ID)
))
assert result["status"] == "scan_requested"
Generated
+1 -1
View File
@@ -837,7 +837,7 @@ wheels = [
[[package]] [[package]]
name = "syncthing-blade-mcp" name = "syncthing-blade-mcp"
version = "0.8.0" version = "0.9.0"
source = { editable = "." } source = { editable = "." }
dependencies = [ dependencies = [
{ name = "httpx" }, { name = "httpx" },