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.

feat(panel): wire the dockable panel to real hub tools, remove fixture data

A. Sam Mohammadf42bb3bf6ae0
diff --git a/packages/mcp-server-revit/src/revit_mcp_server/modules/report_generator/module.json b/packages/mcp-server-revit/src/revit_mcp_server/modules/report_generator/module.json
index 7890c41..ecfc1db 100644
--- a/packages/mcp-server-revit/src/revit_mcp_server/modules/report_generator/module.json
+++ b/packages/mcp-server-revit/src/revit_mcp_server/modules/report_generator/module.json
@@ -13,7 +13,7 @@
{
"id": "export_excel",
"title": "Export to Excel",
- "surface": ["mcp"],
+ "surface": ["mcp", "panel"],
"execution_mode": "sync",
"is_mutating": false,
"input_schema": {
diff --git a/packages/revit-bridge-addin/RevitBridge.csproj b/packages/revit-bridge-addin/RevitBridge.csproj
index f8be388..290a302 100644
--- a/packages/revit-bridge-addin/RevitBridge.csproj
+++ b/packages/revit-bridge-addin/RevitBridge.csproj
@@ -70,6 +70,7 @@
<Reference Include="PresentationFramework" />
<Reference Include="WindowsBase" />
<Reference Include="System.Xaml" />
+ <Reference Include="System.Net.Http" />
</ItemGroup>
</Project>
diff --git a/packages/revit-bridge-addin/src/UI/BridgePanel.xaml.cs b/packages/revit-bridge-addin/src/UI/BridgePanel.xaml.cs
index e1ba57e..3eed972 100644
--- a/packages/revit-bridge-addin/src/UI/BridgePanel.xaml.cs
+++ b/packages/revit-bridge-addin/src/UI/BridgePanel.xaml.cs
@@ -53,7 +53,7 @@ namespace RevitBridge.UI
}
}
- private void OnWebMessageReceived(object? sender, CoreWebView2WebMessageReceivedEventArgs args)
+ private async void OnWebMessageReceived(object? sender, CoreWebView2WebMessageReceivedEventArgs args)
{
string message;
try
@@ -66,9 +66,90 @@ namespace RevitBridge.UI
}
Log.Information("Bridge panel message received: {Message}", message);
+
+ try
+ {
+ await DispatchToHubAsync(message);
+ }
+ catch (JsonException)
+ {
+ // The connectivity-check fallback shell (BuildShellHtml) posts bare
+ // strings like "panel.loaded", not JSON objects — nothing to dispatch.
+ }
+ catch (Exception ex)
+ {
+ Log.Warning(ex, "Failed to dispatch panel message: {Message}", message);
+ }
+
PostHostStatus();
}
+ /// <summary>
+ /// Maps a panel message type to a real hub tool call and posts the result back.
+ /// Only the message types app.js currently sends for real workflows are wired;
+ /// chat/settings/report-browsing are local-only for now (no corresponding hub
+ /// tool) — see docs/product/NEXT_AGENT_HANDOVER.md.
+ /// </summary>
+ private async Task DispatchToHubAsync(string message)
+ {
+ using var doc = JsonDocument.Parse(message);
+ var root = doc.RootElement;
+ if (root.ValueKind != JsonValueKind.Object || !root.TryGetProperty("type", out var typeEl))
+ {
+ return;
+ }
+
+ var type = typeEl.GetString();
+ switch (type)
+ {
+ case "qaqc.runHealthCheck":
+ await RunToolAndPostAsync("qaqc_checker_run_check", new { }, "findings.updated", type);
+ break;
+
+ case "plans.refresh":
+ await RunToolAndPostAsync("list_pending_plans", new { }, "plans.updated", type);
+ break;
+
+ case "plan.approve":
+ case "plan.reject":
+ {
+ var planId = root.TryGetProperty("planId", out var idEl) ? idEl.GetString() : null;
+ if (string.IsNullOrEmpty(planId))
+ {
+ break;
+ }
+
+ var decisionTool = type == "plan.approve" ? "approve_plan" : "reject_plan";
+ var decision = await HubClient.ExecuteToolAsync(decisionTool, new { plan_id = planId });
+ if (!decision.Ok)
+ {
+ PostToPanel(new { type = "tool.error", action = type, message = decision.Error });
+ break;
+ }
+
+ await RunToolAndPostAsync("list_pending_plans", new { }, "plans.updated", type);
+ break;
+ }
+
+ case "reports.exportExcel":
+ await RunToolAndPostAsync("report_generator_export_excel", new { }, "reports.updated", type);
+ break;
+ }
+ }
+
+ private async Task RunToolAndPostAsync(string tool, object arguments, string successType, string action)
+ {
+ var result = await HubClient.ExecuteToolAsync(tool, arguments);
+ if (result.Ok)
+ {
+ PostToPanel(new { type = successType, action, result = result.Result });
+ }
+ else
+ {
+ PostToPanel(new { type = "tool.error", action, message = result.Error });
+ }
+ }
+
private void PostHostStatus()
{
var dirtyCount = DocumentDirtyTracker.GetDirtyUniqueIds().Count;
diff --git a/packages/revit-bridge-addin/src/UI/HubClient.cs b/packages/revit-bridge-addin/src/UI/HubClient.cs
new file mode 100644
index 0000000..f9162fc
--- /dev/null
+++ b/packages/revit-bridge-addin/src/UI/HubClient.cs
@@ -0,0 +1,89 @@
+using System;
+using System.Net.Http;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+
+namespace RevitBridge.UI
+{
+ /// <summary>
+ /// Calls the Python MCP hub's local panel HTTP shim (packages/mcp-server-revit's
+ /// panel_server.py). MCP itself is stdio-only — a WebView2 page cannot launch or
+ /// speak to a stdio subprocess — so per docs/product/PLUGIN_APP_ARCHITECTURE.md
+ /// section 2 the panel reaches the hub over a small loopback HTTP shim instead.
+ /// This is the one piece of the add-in that bridges that gap.
+ /// </summary>
+ internal static class HubClient
+ {
+ private static readonly HttpClient Client = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
+
+ private static int Port
+ {
+ get
+ {
+ var raw = Environment.GetEnvironmentVariable("MCP_PANEL_HTTP_PORT");
+ return int.TryParse(raw, out var port) ? port : 8787;
+ }
+ }
+
+ public static async Task<HubResult> ExecuteToolAsync(string tool, object arguments)
+ {
+ var requestBody = JsonSerializer.Serialize(new { tool, arguments });
+
+ try
+ {
+ using (var content = new StringContent(requestBody, Encoding.UTF8, "application/json"))
+ using (var response = await Client.PostAsync($"http://127.0.0.1:{Port}/execute", content).ConfigureAwait(false))
+ {
+ var text = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
+ return ParseResponse(text, (int)response.StatusCode);
+ }
+ }
+ catch (Exception ex)
+ {
+ return HubResult.Failure($"Could not reach the AEC Model Bridge hub on 127.0.0.1:{Port}: {ex.Message}");
+ }
+ }
+
+ private static HubResult ParseResponse(string text, int statusCode)
+ {
+ try
+ {
+ using (var doc = JsonDocument.Parse(text))
+ {
+ var root = doc.RootElement;
+ var ok = root.TryGetProperty("ok", out var okEl) && okEl.ValueKind == JsonValueKind.True;
+ if (ok && root.TryGetProperty("result", out var resultEl))
+ {
+ return HubResult.Success(resultEl.Clone());
+ }
+
+ var error = root.TryGetProperty("error", out var errEl) ? errEl.GetString() : null;
+ return HubResult.Failure(error ?? $"Hub returned HTTP {statusCode}");
+ }
+ }
+ catch (JsonException)
+ {
+ return HubResult.Failure($"Hub returned an unparseable response (HTTP {statusCode})");
+ }
+ }
+ }
+
+ internal readonly struct HubResult
+ {
+ public bool Ok { get; }
+ public JsonElement Result { get; }
+ public string Error { get; }
+
+ private HubResult(bool ok, JsonElement result, string error)
+ {
+ Ok = ok;
+ Result = result;
+ Error = error;
+ }
+
+ public static HubResult Success(JsonElement result) => new HubResult(true, result, null);
+
+ public static HubResult Failure(string error) => new HubResult(false, default, error);
+ }
+}
diff --git a/panel/app.js b/panel/app.js
index 5f629d8..d140a96 100644
--- a/panel/app.js
+++ b/panel/app.js
@@ -7,33 +7,17 @@ const views = {
settings: { title: "Settings", subtitle: "Local bridge" }
};
+// plans/findings/reports start empty and are populated only from real
+// host.dispatchToHub responses (see the "message" listener below) - there is
+// no fixture/demo data. Use the matching ribbon/panel action (Run Health
+// Check, Review Pending Actions, Export Report) to populate each list.
const state = {
host: null,
snapshot: null,
llm: null,
- plans: [
- {
- id: "plan_demo_01",
- title: "Set FireRating on 12 doors",
- status: "pending",
- detail: "Parameter Manager will write FireRating = 60 to matching door instances."
- },
- {
- id: "plan_demo_02",
- title: "Rename duplicate sheet numbers",
- status: "pending",
- detail: "QA/QC checker found duplicate sheet numbers in the active document."
- }
- ],
- findings: [
- { id: "f-001", severity: "error", title: "Doors missing FireRating", detail: "12 door instances have an empty FireRating value." },
- { id: "f-002", severity: "warning", title: "Views not on sheets", detail: "8 views are not placed on sheets." },
- { id: "f-003", severity: "info", title: "Unplaced rooms", detail: "3 rooms are unplaced in the active model." }
- ],
- reports: [
- { id: "r-001", title: "Model health workbook", detail: "Excel export with elements, types, and QA/QC issues." },
- { id: "r-002", title: "SQLite model summary", detail: "Local database export for downstream reporting." }
- ],
+ plans: [],
+ findings: [],
+ reports: [],
log: [
{ at: "09:00", title: "Panel loaded", detail: "Waiting for host status." }
]
@@ -347,6 +331,41 @@ settingsForm.addEventListener("submit", (event) => {
addLog("Settings saved", hubUrl.value);
});
+// Maps for the raw hub tool results the host forwards after a real MCP tool
+// call (see packages/revit-bridge-addin/src/UI/BridgePanel.xaml.cs's
+// DispatchToHubAsync) into the shapes the render* functions above expect.
+function mapFindings(hubResult) {
+ const findings = (hubResult && hubResult.findings) || [];
+ return findings.map((finding, index) => ({
+ id: finding.element_uid ? `${finding.rule_id}:${finding.element_uid}` : `${finding.rule_id}:${index}`,
+ severity: finding.severity || "info",
+ title: String(finding.rule_id || "finding").replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase()),
+ detail: finding.message || ""
+ }));
+}
+
+function mapPlans(hubResult) {
+ const plans = (hubResult && hubResult.plans) || [];
+ return plans.map((plan) => {
+ const actions = plan.actions || [];
+ return {
+ id: plan.plan_id,
+ status: plan.state,
+ title: actions.length === 1 ? actions[0].tool : `${actions.length} action(s)`,
+ detail: actions.map((action) => action.tool).join(", ") || "No actions"
+ };
+ });
+}
+
+function mapReport(hubResult) {
+ const fileName = String(hubResult.output_file || "").split(/[\\/]/).pop();
+ return {
+ id: hubResult.output_file || `report-${Date.now()}`,
+ title: fileName || "Report",
+ detail: `${hubResult.element_count ?? "?"} elements, ${hubResult.type_count ?? "?"} types exported to ${hubResult.output_file || "workspace"}`
+ };
+}
+
if (window.chrome && window.chrome.webview) {
window.chrome.webview.addEventListener("message", (event) => {
if (event.data?.type === "host.status") {
@@ -362,6 +381,25 @@ if (window.chrome && window.chrome.webview) {
state.llm = event.data;
renderSystemState();
}
+ if (event.data?.type === "findings.updated") {
+ state.findings = mapFindings(event.data.result);
+ renderFindings();
+ addLog("Health check complete", `${state.findings.length} finding(s)`);
+ }
+ if (event.data?.type === "plans.updated") {
+ state.plans = mapPlans(event.data.result);
+ renderPlans();
+ addLog("Plans updated", `${state.plans.length} pending`);
+ }
+ if (event.data?.type === "reports.updated") {
+ const report = mapReport(event.data.result);
+ state.reports = [report, ...state.reports];
+ renderReports();
+ addLog("Report exported", report.title);
+ }
+ if (event.data?.type === "tool.error") {
+ addLog(`Error: ${event.data.action || "tool"}`, event.data.message || "Unknown error");
+ }
if (event.data?.type === "panel.view" && views[event.data.view]) {
setView(event.data.view);
if (event.data.action) {