Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/docker-mcp/internal/catalog/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Server struct {
Env []Env `yaml:"env,omitempty" json:"env,omitempty"`
Command []string `yaml:"command,omitempty" json:"command,omitempty"`
Volumes []string `yaml:"volumes,omitempty" json:"volumes,omitempty"`
User string `yaml:"user,omitempty" json:"user,omitempty"`
DisableNetwork bool `yaml:"disableNetwork,omitempty" json:"disableNetwork,omitempty"`
AllowHosts []string `yaml:"allowHosts,omitempty" json:"allowHosts,omitempty"`
Tools []Tool `yaml:"tools,omitempty" json:"tools,omitempty"`
Expand Down Expand Up @@ -89,6 +90,7 @@ type Container struct {
Image string `yaml:"image" json:"image"`
Command []string `yaml:"command" json:"command"`
Volumes []string `yaml:"volumes" json:"volumes"`
User string `yaml:"user,omitempty" json:"user,omitempty"`
}

func (p *Properties) ToMap() map[string]any {
Expand Down
19 changes: 19 additions & 0 deletions cmd/docker-mcp/internal/gateway/clientpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ func (cp *clientPool) runToolContainer(ctx context.Context, tool catalog.Tool, p
args = append(args, "-v", mount)
}

// User
if tool.Container.User != "" {
userVal := fmt.Sprintf("%v", eval.Evaluate(tool.Container.User, arguments))
if userVal != "" {
args = append(args, "-u", userVal)
}
}

// Image
args = append(args, tool.Container.Image)

Expand Down Expand Up @@ -304,6 +312,17 @@ func (cp *clientPool) argsAndEnv(serverConfig *catalog.ServerConfig, readOnly *b
}
}

// User
if serverConfig.Spec.User != "" {
val := serverConfig.Spec.User
if strings.Contains(val, "{{") && strings.Contains(val, "}}") {
val = fmt.Sprintf("%v", eval.Evaluate(val, serverConfig.Config))
}
if val != "" {
args = append(args, "-u", val)
}
}

return args, env
}

Expand Down
15 changes: 15 additions & 0 deletions cmd/docker-mcp/internal/gateway/clientpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ hub:
assert.Empty(t, env)
}

func TestApplyConfigUser(t *testing.T) {
catalogYAML := `
user: "1001:2002"
`

args, env := argsAndEnv(t, "svc", catalogYAML, "", nil, nil)

assert.Equal(t, []string{
"run", "--rm", "-i", "--init", "--security-opt", "no-new-privileges", "--cpus", "1", "--memory", "2Gb", "--pull", "never",
"-l", "docker-mcp=true", "-l", "docker-mcp-tool-type=mcp", "-l", "docker-mcp-name=svc", "-l", "docker-mcp-transport=stdio",
"-u", "1001:2002",
}, args)
assert.Empty(t, env)
}

func argsAndEnv(t *testing.T, name, catalogYAML, configYAML string, secrets map[string]string, readOnly *bool) ([]string, []string) {
t.Helper()

Expand Down
Loading