Skip to content

Commit cd5ab1c

Browse files
Merge pull request #286 from docker/slim/remove_session_parameter
remove --session name parameter
2 parents 334098c + 718c08f commit cd5ab1c

File tree

8 files changed

+3
-189
lines changed

8 files changed

+3
-189
lines changed

cmd/docker-mcp/commands/gateway.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ func gatewayCommand(docker docker.Client, dockerCli command.Cli) *cobra.Command
210210
runCmd.Flags().StringVar(&options.Memory, "memory", options.Memory, "Memory allocated to each MCP Server (default is 2Gb)")
211211
runCmd.Flags().BoolVar(&options.Static, "static", options.Static, "Enable static mode (aka pre-started servers)")
212212
runCmd.Flags().StringVar(&options.LogFilePath, "log", options.LogFilePath, "Path to log file for stderr output (relative or absolute)")
213-
runCmd.Flags().StringVar(&options.SessionName, "session", "", "Session name for loading and persisting configuration from ~/.docker/mcp/{SessionName}/")
214213

215214
// Very experimental features
216215
_ = runCmd.Flags().MarkHidden("log")

docs/generator/reference/docker_mcp_gateway_run.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,6 @@ options:
242242
experimentalcli: false
243243
kubernetes: false
244244
swarm: false
245-
- option: session
246-
value_type: string
247-
description: |
248-
Session name for loading and persisting configuration from ~/.docker/mcp/{SessionName}/
249-
deprecated: false
250-
hidden: false
251-
experimental: false
252-
experimentalcli: false
253-
kubernetes: false
254-
swarm: false
255245
- option: static
256246
value_type: bool
257247
default_value: "false"

docs/generator/reference/mcp_gateway_run.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ Run the gateway
2929
| `--registry` | `stringSlice` | `[registry.yaml]` | Paths to the registry files (absolute or relative to ~/.docker/mcp/) |
3030
| `--secrets` | `string` | `docker-desktop` | Colon separated paths to search for secrets. Can be `docker-desktop` or a path to a .env file (default to using Docker Desktop's secrets API) |
3131
| `--servers` | `stringSlice` | | Names of the servers to enable (if non empty, ignore --registry flag) |
32-
| `--session` | `string` | | Session name for loading and persisting configuration from ~/.docker/mcp/{SessionName}/ |
3332
| `--static` | `bool` | | Enable static mode (aka pre-started servers) |
3433
| `--tools` | `stringSlice` | | List of tools to enable |
3534
| `--tools-config` | `stringSlice` | `[tools.yaml]` | Paths to the tools files (absolute or relative to ~/.docker/mcp/) |

pkg/gateway/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ type Config struct {
1111
RegistryPath []string
1212
ToolsPath []string
1313
SecretsPath string
14-
SessionName string // Session name for persisting configuration
1514
MCPRegistryServers []catalog.Server // catalog.Server objects from MCP registries
1615
}
1716

pkg/gateway/configuration.go

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"time"
1212

1313
"github.com/fsnotify/fsnotify"
14-
"gopkg.in/yaml.v3"
1514

1615
"github.com/docker/mcp-gateway/pkg/catalog"
1716
"github.com/docker/mcp-gateway/pkg/config"
@@ -30,7 +29,6 @@ type Configuration struct {
3029
config map[string]map[string]any
3130
tools config.ToolsConfig
3231
secrets map[string]string
33-
SessionName string
3432
}
3533

3634
func (c *Configuration) ServerNames() []string {
@@ -92,51 +90,6 @@ func (c *Configuration) Find(serverName string) (*catalog.ServerConfig, *map[str
9290
return nil, &byName, true
9391
}
9492

95-
// Persist writes the configuration files to the session directory if SessionName is set
96-
func (c *Configuration) Persist() error {
97-
if c.SessionName == "" {
98-
return nil // No session name set, nothing to persist
99-
}
100-
101-
// Serialize and write registry.yaml
102-
registry := config.Registry{
103-
Servers: make(map[string]config.Tile),
104-
}
105-
for _, serverName := range c.serverNames {
106-
registry.Servers[serverName] = config.Tile{
107-
Ref: serverName,
108-
}
109-
}
110-
registryBytes, err := yaml.Marshal(registry)
111-
if err != nil {
112-
return fmt.Errorf("failed to marshal registry: %w", err)
113-
}
114-
if err := config.WriteConfigFileToSession(c.SessionName, "registry.yaml", registryBytes); err != nil {
115-
return fmt.Errorf("failed to write registry.yaml: %w", err)
116-
}
117-
118-
// Serialize and write config.yaml
119-
configBytes, err := yaml.Marshal(c.config)
120-
if err != nil {
121-
return fmt.Errorf("failed to marshal config: %w", err)
122-
}
123-
if err := config.WriteConfigFileToSession(c.SessionName, "config.yaml", configBytes); err != nil {
124-
return fmt.Errorf("failed to write config.yaml: %w", err)
125-
}
126-
127-
// Serialize and write tools.yaml
128-
toolsBytes, err := yaml.Marshal(c.tools)
129-
if err != nil {
130-
return fmt.Errorf("failed to marshal tools: %w", err)
131-
}
132-
if err := config.WriteConfigFileToSession(c.SessionName, "tools.yaml", toolsBytes); err != nil {
133-
return fmt.Errorf("failed to write tools.yaml: %w", err)
134-
}
135-
136-
log.Log(fmt.Sprintf(" - Configuration persisted to session '%s'", c.SessionName))
137-
return nil
138-
}
139-
14093
type FileBasedConfiguration struct {
14194
CatalogPath []string
14295
ServerNames []string // Takes precedence over the RegistryPath
@@ -148,7 +101,6 @@ type FileBasedConfiguration struct {
148101
MCPRegistryServers []catalog.Server // Servers fetched from MCP registries
149102
Watch bool
150103
McpOAuthDcrEnabled bool
151-
sessionName string // Session name for persisting configuration
152104

153105
docker docker.Client
154106
}

pkg/gateway/dynamic_mcps.go

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,6 @@ func (g *Gateway) createMcpRemoveTool() *ToolRegistration {
487487
return nil, fmt.Errorf("failed to remove server configuration: %w", err)
488488
}
489489

490-
// Persist configuration if session name is set
491-
if err := g.configuration.Persist(); err != nil {
492-
log.Log("Warning: Failed to persist configuration:", err)
493-
}
494-
495490
return &mcp.CallToolResult{
496491
Content: []mcp.Content{&mcp.TextContent{
497492
Text: fmt.Sprintf("Successfully removed server '%s'.", serverName),
@@ -811,11 +806,6 @@ func (g *Gateway) createMcpConfigSetTool(_ *clientConfig) *ToolRegistration {
811806
// Log the configuration change
812807
log.Log(fmt.Sprintf(" - Set config for server '%s': %s = %s", serverName, configKey, valueStr))
813808

814-
// Persist configuration if session name is set
815-
if err := g.configuration.Persist(); err != nil {
816-
log.Log("Warning: Failed to persist configuration:", err)
817-
}
818-
819809
var resultMessage string
820810
if oldValue != nil {
821811
resultMessage = fmt.Sprintf("Successfully updated config for server '%s': %s = %s (was: %s)", serverName, configKey, valueStr, oldValueStr)
@@ -840,92 +830,6 @@ func (g *Gateway) createMcpConfigSetTool(_ *clientConfig) *ToolRegistration {
840830
}
841831
}
842832

843-
// createMcpSessionNameTool implements a tool for setting the session name
844-
//
845-
//nolint:unused
846-
func (g *Gateway) createMcpSessionNameTool() *ToolRegistration {
847-
tool := &mcp.Tool{
848-
Name: "mcp-session-name",
849-
Description: "Set a session name for the gateway configuration. When set, configuration changes will be persisted to ~/.docker/mcp/{SessionName}/ directory.",
850-
InputSchema: &jsonschema.Schema{
851-
Type: "object",
852-
Properties: map[string]*jsonschema.Schema{
853-
"name": {
854-
Type: "string",
855-
Description: "Session name to set (alphanumeric and hyphens only)",
856-
},
857-
},
858-
Required: []string{"name"},
859-
},
860-
}
861-
862-
handler := func(_ context.Context, req *mcp.CallToolRequest) (*mcp.CallToolResult, error) {
863-
// Parse parameters
864-
var params struct {
865-
Name string `json:"name"`
866-
}
867-
868-
if req.Params.Arguments == nil {
869-
return nil, fmt.Errorf("missing arguments")
870-
}
871-
872-
paramsBytes, err := json.Marshal(req.Params.Arguments)
873-
if err != nil {
874-
return nil, fmt.Errorf("failed to marshal arguments: %w", err)
875-
}
876-
877-
if err := json.Unmarshal(paramsBytes, &params); err != nil {
878-
return nil, fmt.Errorf("failed to parse arguments: %w", err)
879-
}
880-
881-
if params.Name == "" {
882-
return nil, fmt.Errorf("name parameter is required")
883-
}
884-
885-
sessionName := strings.TrimSpace(params.Name)
886-
887-
// Validate session name (alphanumeric and hyphens only)
888-
if !isValidSessionName(sessionName) {
889-
return &mcp.CallToolResult{
890-
Content: []mcp.Content{&mcp.TextContent{
891-
Text: fmt.Sprintf("Error: Invalid session name '%s'. Session names must contain only alphanumeric characters and hyphens.", sessionName),
892-
}},
893-
}, nil
894-
}
895-
896-
// Set the session name
897-
g.configuration.SessionName = sessionName
898-
899-
// Persist the current configuration to the session directory
900-
if err := g.configuration.Persist(); err != nil {
901-
return nil, fmt.Errorf("failed to persist configuration: %w", err)
902-
}
903-
904-
return &mcp.CallToolResult{
905-
Content: []mcp.Content{&mcp.TextContent{
906-
Text: fmt.Sprintf("Successfully set session name to '%s'. Configuration will now be persisted to ~/.docker/mcp/%s/", sessionName, sessionName),
907-
}},
908-
}, nil
909-
}
910-
911-
return &ToolRegistration{
912-
Tool: tool,
913-
Handler: withToolTelemetry("mcp-session-name", handler),
914-
}
915-
}
916-
917-
// isValidSessionName checks if a session name contains only alphanumeric characters and hyphens
918-
//
919-
//nolint:unused
920-
func isValidSessionName(name string) bool {
921-
for _, ch := range name {
922-
if (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') && ch != '-' && ch != '_' {
923-
return false
924-
}
925-
}
926-
return len(name) > 0
927-
}
928-
929833
// createMcpExecTool implements a tool for executing tools that exist in the current session
930834
// but may not be returned from listTools calls
931835
func (g *Gateway) createMcpExecTool() *ToolRegistration {

pkg/gateway/mcpadd.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,6 @@ func (g *Gateway) createMcpAddTool(clientConfig *clientConfig) *ToolRegistration
244244
g.capabilitiesMu.Unlock()
245245
}
246246

247-
// Persist configuration if session name is set
248-
if err := g.configuration.Persist(); err != nil {
249-
log.Log("Warning: Failed to persist configuration:", err)
250-
}
251-
252247
// Get the list of tools that were just added from this server
253248
var addedTools []*mcp.Tool
254249
g.capabilitiesMu.RLock()

pkg/gateway/run.go

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,34 +81,17 @@ func NewGateway(config Config, docker docker.Client) *Gateway {
8181
if config.WorkingSet != "" {
8282
configurator = NewWorkingSetConfiguration(config.WorkingSet, oci.NewService(), docker)
8383
} else {
84-
// Prepend session-specific paths if SessionName is set
85-
registryPath := config.RegistryPath
86-
configPath := config.ConfigPath
87-
toolsPath := config.ToolsPath
88-
89-
if config.SessionName != "" {
90-
// Prepend session-specific paths to load session configs first
91-
sessionRegistry := fmt.Sprintf("%s/registry.yaml", config.SessionName)
92-
sessionConfig := fmt.Sprintf("%s/config.yaml", config.SessionName)
93-
sessionTools := fmt.Sprintf("%s/tools.yaml", config.SessionName)
94-
95-
registryPath = append([]string{sessionRegistry}, registryPath...)
96-
configPath = append([]string{sessionConfig}, configPath...)
97-
toolsPath = append([]string{sessionTools}, toolsPath...)
98-
}
99-
10084
configurator = &FileBasedConfiguration{
10185
ServerNames: config.ServerNames,
10286
CatalogPath: config.CatalogPath,
103-
RegistryPath: registryPath,
104-
ConfigPath: configPath,
87+
RegistryPath: config.RegistryPath,
88+
ConfigPath: config.ConfigPath,
10589
SecretsPath: config.SecretsPath,
106-
ToolsPath: toolsPath,
90+
ToolsPath: config.ToolsPath,
10791
OciRef: config.OciRef,
10892
MCPRegistryServers: config.MCPRegistryServers,
10993
Watch: config.Watch,
11094
McpOAuthDcrEnabled: config.McpOAuthDcrEnabled,
111-
sessionName: config.SessionName,
11295
docker: docker,
11396
}
11497
}
@@ -192,13 +175,6 @@ func (g *Gateway) Run(ctx context.Context) error {
192175
}
193176
defer func() { _ = stopConfigWatcher() }()
194177

195-
// Set the session name in the configuration for persistence if specified via --session flag
196-
if fbc, ok := g.configurator.(*FileBasedConfiguration); ok {
197-
if fbc.sessionName != "" {
198-
g.configuration.SessionName = fbc.sessionName
199-
}
200-
}
201-
202178
// Parse interceptors
203179
var parsedInterceptors []interceptors.Interceptor
204180
if len(g.Interceptors) > 0 {

0 commit comments

Comments
 (0)