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

Function RemoveServer

internal/mcp/client.go:133–159  ·  view source on GitHub ↗

RemoveServer deletes server from the client's config file at scope and reports whether the entry existed.

(client ClientSpec, scope Scope, serverName string)

Source from the content-addressed store, hash-verified

131// RemoveServer deletes server from the client's config file at scope and
132// reports whether the entry existed.
133func RemoveServer(client ClientSpec, scope Scope, serverName string) (string, bool, error) {
134 path := client.ResolvePath(scope)
135 if path == "" {
136 return "", false, fmt.Errorf("mcp: client %s does not support scope %s", client.Name, scope)
137 }
138 // Lock per-file to prevent concurrent read-modify-write races.
139 mu, _ := fileMu.LoadOrStore(path, &sync.Mutex{})
140 mu.(*sync.Mutex).Lock()
141 defer mu.(*sync.Mutex).Unlock()
142 data, err := readJSON(path)
143 if err != nil {
144 return path, false, err
145 }
146 container, _ := data[client.Container].(map[string]any)
147 if container == nil {
148 return path, false, nil
149 }
150 if _, ok := container[serverName]; !ok {
151 return path, false, nil
152 }
153 delete(container, serverName)
154 data[client.Container] = container
155 if err := writeJSON(path, data); err != nil {
156 return "", false, err
157 }
158 return path, true, nil
159}
160
161// ListServers returns all servers installed for the client at scope.
162func ListServers(client ClientSpec, scope Scope) ([]Server, string, error) {

Callers 3

RemoveMethod · 0.92
mcpRemoveCommandMethod · 0.92

Calls 3

readJSONFunction · 0.85
ResolvePathMethod · 0.80
writeJSONFunction · 0.70

Tested by 1