From 8d5a44ee659e9b0a7c3a88f7bb8a64fd6c483794 Mon Sep 17 00:00:00 2001 From: finallylly Date: Sat, 21 Nov 2026 23:08:55 +0800 Subject: [PATCH] fix(runtime): omit empty MCP args instead of writing null mcpConfigEntries wrote "args": null for stdio MCP servers without arguments, such as the built-in gate server. Claude Code skips a server whose args is null, so SOP nodes running on Claude never saw submit_gate_result and stopped for manual confirmation. Omit args when it is empty, matching the Codex renderer. --- internal/runtime/materialize.go | 7 +++- internal/runtime/materialize_mcp_args_test.go | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 internal/runtime/materialize_mcp_args_test.go diff --git a/internal/runtime/materialize.go b/internal/runtime/materialize.go index ea1dd369..52582495 100644 --- a/internal/runtime/materialize.go +++ b/internal/runtime/materialize.go @@ -448,7 +448,12 @@ func mcpConfigEntries(servers []domain.MCPServerDefinition) (map[string]any, err } } else { entry["command"] = m.Command - entry["args"] = m.Args + // A nil slice would render as "args": null, which Claude Code + // rejects by silently skipping the whole server (including the + // gate MCP). Omit args when empty, as the Codex renderer does. + if len(m.Args) > 0 { + entry["args"] = m.Args + } if cwd := MCPRuntimeWorkingDirectory(m); cwd != "" { entry["cwd"] = cwd } diff --git a/internal/runtime/materialize_mcp_args_test.go b/internal/runtime/materialize_mcp_args_test.go new file mode 100644 index 00000000..202f42ad --- /dev/null +++ b/internal/runtime/materialize_mcp_args_test.go @@ -0,0 +1,36 @@ +package runtime + +import ( + "encoding/json" + "strings" + "testing" + + "agentflow/internal/domain" +) + +// Claude Code skips a stdio MCP server whose args is null, which hid the gate +// MCP (submit_gate_result) from SOP nodes. Empty args must not render as null. +func TestMCPConfigEntriesOmitsEmptyArgs(t *testing.T) { + entries, err := mcpConfigEntries([]domain.MCPServerDefinition{ + {ID: "gate", Command: ".agentflow/gate-mcp"}, + {ID: "tool", Command: "node", Args: []string{"server.js", "--stdio"}}, + }) + if err != nil { + t.Fatal(err) + } + data, err := json.Marshal(entries) + if err != nil { + t.Fatal(err) + } + if strings.Contains(string(data), "null") { + t.Fatalf("MCP config must not contain null values: %s", data) + } + gate, _ := entries["gate"].(map[string]any) + if _, ok := gate["args"]; ok { + t.Fatalf("server without args must omit args: %+v", gate) + } + tool, _ := entries["tool"].(map[string]any) + if args, _ := tool["args"].([]string); len(args) != 2 || args[0] != "server.js" || args[1] != "--stdio" { + t.Fatalf("server args lost: %+v", tool) + } +}