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(panel): keep codex on the CLI path even with an Anthropic API key configured

sammohammad57879ae60c4e3e9
diff --git a/packages/mcp-server-revit/src/revit_mcp_server/panel_server.py b/packages/mcp-server-revit/src/revit_mcp_server/panel_server.py
index b6120e5..2ab4011 100644
--- a/packages/mcp-server-revit/src/revit_mcp_server/panel_server.py
+++ b/packages/mcp-server-revit/src/revit_mcp_server/panel_server.py
@@ -175,17 +175,22 @@ class PanelRequestHandler(BaseHTTPRequestHandler):
session_id = body.get("session_id")
try:
- if config.anthropic_api_key:
- # Native path takes priority whenever an API key is
- # configured, regardless of the requested `provider` value -
- # it replaces the CLI-based "claude" option entirely (see
- # /agent/providers above for how the panel learns this).
+ if provider == "codex":
+ # codex has no native path (Task 1's ADR scopes it as
+ # CLI-only) - route here unconditionally, even when an API
+ # key is configured for the "claude" native path. agent_bridge
+ # itself reports a missing-CLI error if codex isn't on PATH.
+ result = agent_bridge.run_agent_turn(provider, message, session_id)
+ elif config.anthropic_api_key:
+ # Native path takes priority for "claude" (or an unspecified
+ # provider, which defaults to "claude") whenever an API key
+ # is configured - it replaces the CLI-based "claude" option
+ # entirely (see /agent/providers above for how the panel
+ # learns this).
result = agent_native.run_native_turn(message, session_id, self.registry, self.approval_provider)
- elif provider == "codex" or (provider == "claude" and shutil.which("claude") is not None):
- # CLI fallback: codex has no native path so always routes
- # here (agent_bridge itself reports a missing-CLI error);
- # claude only lands here with no API key configured AND the
- # CLI resolvable on PATH.
+ elif provider == "claude" and shutil.which("claude") is not None:
+ # CLI fallback: only reached with no API key configured AND
+ # the claude CLI resolvable on PATH.
result = agent_bridge.run_agent_turn(provider, message, session_id)
else:
result = {
diff --git a/packages/mcp-server-revit/tests/test_panel_server.py b/packages/mcp-server-revit/tests/test_panel_server.py
index 4bcf7ff..812f3be 100644
--- a/packages/mcp-server-revit/tests/test_panel_server.py
+++ b/packages/mcp-server-revit/tests/test_panel_server.py
@@ -233,6 +233,37 @@ def test_agent_chat_dispatches_to_native_when_api_key_configured(running_server,
assert bridge_calls == []
+def test_agent_chat_explicit_codex_stays_on_cli_path_even_with_api_key_configured(running_server, monkeypatch):
+ """Regression test: codex has no native path (Task 1's ADR scopes it as
+ CLI-only regardless of API key state). An explicit provider: "codex"
+ request must always go through agent_bridge.run_agent_turn, even when an
+ Anthropic API key is configured and would otherwise route "claude" to
+ the native path."""
+ monkeypatch.setattr(panel_server.config, "anthropic_api_key", "test-key")
+ monkeypatch.setattr(panel_server.shutil, "which", lambda name: "/usr/bin/codex" if name == "codex" else None)
+
+ native_calls = []
+ bridge_calls = []
+
+ def fake_native(message, session_id, registry, approval_provider):
+ native_calls.append((message, session_id))
+ return {"ok": True, "response": "native reply", "session_id": "sess-native"}
+
+ def fake_bridge(provider, message, session_id):
+ bridge_calls.append((provider, message, session_id))
+ return {"ok": True, "response": "codex reply", "session_id": "sess-codex"}
+
+ monkeypatch.setattr(panel_server.agent_native, "run_native_turn", fake_native)
+ monkeypatch.setattr(panel_server.agent_bridge, "run_agent_turn", fake_bridge)
+
+ status, body = _post(running_server, "/agent/chat", {"message": "hi", "provider": "codex"})
+
+ assert status == 200
+ assert body == {"ok": True, "response": "codex reply", "session_id": "sess-codex"}
+ assert bridge_calls == [("codex", "hi", None)]
+ assert native_calls == []
+
+
def test_agent_chat_no_provider_available_returns_error_without_dispatch(running_server, monkeypatch):
"""No API key and no CLI on PATH: the chat request must fail fast with
the "no provider available" error, without ever calling either agent