@@ -86,8 +86,28 @@ func gatewayCommand(docker docker.Client, dockerCli command.Cli) *cobra.Command
86
86
options .Port = 8811
87
87
}
88
88
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
+
91
111
options .RegistryPath = append (options .RegistryPath , additionalRegistries ... )
92
112
options .ConfigPath = append (options .ConfigPath , additionalConfigs ... )
93
113
options .ToolsPath = append (options .ToolsPath , additionalToolsConfig ... )
@@ -171,3 +191,23 @@ To enable this experimental feature, run:
171
191
This feature allows the gateway to automatically include user-managed catalogs
172
192
alongside the default Docker catalog.` )
173
193
}
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