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
28 changes: 2 additions & 26 deletions internal/config/fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,28 +496,6 @@ func isWithinPath(path, root string) bool {
return strings.HasPrefix(path, root+string(os.PathSeparator))
}

func nearestUpwardPath(relPath, cwd string) string {
base := resolveWorkingDirectory(cwd)
if base == "" {
return ""
}

dir := base
for {
candidate := filepath.Join(dir, relPath)
info, err := os.Stat(candidate)
if err == nil && !info.IsDir() {
return candidate
}

parent := filepath.Dir(dir)
if parent == dir {
return ""
}
dir = parent
}
}

func fallbackSourcePaths(cfg *Config) []string {
return fallbackSourcePathsForCWD(cfg, "")
}
Expand All @@ -534,6 +512,8 @@ func defaultFallbackSourcePaths() []string {
}

func defaultFallbackSourcePathsForCWD(cwd string) []string {
_ = cwd
Comment on lines 514 to +515
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore an opt-in path for project-local fallback configs

Ignoring cwd here removes the only code path that ever added the nearest-parent .mcp.json / .kiro/settings/mcp.json files to the default fallback set. That means any trusted repo that relied on project-local MCP config for zero-config onboarding now regresses to mcpx listing no servers (or unknown server) unless the user manually copies those entries into a global config. fallback_sources is not an equivalent workaround because it is a static path list from config.toml, not “the nearest file under the request CWD”, so this change removes the feature entirely instead of making it explicit/opt-in.

Useful? React with 👍 / 👎.


home, _ := os.UserHomeDir()
if home == "" {
return nil
Expand All @@ -547,9 +527,7 @@ func defaultFallbackSourcePathsForCWD(cwd string) []string {
filepath.Join(home, "Library", "Application Support", "Code", "User", "globalStorage", "saoudrizwan.claude-dev", "settings", "cline_mcp_settings.json"),
filepath.Join(home, ".claude.json"),
filepath.Join(home, ".codex", "config.toml"),
nearestUpwardPath(".mcp.json", cwd),
filepath.Join(home, ".kiro", "settings", "mcp.json"),
nearestUpwardPath(filepath.Join(".kiro", "settings", "mcp.json"), cwd),
}
case "linux":
return []string{
Expand All @@ -558,9 +536,7 @@ func defaultFallbackSourcePathsForCWD(cwd string) []string {
filepath.Join(home, ".config", "Code", "User", "globalStorage", "saoudrizwan.claude-dev", "settings", "cline_mcp_settings.json"),
filepath.Join(home, ".claude.json"),
filepath.Join(home, ".codex", "config.toml"),
nearestUpwardPath(".mcp.json", cwd),
filepath.Join(home, ".kiro", "settings", "mcp.json"),
nearestUpwardPath(filepath.Join(".kiro", "settings", "mcp.json"), cwd),
}
default:
return nil
Expand Down
56 changes: 5 additions & 51 deletions internal/config/fallback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ bearer_token_env_var = "REMOTE_TOKEN"
}

func TestLoadCodexConfigFileAddsCodexAppsServerFromAuthFile(t *testing.T) {
t.Setenv("CODEX_HOME", "")
home := t.TempDir()
t.Setenv("HOME", home)

Expand Down Expand Up @@ -492,6 +493,7 @@ apps = true
}

func TestLoadCodexConfigFileCodexAppsUsesConnectorsTokenEnv(t *testing.T) {
t.Setenv("CODEX_HOME", "")
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv(codexConnectorsTokenEnvVar, "connectors-999")
Expand Down Expand Up @@ -730,43 +732,6 @@ func TestLoadMCPServersFileReadsClaudeCodeProjectServers(t *testing.T) {
}
}

func TestNearestUpwardPathFindsNearestParent(t *testing.T) {
root := t.TempDir()
parent := filepath.Join(root, "parent")
child := filepath.Join(parent, "child")
grandChild := filepath.Join(child, "grandchild")
if err := os.MkdirAll(grandChild, 0700); err != nil {
t.Fatalf("mkdir grandchild: %v", err)
}

nearest := filepath.Join(child, ".mcp.json")
farther := filepath.Join(parent, ".mcp.json")
for _, path := range []string{nearest, farther} {
if err := os.WriteFile(path, []byte(`{"mcpServers":{}}`), 0600); err != nil {
t.Fatalf("write %s: %v", path, err)
}
}

prevWD, err := os.Getwd()
if err != nil {
t.Fatalf("getwd: %v", err)
}
t.Cleanup(func() {
_ = os.Chdir(prevWD)
})
if err := os.Chdir(grandChild); err != nil {
t.Fatalf("chdir grandchild: %v", err)
}

if got := nearestUpwardPath(".mcp.json", ""); got != nearest {
gotResolved, gotErr := filepath.EvalSymlinks(got)
wantResolved, wantErr := filepath.EvalSymlinks(nearest)
if gotErr != nil || wantErr != nil || gotResolved != wantResolved {
t.Fatalf("nearestUpwardPath(.mcp.json) = %q, want %q", got, nearest)
}
}
}

func TestMergeFallbackServersForCWDUsesProvidedWorkingDirectory(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
Expand All @@ -791,17 +756,6 @@ func TestMergeFallbackServersForCWDUsesProvidedWorkingDirectory(t *testing.T) {
t.Fatalf("write project-b config: %v", err)
}

prevWD, err := os.Getwd()
if err != nil {
t.Fatalf("getwd: %v", err)
}
t.Cleanup(func() {
_ = os.Chdir(prevWD)
})
if err := os.Chdir(projectASubdir); err != nil {
t.Fatalf("chdir project-a subdir: %v", err)
}

paths := fallbackSourcePathsForCWD(nil, projectBSubdir)
if len(paths) == 0 {
t.Skip("no fallback source paths for this platform")
Expand All @@ -811,11 +765,11 @@ func TestMergeFallbackServersForCWDUsesProvidedWorkingDirectory(t *testing.T) {
if err := MergeFallbackServersForCWD(cfg, projectBSubdir); err != nil {
t.Fatalf("MergeFallbackServersForCWD() error = %v", err)
}
if _, ok := cfg.Servers["server-b"]; !ok {
t.Fatalf("cfg.Servers = %#v, want server-b from provided cwd", cfg.Servers)
if _, ok := cfg.Servers["server-b"]; ok {
t.Fatalf("cfg.Servers = %#v, want project-local server excluded", cfg.Servers)
}
if _, ok := cfg.Servers["server-a"]; ok {
t.Fatalf("cfg.Servers = %#v, want server-a excluded", cfg.Servers)
t.Fatalf("cfg.Servers = %#v, want project-local server excluded", cfg.Servers)
}
}

Expand Down
Loading