diff --git a/apps/backend/internal/agent/mcpconfig/passthrough.go b/apps/backend/internal/agent/mcpconfig/passthrough.go index d99bf28ffa..8c805e41a3 100644 --- a/apps/backend/internal/agent/mcpconfig/passthrough.go +++ b/apps/backend/internal/agent/mcpconfig/passthrough.go @@ -168,6 +168,11 @@ func claudeRemoteType(t string) string { // inferred from the presence of `command` vs `url` (there is no `type` key). type CodexStrategy struct{} +const ( + codexKandevServerName = "kandev" + codexKandevApprovalMode = "approve" +) + func (CodexStrategy) BuildPassthroughMCP(servers []types.McpServer, _ PassthroughPaths) (PassthroughArtifacts, error) { args := make([]string, 0, len(servers)*4) for _, srv := range servers { @@ -215,6 +220,9 @@ func codexServerArgs(srv types.McpServer) ([]string, error) { pairs = append(pairs, pair{"http_headers", srv.Headers}) } } + if srv.Name == codexKandevServerName { + pairs = append(pairs, pair{"default_tools_approval_mode", codexKandevApprovalMode}) + } // NOTE: env vars and headers are JSON-encoded into `-c` overrides, which // land in the process argument list (visible via `ps aux`) — a local user // on the host could read tokens this way. Codex has no file-based MCP config diff --git a/apps/backend/internal/agent/mcpconfig/passthrough_test.go b/apps/backend/internal/agent/mcpconfig/passthrough_test.go index 13ad632a84..a2cd0275ea 100644 --- a/apps/backend/internal/agent/mcpconfig/passthrough_test.go +++ b/apps/backend/internal/agent/mcpconfig/passthrough_test.go @@ -140,6 +140,7 @@ func TestCodexStrategy_Args(t *testing.T) { // stdio server: command + args + env for _, want := range []string{ `-c mcp_servers.kandev.url="http://localhost:1234/mcp"`, + `-c mcp_servers.kandev.default_tools_approval_mode="approve"`, `-c mcp_servers.github.command="npx"`, `-c mcp_servers.github.args=["-y","@mcp/github"]`, `-c mcp_servers.github.env={"GITHUB_TOKEN":"tok"}`, @@ -150,6 +151,10 @@ func TestCodexStrategy_Args(t *testing.T) { t.Errorf("missing arg %q in:\n%s", want, joined) } } + if strings.Contains(joined, `mcp_servers.github.default_tools_approval_mode`) || + strings.Contains(joined, `mcp_servers.stream.default_tools_approval_mode`) { + t.Errorf("external MCP servers must not receive Kandev approval policy:\n%s", joined) + } // Every value token must be preceded by a -c flag. for i := 0; i < len(art.Args); i += 2 { if art.Args[i] != "-c" { @@ -166,6 +171,27 @@ func TestCodexStrategy_OmitsEmptyArgsAndEnv(t *testing.T) { } } +func TestCodexStrategy_KandevPolicyIsAppliedPerLaunch(t *testing.T) { + for _, url := range []string{ + "http://localhost:1001/mcp", + "http://localhost:1002/mcp", + } { + art, err := CodexStrategy{}.BuildPassthroughMCP([]types.McpServer{ + {Name: "kandev", Type: "http", URL: url}, + }, PassthroughPaths{}) + if err != nil { + t.Fatalf("unexpected error for %s: %v", url, err) + } + joined := strings.Join(art.Args, " ") + if !strings.Contains(joined, `mcp_servers.kandev.default_tools_approval_mode="approve"`) { + t.Errorf("launch for %s omitted Kandev approval policy: %s", url, joined) + } + if !strings.Contains(joined, `mcp_servers.kandev.url="`+url+`"`) { + t.Errorf("launch for %s omitted dynamic Kandev URL: %s", url, joined) + } + } +} + func TestCodexStrategy_QuotesServerNamesWithDots(t *testing.T) { servers := []types.McpServer{{Name: "my.server", Type: "stdio", Command: "run"}} art, _ := CodexStrategy{}.BuildPassthroughMCP(servers, PassthroughPaths{})