Skip to content

Commit 1105330

Browse files
committed
Finally, wire up the multiple catalogs
1 parent 08dc26d commit 1105330

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

cmd/docker-mcp/commands/gateway.go

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,28 @@ func gatewayCommand(docker docker.Client, dockerCli command.Cli) *cobra.Command
8686
options.Port = 8811
8787
}
8888

89-
// Append additional catalogs to the main catalog path
90-
options.CatalogPath = append(options.CatalogPath, additionalCatalogs...)
89+
// Build catalog path list with proper precedence order
90+
catalogPaths := options.CatalogPath // Start with existing catalog paths (includes docker-mcp.yaml default)
91+
92+
// Add configured catalogs if requested
93+
if useConfiguredCatalogs {
94+
configuredPaths, err := getConfiguredCatalogPaths()
95+
if err != nil {
96+
return fmt.Errorf("failed to load configured catalog paths: %w", err)
97+
}
98+
// Insert configured catalogs after docker-mcp.yaml but before CLI-specified catalogs
99+
if len(catalogPaths) > 0 {
100+
// Insert after the first element (docker-mcp.yaml)
101+
catalogPaths = append(catalogPaths[:1], append(configuredPaths, catalogPaths[1:]...)...)
102+
} else {
103+
catalogPaths = append(catalogPaths, configuredPaths...)
104+
}
105+
}
106+
107+
// Append additional catalogs (CLI-specified have highest precedence)
108+
catalogPaths = append(catalogPaths, additionalCatalogs...)
109+
options.CatalogPath = catalogPaths
110+
91111
options.RegistryPath = append(options.RegistryPath, additionalRegistries...)
92112
options.ConfigPath = append(options.ConfigPath, additionalConfigs...)
93113
options.ToolsPath = append(options.ToolsPath, additionalToolsConfig...)
@@ -171,3 +191,23 @@ To enable this experimental feature, run:
171191
This feature allows the gateway to automatically include user-managed catalogs
172192
alongside the default Docker catalog.`)
173193
}
194+
195+
// getConfiguredCatalogPaths returns the file paths of all configured catalogs
196+
func getConfiguredCatalogPaths() ([]string, error) {
197+
cfg, err := catalog.ReadConfig()
198+
if err != nil {
199+
// If config doesn't exist or can't be read, return empty list
200+
// This is not an error condition - user just hasn't configured any catalogs yet
201+
return []string{}, nil
202+
}
203+
204+
var catalogPaths []string
205+
for catalogName := range cfg.Catalogs {
206+
// Skip the Docker catalog as it's handled separately
207+
if catalogName != catalog.DockerCatalogName {
208+
catalogPaths = append(catalogPaths, catalogName+".yaml")
209+
}
210+
}
211+
212+
return catalogPaths, nil
213+
}

0 commit comments

Comments
 (0)