Skip to content

Open-source Revit MCP server: let Claude and other AI assistants read and edit BIM models, with human approval on every change.

Fix approval gate blocking draft-only plan tools (#63)

A. Sam Mohammad9782afd71859
diff --git a/docs/tools-generated.md b/docs/tools-generated.md
index 1775d33..8915127 100644
--- a/docs/tools-generated.md
+++ b/docs/tools-generated.md
@@ -85,8 +85,8 @@ This catalog lists all tools exposed by the AEC Model Bridge providers.
| `parameter_manager_diff_params` | Compare parameter values between two saved snapshots and list the differences. | No | sync |
| `parameter_manager_export_params_csv` | Export parameters of the matching snapshot elements to a CSV file in the workspace. | No | sync |
| `parameter_manager_filter_params` | Return a parameter grid for the elements of a snapshot that match a filter, optionally including read-only parameters. | No | sync |
-| `parameter_manager_import_params_csv` | Import parameter values from a CSV file in the workspace and apply them to elements. | Yes | sync |
-| `parameter_manager_plan_set_params` | Create a draft ActionPlan that sets parameter values on the elements of a snapshot matching a filter. | Yes | sync |
+| `parameter_manager_import_params_csv` | Read parameter values from a CSV file in the workspace and create a draft ActionPlan that applies them. | No | sync |
+| `parameter_manager_plan_set_params` | Create a draft ActionPlan that sets parameter values on the elements of a snapshot matching a filter. | No | sync |
| `qaqc_checker_list_issues` | List recorded QA/QC issues for a document, optionally filtered by status and severity. | No | sync |
| `qaqc_checker_list_rules` | List the QA/QC rules that are available, optionally for one rule pack. | No | sync |
| `qaqc_checker_resolve_issue` | Mark one recorded QA/QC issue as resolved. | No | sync |
diff --git a/packages/mcp-server-revit/src/revit_mcp_server/modules/parameter_manager/module.json b/packages/mcp-server-revit/src/revit_mcp_server/modules/parameter_manager/module.json
index 417d1fd..e867636 100644
--- a/packages/mcp-server-revit/src/revit_mcp_server/modules/parameter_manager/module.json
+++ b/packages/mcp-server-revit/src/revit_mcp_server/modules/parameter_manager/module.json
@@ -52,9 +52,7 @@
"title": "Plan Parameter Set",
"surface": ["mcp"],
"execution_mode": "sync",
- "is_mutating": true,
- "destructive": false,
- "requires_plan": true,
+ "is_mutating": false,
"input_schema": {
"type": "object",
"properties": {
@@ -90,9 +88,7 @@
"title": "Import Parameters from CSV",
"surface": ["mcp"],
"execution_mode": "sync",
- "is_mutating": true,
- "destructive": false,
- "requires_plan": true,
+ "is_mutating": false,
"input_schema": {
"type": "object",
"properties": {
diff --git a/packages/mcp-server-revit/src/revit_mcp_server/modules/parameter_manager/module.py b/packages/mcp-server-revit/src/revit_mcp_server/modules/parameter_manager/module.py
index 726b769..bb91892 100644
--- a/packages/mcp-server-revit/src/revit_mcp_server/modules/parameter_manager/module.py
+++ b/packages/mcp-server-revit/src/revit_mcp_server/modules/parameter_manager/module.py
@@ -39,8 +39,24 @@ STORAGE_TYPE_VALIDATORS: Dict[str, type] = {
def _workspace_dir(workspace: Any) -> Path:
return workspace.allowed_directories[0]
+def _confined(workspace: Any, *parts: str) -> Path:
+ """Join parts under the workspace and refuse anything that resolves outside it.
+
+ Snapshot ids and file names come from the caller, and the draft-only tools run
+ without an approved plan, so '..', absolute paths and symlinks must not escape.
+ """
+ base = _workspace_dir(workspace)
+ candidate = (base.joinpath(*parts)).resolve()
+ checker = getattr(workspace, "assert_in_workspace", None)
+ if checker is not None:
+ return checker(candidate)
+ if not candidate.is_relative_to(base.resolve()):
+ raise ValueError(f"{candidate} is outside the allowed workspace directories")
+ return candidate
+
+
def _load_snapshot(snapshot_id: str, workspace: Any) -> Dict[str, Any]:
- path = _workspace_dir(workspace) / "snapshots" / f"{snapshot_id}.json"
+ path = _confined(workspace, "snapshots", f"{snapshot_id}.json")
if not path.exists():
raise ValueError(f"Snapshot '{snapshot_id}' not found.")
with open(path, "r", encoding="utf-8") as f:
@@ -288,7 +304,7 @@ class ParameterManagerModule:
elements = self._get_elements(snapshot_id, workspace)
matched = [el for el in elements if _match_element(el, element_filter)]
- output_path = _workspace_dir(workspace) / output_filename
+ output_path = _confined(workspace, output_filename)
header = ["uid", "element_id", "category", "family", "type_name"] + param_names
with open(output_path, "w", newline="", encoding="utf-8") as csvfile:
@@ -321,7 +337,7 @@ class ParameterManagerModule:
workspace: Any = None,
**_,
) -> Dict[str, Any]:
- csv_path = _workspace_dir(workspace) / csv_filename
+ csv_path = _confined(workspace, csv_filename)
if not csv_path.exists():
raise ValueError(f"CSV file '{csv_filename}' not found in workspace.")
diff --git a/packages/mcp-server-revit/src/revit_mcp_server/tool_metadata.py b/packages/mcp-server-revit/src/revit_mcp_server/tool_metadata.py
index 890c5b0..f53972b 100644
--- a/packages/mcp-server-revit/src/revit_mcp_server/tool_metadata.py
+++ b/packages/mcp-server-revit/src/revit_mcp_server/tool_metadata.py
@@ -159,7 +159,7 @@ DESCRIPTIONS: dict[str, str] = {
"parameter_manager_diff_params": "Compare parameter values between two saved snapshots and list the differences. Read-only.",
"parameter_manager_plan_set_params": "Create a draft ActionPlan that sets parameter values on the elements of a snapshot matching a filter. Review and approve the plan before it runs.",
"parameter_manager_export_params_csv": "Export parameters of the matching snapshot elements to a CSV file in the workspace. Writes a file; does not change the model.",
- "parameter_manager_import_params_csv": "Import parameter values from a CSV file in the workspace and apply them to elements. Write operation.",
+ "parameter_manager_import_params_csv": "Read parameter values from a CSV file in the workspace and create a draft ActionPlan that applies them. Does not change the model; review and approve the plan before it runs.",
"qaqc_checker_run_check": "Run a QA/QC rule pack against a saved snapshot and record the issues it finds.",
"qaqc_checker_list_issues": "List recorded QA/QC issues for a document, optionally filtered by status and severity. Read-only.",
"qaqc_checker_resolve_issue": "Mark one recorded QA/QC issue as resolved.",
@@ -498,7 +498,6 @@ ADDITIVE_NAMES = frozenset(
"selection_tools_set_selection",
"selection_tools_restore_selection",
"selection_tools_select_by_query",
- "parameter_manager_plan_set_params",
"navisworks_run_clash_test",
"speckle_publish_version",
"speckle_send_object",
diff --git a/packages/mcp-server-revit/tests/test_parameter_manager_paths.py b/packages/mcp-server-revit/tests/test_parameter_manager_paths.py
new file mode 100644
index 0000000..25fa5c4
--- /dev/null
+++ b/packages/mcp-server-revit/tests/test_parameter_manager_paths.py
@@ -0,0 +1,70 @@
+"""The draft-only parameter_manager tools run without an approved plan, so every
+caller-supplied file name must stay inside the workspace."""
+import json
+import os
+
+import pytest
+
+from test_parameter_manager import MockWorkspace, ParameterManagerModule # noqa: E402
+from revit_mcp_server.security.workspace import WorkspaceMonitor
+
+
+def outside(tmp_path):
+ work = tmp_path / "work"
+ work.mkdir()
+ secret = tmp_path / "outside"
+ secret.mkdir()
+ (secret / "secret.json").write_text(json.dumps({"elements": [{"uid": "u1", "params": {}}]}))
+ (secret / "secret.csv").write_text("uid,Mark\nu1,X\n")
+ return work, secret
+
+
[email protected]("workspace_cls", [MockWorkspace, lambda p: WorkspaceMonitor([p])])
+def test_snapshot_id_cannot_escape_workspace(outside, workspace_cls):
+ work, _ = outside
+ pm = ParameterManagerModule()
+ ws = workspace_cls(work)
+ (work / "snapshots").mkdir()
+ with pytest.raises(Exception, match="outside the allowed workspace"):
+ pm.plan_set_params(
+ element_filter={}, param_updates={"Mark": "1"},
+ snapshot_id="../../outside/secret", workspace=ws,
+ )
+
+
[email protected]("workspace_cls", [MockWorkspace, lambda p: WorkspaceMonitor([p])])
[email protected]("name", ["../outside/secret.csv", None])
+def test_csv_filename_cannot_escape_workspace(outside, workspace_cls, name):
+ work, secret = outside
+ pm = ParameterManagerModule()
+ ws = workspace_cls(work)
+ target = name or str(secret / "secret.csv") # absolute path case
+ with pytest.raises(Exception, match="outside the allowed workspace"):
+ pm.import_params_csv(csv_filename=target, snapshot_id="x", workspace=ws)
+
+
+def test_export_filename_cannot_escape_workspace(outside):
+ work, secret = outside
+ pm = ParameterManagerModule()
+ ws = MockWorkspace(work)
+ (work / "snapshots").mkdir()
+ with pytest.raises(Exception):
+ pm.export_params_csv(
+ element_filter={}, param_names=["Mark"], snapshot_id="",
+ output_filename="../outside/leak.csv", workspace=ws,
+ )
+ assert not (secret / "leak.csv").exists()
+
+
[email protected](os.name == "nt", reason="symlink creation needs privileges on Windows")
+def test_symlink_inside_workspace_cannot_escape(outside):
+ work, secret = outside
+ (work / "snapshots").mkdir()
+ (work / "snapshots" / "link.json").symlink_to(secret / "secret.json")
+ pm = ParameterManagerModule()
+ with pytest.raises(Exception, match="outside the allowed workspace"):
+ pm.plan_set_params(
+ element_filter={}, param_updates={"Mark": "1"},
+ snapshot_id="link", workspace=MockWorkspace(work),
+ )
diff --git a/packages/mcp-server-revit/tests/test_plan_gate_reachability.py b/packages/mcp-server-revit/tests/test_plan_gate_reachability.py
new file mode 100644
index 0000000..977e48f
--- /dev/null
+++ b/packages/mcp-server-revit/tests/test_plan_gate_reachability.py
@@ -0,0 +1,102 @@
+"""Regression: draft-only plan tools must be reachable under approval_mode="required".
+
+`parameter_manager_plan_set_params` and `parameter_manager_import_params_csv` only
+DRAFT an ActionPlan (no model write), so they must not be flagged `is_mutating`,
+otherwise the gate demands a `plan_id` before a plan can ever be drafted. Tools that
+really write must stay gated.
+"""
+from __future__ import annotations
+
+import pytest
+
+from revit_mcp_server.config import BridgeMode, Config, config
+from revit_mcp_server.errors import BridgeError
+from revit_mcp_server.module_registry import ModuleRegistry
+from revit_mcp_server.providers.approval_provider import ApprovalProvider
+from revit_mcp_server.providers.module_provider import ModuleProvider
+from revit_mcp_server.providers.registry import ProviderRegistry
+from revit_mcp_server.security.workspace import WorkspaceMonitor
+
+from test_approval_provider import FakeParamStore
+
+DRAFT_ONLY = ("parameter_manager_plan_set_params", "parameter_manager_import_params_csv")
+
+
+def stack(tmp_path, monkeypatch):
+ monkeypatch.setattr(config, "mode", BridgeMode.mock)
+ registry = ProviderRegistry()
+ workspace = WorkspaceMonitor([tmp_path])
+ approval = ApprovalProvider(workspace=workspace, registry=registry, approval_mode="required")
+ registry.register(approval)
+ store = FakeParamStore({1: {"Mark": "D-101"}})
+ registry.register(store)
+ cfg = Config(workspace_dir=tmp_path, allowed_directories=[tmp_path],
+ audit_log=tmp_path / "audit.log", enable_user_modules=False)
+ modules = ModuleRegistry(config_obj=cfg)
+ modules.discover_and_load()
+ mp = ModuleProvider(module_registry=modules, workspace=workspace, tool_registry=registry)
+ registry.register(mp)
+ return registry, approval, store, mp
+
+
+def _gate_applies(registry, name, arguments, gate):
+ """Mirror of the call_tool / panel / agent gate step."""
+ tool_def = registry.lookup_tool(name)
+ if tool_def and tool_def.is_mutating:
+ gate.check_tool_execution(name, arguments)
+
+
[email protected]("name", DRAFT_ONLY)
+def test_draft_only_tools_pass_gate_without_plan_id(stack, name):
+ registry, approval, *_ = stack
+ assert registry.lookup_tool(name).is_mutating is False
+ _gate_applies(registry, name, {}, approval.gate) # must not raise
+
+
+ "revit_set_parameter_value",
+ "selection_tools_set_selection",
+ "selection_tools_group_rename",
+ "selection_tools_group_ungroup",
+ "selection_tools_group_convert_to_detail",
+])
+def test_writing_tools_stay_mutating_and_blocked(stack, name):
+ registry, approval, *_ = stack
+ assert registry.lookup_tool(name).is_mutating is True
+ with pytest.raises(BridgeError, match="requires a valid 'plan_id'"):
+ _gate_applies(registry, name, {}, approval.gate)
+
+
+async def test_draft_approve_execute_end_to_end(stack):
+ registry, approval, store, mp = stack
+ gate = approval.gate
+
+ # 1. Draft: passes the gate with no plan_id.
+ _gate_applies(registry, "parameter_manager_plan_set_params", {}, gate)
+ draft = await mp.execute_tool("parameter_manager_plan_set_params", {
+ "element_filter": {"category": "OST_Doors"},
+ "param_updates": {"Mark": "D-201"},
+ })
+ assert draft["plan_type"] == "action_plan_draft"
+ assert draft["actions"]
+ action = draft["actions"][0]
+ action["arguments"]["element_id"] = 1 # map onto the fake store
+
+ # 2. Review: register the draft as a pending plan.
+ plan = await approval.execute_tool("plan_actions", {"actions": [action]})
+ plan_id = plan["plan_id"]
+ assert plan["state"] == "pending"
+
+ # The writing tool is blocked until approved.
+ with pytest.raises(BridgeError, match="not 'approved'"):
+ _gate_applies(registry, "revit_set_parameter_value", {"plan_id": plan_id}, gate)
+ assert store.values[1]["Mark"] == "D-101"
+
+ # 3. Approve, then execute.
+ await approval.execute_tool("approve_plan", {"plan_id": plan_id})
+ _gate_applies(registry, "revit_set_parameter_value", {"plan_id": plan_id}, gate)
+ result = await approval.execute_tool("execute_plan", {"plan_id": plan_id})
+ assert result["state"] == "executed"
+ assert store.values[1]["Mark"] == "D-201"