Skip to content

Commit 93ae6e5

Browse files
Add support for extraHosts in MCP server catalog entries
Add support for the extraHosts setting in Catalog entries which allows specifying custom hostname-to-IP mappings for MCP containers. When present, the gateway passes these entries to Docker using the --add-host flag, adding static entries to the container's /etc/hosts file. Changes: - Add ExtraHosts []string field to catalog.Server struct - Add --add-host flag support in clientpool.argsAndEnv() function - Add TestApplyConfigExtraHosts test with playwright-like catalog entry - Add example catalog file showing usage with playwright server Example usage in catalog YAML: playwright: image: mcp/playwright@sha256:... extraHosts: - "myapp.local:192.168.1.100" - "testserver:10.0.0.5"
1 parent 16a778f commit 93ae6e5

4 files changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
registry:
2+
playwright:
3+
description: Playwright MCP server.
4+
title: Playwright
5+
type: server
6+
longLived: true
7+
dateAdded: "2025-05-05T20:04:34Z"
8+
image: mcp/playwright@sha256:53da89d1da3dfbb61c10f707c1713cfee1f870f7fba5334e126c6c765e37db56
9+
ref: ""
10+
readme: http://desktop.docker.com/mcp/catalog/v3/readme/playwright.md
11+
toolsUrl: http://desktop.docker.com/mcp/catalog/v3/tools/playwright.json
12+
source: https://github.com/microsoft/playwright-mcp/tree/64f65ccd105842204e3e1b1e1a7b28825492b089
13+
upstream: https://github.com/microsoft/playwright-mcp
14+
icon: https://avatars.githubusercontent.com/u/6154722?v=4
15+
extraHosts:
16+
- "myapp.local:192.168.1.100"
17+
- "testserver:10.0.0.5"

pkg/catalog/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Server struct {
3232
User string `yaml:"user,omitempty" json:"user,omitempty"`
3333
DisableNetwork bool `yaml:"disableNetwork,omitempty" json:"disableNetwork,omitempty"`
3434
AllowHosts []string `yaml:"allowHosts,omitempty" json:"allowHosts,omitempty"`
35+
ExtraHosts []string `yaml:"extraHosts,omitempty" json:"extraHosts,omitempty"`
3536
Tools []Tool `yaml:"tools,omitempty" json:"tools,omitempty"`
3637
Config []any `yaml:"config,omitempty" json:"config,omitempty"`
3738
Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty"`

pkg/gateway/clientpool.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@ func (cp *clientPool) argsAndEnv(serverConfig *catalog.ServerConfig, readOnly *b
373373
}
374374
}
375375

376+
// Extra hosts (for /etc/hosts entries)
377+
for _, host := range serverConfig.Spec.ExtraHosts {
378+
if host != "" {
379+
args = append(args, "--add-host", host)
380+
}
381+
}
382+
376383
return args, env
377384
}
378385

pkg/gateway/clientpool_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,29 @@ user: "1001:2002"
160160
assert.Empty(t, env)
161161
}
162162

163+
func TestApplyConfigExtraHosts(t *testing.T) {
164+
catalogYAML := `
165+
description: Playwright MCP server.
166+
title: Playwright
167+
type: server
168+
longLived: true
169+
image: mcp/playwright@sha256:53da89d1da3dfbb61c10f707c1713cfee1f870f7fba5334e126c6c765e37db56
170+
extraHosts:
171+
- "myhost:192.168.1.100"
172+
- "anotherhost:10.0.0.1"
173+
`
174+
175+
args, env := argsAndEnv(t, "playwright", catalogYAML, "", nil, nil)
176+
177+
assert.Equal(t, []string{
178+
"run", "--rm", "-i", "--init", "--security-opt", "no-new-privileges", "--cpus", "1", "--memory", "2Gb", "--pull", "never",
179+
"-l", "docker-mcp=true", "-l", "docker-mcp-tool-type=mcp", "-l", "docker-mcp-name=playwright", "-l", "docker-mcp-transport=stdio",
180+
"--add-host", "myhost:192.168.1.100",
181+
"--add-host", "anotherhost:10.0.0.1",
182+
}, args)
183+
assert.Empty(t, env)
184+
}
185+
163186
func TestApplyConfigLongLivedIgnoresReadOnly(t *testing.T) {
164187
catalogYAML := `
165188
longLived: true

0 commit comments

Comments
 (0)