Skip to content

Commit 06c93da

Browse files
update server enable/disable to support catalogs
1 parent b668ad3 commit 06c93da

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

cmd/docker-mcp/internal/catalog/catalog.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,27 @@ func GetWithOptions(ctx context.Context, useConfigured bool, additionalCatalogs
140140
catalogPaths = append(catalogPaths, additionalCatalogs...)
141141
}
142142

143+
// Remove duplicates while preserving order
144+
catalogPaths = removeDuplicates(catalogPaths)
145+
143146
return ReadFrom(ctx, catalogPaths)
144147
}
145148

149+
// removeDuplicates removes duplicate strings while preserving order (first occurrence wins)
150+
func removeDuplicates(slice []string) []string {
151+
keys := make(map[string]bool)
152+
result := []string{}
153+
154+
for _, item := range slice {
155+
if !keys[item] {
156+
keys[item] = true
157+
result = append(result, item)
158+
}
159+
}
160+
161+
return result
162+
}
163+
146164
// getConfiguredCatalogs reads the catalog registry and returns the list of configured catalog files
147165
func getConfiguredCatalogs() ([]string, error) {
148166
homeDir, err := user.HomeDir()

cmd/docker-mcp/server/enable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func update(ctx context.Context, docker docker.Client, add []string, remove []st
3232
return fmt.Errorf("parsing registry config: %w", err)
3333
}
3434

35-
catalog, err := catalog.Get(ctx)
35+
catalog, err := catalog.GetWithOptions(ctx, true, nil)
3636
if err != nil {
3737
return err
3838
}

cmd/docker-mcp/server/server_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ func withCatalog(yaml string) option {
229229
return func(t *testing.T, home string, _ *fakeDocker) {
230230
t.Helper()
231231
writeFile(t, filepath.Join(home, ".docker/mcp/catalogs/docker-mcp.yaml"), []byte(yaml))
232+
233+
// Create catalog.json registry file to register the docker-mcp catalog
234+
catalogRegistry := `{
235+
"catalogs": {
236+
"docker-mcp": {
237+
"displayName": "Docker MCP Default Catalog",
238+
"url": "docker-mcp.yaml",
239+
"lastUpdate": "2024-01-01T00:00:00Z"
240+
}
241+
}
242+
}`
243+
writeFile(t, filepath.Join(home, ".docker/mcp/catalog.json"), []byte(catalogRegistry))
232244
}
233245
}
234246

0 commit comments

Comments
 (0)