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 CreateTransaction calling itself (#95)

A. Sam Mohammad28ee173df297
diff --git a/packages/mcp-server-revit/tests/test_addin_source_guards.py b/packages/mcp-server-revit/tests/test_addin_source_guards.py
new file mode 100644
index 0000000..e1c3c1f
--- /dev/null
+++ b/packages/mcp-server-revit/tests/test_addin_source_guards.py
@@ -0,0 +1,40 @@
+"""Static guards on the C# add-in source.
+
+There is no C# test project yet and CI only compiles the add-in, so a method that calls
+itself still builds. These checks read the source text and fail on known-fatal patterns.
+"""
+import re
+from pathlib import Path
+
+ADDIN_SRC = Path(__file__).resolve().parents[3] / "packages" / "revit-bridge-addin" / "src"
+FACTORY = ADDIN_SRC / "Bridge" / "BridgeCommandFactory.cs"
+
+
+def _method_body(source: str, signature_re: str) -> str:
+ match = re.search(signature_re, source)
+ assert match, f"method not found: {signature_re}"
+ start = source.index("{", match.end())
+ depth = 0
+ for i in range(start, len(source)):
+ if source[i] == "{":
+ depth += 1
+ elif source[i] == "}":
+ depth -= 1
+ if depth == 0:
+ return source[start : i + 1]
+ raise AssertionError("unbalanced braces")
+
+
+def test_create_transaction_builds_a_real_transaction_and_does_not_call_itself():
+ body = _method_body(
+ FACTORY.read_text(encoding="utf-8"),
+ r"public static Transaction CreateTransaction\(Document doc, string name\)",
+ )
+ assert "BridgeCommandFactory.CreateTransaction(" not in body, "CreateTransaction calls itself"
+ assert "CreateTransaction(" not in body, "CreateTransaction calls itself"
+ assert "new Transaction(" in body, "CreateTransaction must construct the Revit Transaction"
+
+
+def test_add_in_constructs_transactions_somewhere():
+ hits = [p for p in ADDIN_SRC.rglob("*.cs") if "new Transaction(" in p.read_text(encoding="utf-8")]
+ assert hits, "no 'new Transaction(' in the add-in: every model write would fail"
diff --git a/packages/revit-bridge-addin/src/Bridge/BridgeCommandFactory.cs b/packages/revit-bridge-addin/src/Bridge/BridgeCommandFactory.cs
index 38286ed..15f4bb9 100644
--- a/packages/revit-bridge-addin/src/Bridge/BridgeCommandFactory.cs
+++ b/packages/revit-bridge-addin/src/Bridge/BridgeCommandFactory.cs
@@ -33,7 +33,7 @@ public static class BridgeCommandFactory
{
var actionId = CurrentActionId;
string txName = string.IsNullOrEmpty(actionId) ? $"AMB: {name}" : $"AMB: {name} #{actionId}";
- return BridgeCommandFactory.CreateTransaction(doc, txName);
+ return new Transaction(doc, txName);
}
static BridgeCommandFactory()