Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions internal/runtime/agent_cli_mcp_render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"reflect"
"strings"
"testing"

"agentflow/internal/domain"
)

func readAgentCLIMCPDoc(t *testing.T, home, rel string) any {
Expand Down Expand Up @@ -118,3 +120,34 @@ func TestWriteAgentCLIMCPConfigKimiToolTimeout(t *testing.T) {
t.Fatalf("kimi mcp:\n got %v\nwant %v", got, want)
}
}

func TestWriteAgentCLIMCPConfigStdioArgs(t *testing.T) {
entries, err := mcpConfigEntries([]domain.MCPServerDefinition{
{ID: gateMCPServerID, Command: "gate-mcp"},
{ID: "empty-args", Command: "tool", Args: []string{}},
{ID: "with-args", Command: "node", Args: []string{"server.js", "--stdio"}},
})
if err != nil {
t.Fatal(err)
}
for _, kind := range []string{AgentCLIPi, AgentCLIKimi, AgentCLICursor, AgentCLIAntigravity} {
t.Run(kind, func(t *testing.T) {
home := t.TempDir()
if err := WriteAgentCLIMCPConfig(kind, HostAgentCLIHome(home), entries, AgentCLIMCPOptions{}); err != nil {
t.Fatal(err)
}
doc := readAgentCLIMCPDoc(t, home, agentCLIMCPPaths[kind]).(map[string]any)
servers := doc["mcpServers"].(map[string]any)
for _, id := range []string{gateMCPServerID, "empty-args"} {
server := servers[id].(map[string]any)
if args, ok := server["args"]; ok {
t.Errorf("%s should omit args, got %#v", id, args)
}
}
want := []any{"server.js", "--stdio"}
if got := servers["with-args"].(map[string]any)["args"]; !reflect.DeepEqual(got, want) {
t.Errorf("stdio args = %#v, want %#v", got, want)
}
})
}
}
9 changes: 9 additions & 0 deletions internal/runtime/gate_mcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ func TestMaterializeInvocationInjectsGateMCP(t *testing.T) {
t.Fatalf("mcp config missing %q:\n%s", want, text)
}
}
var config struct {
MCPServers map[string]map[string]json.RawMessage `json:"mcpServers"`
}
if err := json.Unmarshal(raw, &config); err != nil {
t.Fatal(err)
}
if args, ok := config.MCPServers[gateMCPServerID]["args"]; ok {
t.Fatalf("gate MCP has no command-line arguments, got args %s", args)
}
if info, err := os.Stat(filepath.Join(workspace, ".agentflow", "config", "reviewer", "gate-mcp")); err != nil || info.Mode().Perm()&0o111 == 0 {
t.Fatal(err)
}
Expand Down
5 changes: 4 additions & 1 deletion internal/runtime/materialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,10 @@ func mcpConfigEntries(servers []domain.MCPServerDefinition) (map[string]any, err
}
} else {
entry["command"] = m.Command
entry["args"] = m.Args
// Some MCP clients reject null for this optional field.
if len(m.Args) > 0 {
entry["args"] = m.Args
}
if cwd := MCPRuntimeWorkingDirectory(m); cwd != "" {
entry["cwd"] = cwd
}
Expand Down
Loading