ππΌββοΈ The blackboard for coding agents - agentic development environment for claude code, codex, cursor, opencode, grok and more.
Rust adeai-agentsclaudeclaude-codecodexcursorgeminigrokopencodespec-driven-developmentvibe-codingvim
fix(orchestrator): start reliably by fixing MCP registration quoting and name (#123)
Valentin Palkovicd851101c02fe
diff --git a/.mcp.json b/.mcp.jsonindex dac57dd..dca3c57 100644--- a/.mcp.json+++ b/.mcp.json@@ -1,7 +1,9 @@{- "agtx": {- "type": "stdio",- "command": "agtx",- "args": ["mcp-serve"]+ "mcpServers": {+ "agtx": {+ "type": "stdio",+ "command": "agtx",+ "args": ["mcp-serve"]+ }}}diff --git a/src/agent/operations.rs b/src/agent/operations.rsindex e2f3452..e0b0a94 100644--- a/src/agent/operations.rs+++ b/src/agent/operations.rs@@ -91,13 +91,28 @@ impl AgentOperations for CodingAgent {fn build_orchestrator_command(&self, mcp_json: &str, _agtx_bin: &str) -> String {match self.agent.name.as_str() {- // Pre-remove any stale `agtx` registration (last run crashed before- // its own `mcp remove`) so `add-json` doesn't fail with "already- // exists" and short-circuit the `&&` into an empty shell.+ // Register under a unique name (`agtx-orchestrator`) rather than+ // `agtx` to avoid colliding with an `agtx` server already defined in+ // another scope (the Claude Code plugin's `plugin:agtx:agtx`, a+ // user-scope entry in ~/.claude.json, or the repo's .mcp.json).+ // A same-named server across scopes with different endpoints makes+ // Claude Code report a configuration conflict and refuse to connect.+ //+ // Pre-remove any stale registration (last run crashed before its own+ // `mcp remove`) so `add-json` doesn't fail with "already exists" and+ // short-circuit the `&&` into an empty shell.+ //+ // The JSON must be single-quoted for `add-json`, but this whole+ // command is itself wrapped in `sh -c '...'` by create_window. A bare+ // `'{json}'` would close that outer quote and let the shell mangle the+ // JSON (yielding "Invalid configuration: Invalid input"). Escape the+ // wrapping quotes as `'\''` (the POSIX single-quote-in-single-quote+ // idiom, same convention build_interactive_command uses for prompts)+ // so they survive the outer `sh -c` layer intact."claude" => format!(- "claude mcp remove agtx --scope local 2>/dev/null || true; \- claude mcp add-json agtx '{}' --scope local && {}; \- claude mcp remove agtx --scope local",+ "claude mcp remove agtx-orchestrator --scope local 2>/dev/null || true; \+ claude mcp add-json agtx-orchestrator '\\''{}'\\'' --scope local && {}; \+ claude mcp remove agtx-orchestrator --scope local",mcp_json,self.build_interactive_command("")),diff --git a/tests/agent_tests.rs b/tests/agent_tests.rsindex 32d6d81..a8e180f 100644--- a/tests/agent_tests.rs+++ b/tests/agent_tests.rs@@ -166,13 +166,29 @@ fn test_build_orchestrator_command_claude_is_idempotent() {let cmd = ops.build_orchestrator_command("{\"type\":\"stdio\"}", "/usr/bin/agtx");let pre_remove_idx = cmd- .find("claude mcp remove agtx")+ .find("claude mcp remove agtx-orchestrator").expect("pre-remove stale registration");let add_idx = cmd- .find("claude mcp add-json agtx")+ .find("claude mcp add-json agtx-orchestrator").expect("register MCP");assert!(pre_remove_idx < add_idx, "pre-remove must precede add-json:\n{cmd}");+ // Must NOT register under the bare `agtx` name: that collides with an `agtx`+ // server defined in another scope (plugin / user / .mcp.json) and makes+ // Claude Code report a configuration conflict and refuse to connect.+ assert!(+ !cmd.contains("add-json agtx "),+ "must register under a unique name, not bare `agtx`:\n{cmd}"+ );++ // The JSON's wrapping single quotes must be escaped (`'\''`) so the command+ // survives create_window's outer `sh -c '...'` layer. A bare `'{json}'` would+ // break out of that wrapper and mangle the JSON.+ assert!(+ cmd.contains(r"'\''"),+ "JSON quotes must be escaped for the outer sh -c wrapper:\n{cmd}"+ );+let pre_section = &cmd[..add_idx];assert!(pre_section.contains("|| true") || pre_section.contains("2>/dev/null"),