Skip to content

Commit 3c51ecc

Browse files
authored
Use the default profile in gateway. (#276)
1 parent 797afb6 commit 3c51ecc

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

cmd/docker-mcp/commands/gateway.go

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func gatewayCommand(docker docker.Client, dockerCli command.Cli) *cobra.Command
3333
// In-container.
3434
// Note: The catalog URL will be updated after checking the feature flag in RunE
3535
options = gateway.Config{
36-
CatalogPath: []string{catalog.DockerCatalogURLV2}, // Default to v2, will be updated based on flag
3736
SecretsPath: "docker-desktop:/run/secrets/mcp_secret:/.env",
3837
Options: gateway.Options{
3938
Cpus: 1,
@@ -47,11 +46,7 @@ func gatewayCommand(docker docker.Client, dockerCli command.Cli) *cobra.Command
4746
} else {
4847
// On-host.
4948
options = gateway.Config{
50-
CatalogPath: []string{catalog.DockerCatalogFilename},
51-
RegistryPath: []string{"registry.yaml"},
52-
ConfigPath: []string{"config.yaml"},
53-
ToolsPath: []string{"tools.yaml"},
54-
SecretsPath: "docker-desktop",
49+
SecretsPath: "docker-desktop",
5550
Options: gateway.Options{
5651
Cpus: 1,
5752
Memory: "2Gb",
@@ -62,12 +57,35 @@ func gatewayCommand(docker docker.Client, dockerCli command.Cli) *cobra.Command
6257
},
6358
}
6459
}
60+
if !isWorkingSetsFeatureEnabled(dockerCli) {
61+
// Default these only if we aren't defaulting to profiles
62+
setLegacyDefaults(&options)
63+
}
6564

6665
runCmd := &cobra.Command{
6766
Use: "run",
6867
Short: "Run the gateway",
6968
Args: cobra.NoArgs,
7069
RunE: func(cmd *cobra.Command, _ []string) error {
70+
if isWorkingSetsFeatureEnabled(dockerCli) {
71+
if len(options.ServerNames) > 0 || enableAllServers ||
72+
len(options.CatalogPath) > 0 || len(options.RegistryPath) > 0 || len(options.ConfigPath) > 0 || len(options.ToolsPath) > 0 ||
73+
len(additionalCatalogs) > 0 || len(additionalRegistries) > 0 || len(additionalConfigs) > 0 || len(additionalToolsConfig) > 0 ||
74+
len(mcpRegistryUrls) > 0 || len(options.OciRef) > 0 ||
75+
(options.SecretsPath != "docker-desktop" && !strings.HasPrefix(options.SecretsPath, "docker-desktop:")) {
76+
// We're in legacy mode, so we can't use the working set feature
77+
if options.WorkingSet != "" {
78+
return fmt.Errorf("cannot use --profile with --servers, --enable-all-servers, --catalog, --additional-catalog, --registry, --additional-registry, --config, --additional-config, --tools-config, --additional-tools-config, --secrets, --oci-ref, --mcp-registry flags")
79+
}
80+
// Make sure to default the options in legacy mode
81+
setLegacyDefaults(&options)
82+
} else if options.WorkingSet == "" {
83+
// ELSE we're in working set mode,
84+
// so IF no profile specified, use the default profile
85+
options.WorkingSet = "default"
86+
}
87+
}
88+
7189
// Check if OAuth interceptor feature is enabled
7290
options.OAuthInterceptorEnabled = isOAuthInterceptorFeatureEnabled(dockerCli)
7391

@@ -123,17 +141,6 @@ func gatewayCommand(docker docker.Client, dockerCli command.Cli) *cobra.Command
123141
options.MCPRegistryServers = mcpServers
124142
}
125143

126-
// TODO(cody): When all commands are migrated, we should default this parameter to "default"
127-
// Also need to consider the case when there is no default profile
128-
if options.WorkingSet != "" {
129-
if len(options.ServerNames) > 0 {
130-
return fmt.Errorf("cannot use --profile with --servers flag")
131-
}
132-
if enableAllServers {
133-
return fmt.Errorf("cannot use --profile with --enable-all-servers flag")
134-
}
135-
}
136-
137144
// Handle --enable-all-servers flag
138145
if enableAllServers {
139146
if len(options.ServerNames) > 0 {
@@ -361,3 +368,24 @@ func isWorkingSetsFeatureEnabled(dockerCli command.Cli) bool {
361368
}
362369
return value == "enabled"
363370
}
371+
372+
func setLegacyDefaults(options *gateway.Config) {
373+
if os.Getenv("DOCKER_MCP_IN_CONTAINER") == "1" {
374+
if len(options.CatalogPath) == 0 {
375+
options.CatalogPath = []string{catalog.DockerCatalogURLV2} // Default to v2, will be updated based on flag
376+
}
377+
} else {
378+
if len(options.CatalogPath) == 0 {
379+
options.CatalogPath = []string{catalog.DockerCatalogFilename}
380+
}
381+
if len(options.RegistryPath) == 0 {
382+
options.RegistryPath = []string{"registry.yaml"}
383+
}
384+
if len(options.ConfigPath) == 0 {
385+
options.ConfigPath = []string{"config.yaml"}
386+
}
387+
if len(options.ToolsPath) == 0 {
388+
options.ToolsPath = []string{"tools.yaml"}
389+
}
390+
}
391+
}

0 commit comments

Comments
 (0)