fix: persist Codex MCP approval (#2691) (#2699)

This commit is contained in:
Fernando San Martín W.
2026-08-15 17:18:15 -04:00
committed by GitHub
parent 68112773e9
commit b87cbcf3ed
2 changed files with 34 additions and 0 deletions
@@ -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
@@ -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{})