MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / TestAddServerMergesExistingFile

Function TestAddServerMergesExistingFile

internal/mcp/mcp_test.go:103–128  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

101}
102
103func TestAddServerMergesExistingFile(t *testing.T) {
104 home := t.TempDir()
105 t.Setenv("HOME", home)
106 client, _ := mcp.ClientByName("claude")
107 path := filepath.Join(home, ".claude.json")
108 preexisting := map[string]any{"theme": "dark"}
109 raw, _ := json.MarshalIndent(preexisting, "", " ")
110 if err := os.WriteFile(path, raw, 0o600); err != nil {
111 t.Fatal(err)
112 }
113 _, err := mcp.AddServer(client, mcp.UserScope, mcp.Server{Name: "x", Command: "y"})
114 if err != nil {
115 t.Fatal(err)
116 }
117 data, _ := os.ReadFile(path)
118 var got map[string]any
119 if err := json.Unmarshal(data, &got); err != nil {
120 t.Fatal(err)
121 }
122 if got["theme"] != "dark" {
123 t.Fatalf("theme overwritten: %v", got)
124 }
125 if _, ok := got["mcpServers"]; !ok {
126 t.Fatalf("missing mcpServers: %v", got)
127 }
128}

Callers

nothing calls this directly

Calls 3

ClientByNameFunction · 0.92
AddServerFunction · 0.92
ReadFileMethod · 0.80

Tested by

no test coverage detected