Skip to content
Open
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
5 changes: 4 additions & 1 deletion pkg/gateway/clientpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,10 @@ func (cp *clientPool) argsAndEnv(serverConfig *catalog.ServerConfig, readOnly *b
continue
}

if readOnly != nil && *readOnly && !strings.HasSuffix(mount, ":ro") {
// For long-lived servers, never mount volumes as read-only
// because the container will be shared across multiple tool calls
isLongLived := serverConfig.Spec.LongLived || cp.LongLived
if !isLongLived && readOnly != nil && *readOnly && !strings.HasSuffix(mount, ":ro") {
args = append(args, "-v", mount+":ro")
} else {
args = append(args, "-v", mount)
Expand Down
36 changes: 36 additions & 0 deletions pkg/gateway/clientpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,42 @@ user: "1001:2002"
assert.Empty(t, env)
}

func TestApplyConfigLongLivedIgnoresReadOnly(t *testing.T) {
catalogYAML := `
longLived: true
volumes:
- '/local/data:/data'
`

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

// Even though readOnly is true, volumes should NOT have :ro appended
// because long-lived servers share containers across multiple tool calls
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=longlived", "-l", "docker-mcp-transport=stdio",
"-v", "/local/data:/data",
}, args)
assert.Empty(t, env)
}

func TestApplyConfigShortLivedRespectsReadOnly(t *testing.T) {
catalogYAML := `
volumes:
- '/local/data:/data'
`

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

// Short-lived servers should respect readOnly flag
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=shortlived", "-l", "docker-mcp-transport=stdio",
"-v", "/local/data:/data:ro",
}, 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