Open-source Revit MCP server: let Claude and other AI assistants read and edit BIM models, with human approval on every change.
Python aecai-agentsautodeskautomationbimclaudeifcmcpmcp-servermodel-context-protocolnavisworksrevitrevit-addinrevit-apirhino
fix(hub): never swallow a workspace-sandbox violation from a legacy handler
A. Sam Mohammad99d481fcd912
diff --git a/packages/mcp-server-revit/src/revit_mcp_server/providers/revit.py b/packages/mcp-server-revit/src/revit_mcp_server/providers/revit.pyindex 87f916c..fe0da9d 100644--- a/packages/mcp-server-revit/src/revit_mcp_server/providers/revit.py+++ b/packages/mcp-server-revit/src/revit_mcp_server/providers/revit.py@@ -6,6 +6,7 @@ from pathlib import Pathfrom ..config import config, BridgeModefrom ..bridge.client import BridgeClientfrom ..bridge.mock import MockBridge+from ..errors import WorkspaceViolationfrom ..security.workspace import WorkspaceMonitorfrom ..legacy.tools import TOOL_HANDLERSfrom .base import AECProvider, ProviderTool, enrich_mutation_metadata@@ -108,15 +109,25 @@ class RevitProvider(AECProvider):payload["request_id"] = arguments["request_id"]if self.mode == BridgeMode.bridge:- # Under bridge mode, execute the legacy handler if we need custom validation or prep+ # Under bridge mode, run the legacy handler for validation/prep only — its+ # return value is discarded, the bridge call below is the real result.legacy_dot_name = bridge_toolhandler = TOOL_HANDLERS.get(legacy_dot_name)if handler:try:handler(payload, self.workspace)+ except WorkspaceViolation:+ # A workspace-sandbox escape must always block the call — swallowing+ # this as a warning would let a path-outside-workspace request reach+ # the live bridge anyway, silently defeating the sandbox for every+ # tool that happens to have a legacy handler.+ raiseexcept Exception as e:+ # Other legacy-schema validation failures are advisory only: these+ # Pydantic input models predate the current provider architecture+ # and can drift out of sync with what the bridge actually accepts.logger.warning(f"Revit legacy handler validation warning: {e}")-+# Send to bridge clientreturn self._bridge.send_tool(bridge_tool, payload)else:diff --git a/packages/mcp-server-revit/tests/test_tools.py b/packages/mcp-server-revit/tests/test_tools.pyindex dddf81a..20b8798 100644--- a/packages/mcp-server-revit/tests/test_tools.py+++ b/packages/mcp-server-revit/tests/test_tools.py@@ -1,7 +1,22 @@import pytest+from revit_mcp_server.config import BridgeMode+from revit_mcp_server.errors import WorkspaceViolationfrom revit_mcp_server.security.workspace import WorkspaceMonitorfrom revit_mcp_server.providers.revit import RevitProvider++class FakeBridge:+ """Stands in for the 'live' Revit bridge — records whether a call ever+ reached it, so tests can prove an unsafe request never got that far."""++ def __init__(self, base_url: str, token: str | None = None):+ self.calls = []++ def send_tool(self, tool_name, payload):+ self.calls.append((tool_name, payload))+ return {"ok": True}++def test_all_handlers_registered(tmp_path):workspace = WorkspaceMonitor([tmp_path])provider = RevitProvider(workspace=workspace)@@ -19,3 +34,28 @@ async def test_export_quantities_uses_workspace(tmp_path):with pytest.raises(Exception):# Path outside workspace must raise ValueError or PermissionErrorawait provider.execute_tool("revit_get_element_geometry", {"element_id": 1, "path": "C:/outside.rvt"})+++async def test_bridge_mode_never_forwards_an_out_of_workspace_path(tmp_path):+ """An out-of-workspace path must be rejected before reaching the live bridge,+ not just in mock mode. This exercises RevitProvider in BridgeMode.bridge with+ an injected fake bridge standing in for the real C# add-in — if the sandbox+ check were ever silently downgraded to a warning (as the legacy-handler path+ in execute_tool used to do for WorkspaceViolation specifically), the fake+ bridge would see the call anyway."""+ workspace = WorkspaceMonitor([tmp_path])+ fake_bridge = FakeBridge("http://127.0.0.1:3000")+ provider = RevitProvider(+ workspace=workspace,+ mode=BridgeMode.bridge,+ bridge_factory=lambda u, t=None: fake_bridge,+ )++ with pytest.raises(WorkspaceViolation):+ await provider.execute_tool(+ "revit_batch_create_sheets_from_csv",+ {"csv_path": "C:/outside/sheets.csv", "titleblock_name": "A1"},+ )++ assert fake_bridge.calls == []