From 4c616de5d2297152018261c7b09d22cfc5d09c06 Mon Sep 17 00:00:00 2001 From: George Lydakis Date: Sun, 22 Mar 2026 23:33:18 -0400 Subject: [PATCH] fix: avoid codex apps probing during server listing --- internal/daemon/daemon_tools_test.go | 45 ++++++++++++-------------- internal/servercatalog/catalog.go | 20 +----------- internal/servercatalog/catalog_test.go | 20 ++++++------ 3 files changed, 30 insertions(+), 55 deletions(-) diff --git a/internal/daemon/daemon_tools_test.go b/internal/daemon/daemon_tools_test.go index 359fd7d..71c7ce7 100644 --- a/internal/daemon/daemon_tools_test.go +++ b/internal/daemon/daemon_tools_test.go @@ -3,7 +3,6 @@ package daemon import ( "context" "encoding/json" - "errors" "reflect" "strings" "testing" @@ -171,7 +170,7 @@ func TestToolSchemaPayloadUsesNativeToolName(t *testing.T) { } } -func TestListServersHidesCodexAppsAndShowsVirtualServers(t *testing.T) { +func TestListServersHidesCodexAppsWithoutDiscovery(t *testing.T) { cfg := &config.Config{ Servers: map[string]config.ServerConfig{ "github": {}, @@ -186,16 +185,11 @@ func TestListServersHidesCodexAppsAndShowsVirtualServers(t *testing.T) { ka := NewKeepalive(nil) defer ka.Stop() + calls := 0 deps := runtimeDefaultDeps() - deps.poolListTools = func(_ context.Context, _ *mcppool.Pool, server string) ([]mcppool.ToolInfo, error) { - if server != codexAppsServerName { - t.Fatalf("poolListTools server = %q, want %q", server, codexAppsServerName) - } - return []mcppool.ToolInfo{ - {Name: "linear_get_profile"}, - {Name: "zillow_get_zestimate"}, - {Name: "google calendar_search"}, - }, nil + deps.poolListTools = func(_ context.Context, _ *mcppool.Pool, _ string) ([]mcppool.ToolInfo, error) { + calls++ + return nil, nil } resp := listServersWithDeps(context.Background(), cfg, nil, ka, false, deps) @@ -204,23 +198,19 @@ func TestListServersHidesCodexAppsAndShowsVirtualServers(t *testing.T) { } got := decodeServerLines(resp.Content) - want := []string{"github", "google_calendar", "linear", "supermemory", "zillow"} + want := []string{"github", "supermemory"} if !reflect.DeepEqual(got, want) { t.Fatalf("server list = %#v, want %#v", got, want) } entries := decodeServerEntries(resp.Content) for _, entry := range entries { - switch entry.Name { - case "github", "supermemory": - if entry.Origin.Kind != config.ServerOriginKindMCPXConfig { - t.Fatalf("server %q origin kind = %q, want %q", entry.Name, entry.Origin.Kind, config.ServerOriginKindMCPXConfig) - } - case "google_calendar", "linear", "zillow": - if entry.Origin.Kind != config.ServerOriginKindCodexApps { - t.Fatalf("server %q origin kind = %q, want %q", entry.Name, entry.Origin.Kind, config.ServerOriginKindCodexApps) - } + if entry.Origin.Kind != config.ServerOriginKindMCPXConfig { + t.Fatalf("server %q origin kind = %q, want %q", entry.Name, entry.Origin.Kind, config.ServerOriginKindMCPXConfig) } } + if calls != 0 { + t.Fatalf("codex list-tools calls = %d, want 0", calls) + } for _, name := range got { if name == codexAppsServerName { t.Fatalf("server list = %#v, want %q omitted", got, codexAppsServerName) @@ -228,7 +218,7 @@ func TestListServersHidesCodexAppsAndShowsVirtualServers(t *testing.T) { } } -func TestListServersKeepsConfiguredServersWhenCodexAppsDiscoveryFails(t *testing.T) { +func TestListServersKeepsConfiguredServersWhenCodexAppsConfigured(t *testing.T) { cfg := &config.Config{ Servers: map[string]config.ServerConfig{ "github": {}, @@ -239,9 +229,11 @@ func TestListServersKeepsConfiguredServersWhenCodexAppsDiscoveryFails(t *testing ka := NewKeepalive(nil) defer ka.Stop() + calls := 0 deps := runtimeDefaultDeps() deps.poolListTools = func(_ context.Context, _ *mcppool.Pool, _ string) ([]mcppool.ToolInfo, error) { - return nil, errors.New("token expired") + calls++ + return nil, nil } resp := listServersWithDeps(context.Background(), cfg, nil, ka, false, deps) @@ -260,8 +252,11 @@ func TestListServersKeepsConfiguredServersWhenCodexAppsDiscoveryFails(t *testing t.Fatalf("server %q origin kind = %q, want %q", entry.Name, entry.Origin.Kind, config.ServerOriginKindMCPXConfig) } } - if !strings.Contains(resp.Stderr, "failed to enumerate codex apps") { - t.Fatalf("listServers() stderr = %q, want codex-apps warning", resp.Stderr) + if resp.Stderr != "" { + t.Fatalf("listServers() stderr = %q, want empty", resp.Stderr) + } + if calls != 0 { + t.Fatalf("codex list-tools calls = %d, want 0", calls) } } diff --git a/internal/servercatalog/catalog.go b/internal/servercatalog/catalog.go index fa665dd..ddbde82 100644 --- a/internal/servercatalog/catalog.go +++ b/internal/servercatalog/catalog.go @@ -38,6 +38,7 @@ func New(cfg *config.Config, listTools ListToolsFunc) *Catalog { } func (c *Catalog) ServerNames(ctx context.Context) ([]string, error) { + _ = ctx if c == nil || c.cfg == nil { return nil, nil } @@ -50,25 +51,6 @@ func (c *Catalog) ServerNames(ctx context.Context) ([]string, error) { names[name] = struct{}{} } - if c.hasCodexApps() { - if c.listTools == nil { - return nil, fmt.Errorf("codex apps discovery requires list tools callback") - } - tools, err := c.listTools(ctx, CodexAppsServerName) - if err != nil { - return nil, err - } - for name := range codexVirtualServerMap(tools) { - if strings.TrimSpace(name) == "" { - continue - } - if _, exists := c.cfg.Servers[name]; exists { - continue - } - names[name] = struct{}{} - } - } - out := make([]string, 0, len(names)) for name := range names { out = append(out, name) diff --git a/internal/servercatalog/catalog_test.go b/internal/servercatalog/catalog_test.go index 917f2f6..3fa79a8 100644 --- a/internal/servercatalog/catalog_test.go +++ b/internal/servercatalog/catalog_test.go @@ -9,7 +9,7 @@ import ( "github.com/lydakis/mcpx/internal/mcppool" ) -func TestServerNamesHidesCodexAppsAndAddsVirtualApps(t *testing.T) { +func TestServerNamesHidesCodexAppsWithoutDiscovery(t *testing.T) { cfg := &config.Config{ Servers: map[string]config.ServerConfig{ "playwright": {}, @@ -18,15 +18,10 @@ func TestServerNamesHidesCodexAppsAndAddsVirtualApps(t *testing.T) { }, } - catalog := New(cfg, func(_ context.Context, server string) ([]mcppool.ToolInfo, error) { - if server != CodexAppsServerName { - t.Fatalf("listTools server = %q, want %q", server, CodexAppsServerName) - } - return []mcppool.ToolInfo{ - {Name: "linear_get_profile"}, - {Name: "zillow_get_zestimate"}, - {Name: "google calendar_search"}, - }, nil + calls := 0 + catalog := New(cfg, func(_ context.Context, _ string) ([]mcppool.ToolInfo, error) { + calls++ + return nil, nil }) names, err := catalog.ServerNames(context.Background()) @@ -34,10 +29,13 @@ func TestServerNamesHidesCodexAppsAndAddsVirtualApps(t *testing.T) { t.Fatalf("ServerNames() error = %v", err) } - want := []string{"google_calendar", "linear", "playwright", "supermemory", "zillow"} + want := []string{"playwright", "supermemory"} if !reflect.DeepEqual(names, want) { t.Fatalf("ServerNames() = %#v, want %#v", names, want) } + if calls != 0 { + t.Fatalf("codex list-tools calls = %d, want 0", calls) + } } func TestResolveReturnsConfiguredRouteWithoutCodexAppsProbe(t *testing.T) {