@@ -160,13 +160,6 @@ const geminiSettingsJsonTemplate = `{
160160 "selectedType": "oauth-personal"
161161 },
162162 "disableYoloMode": false
163- },
164- "mcpServers": {
165- "playwright": {
166- "command": "docker-git-playwright-mcp",
167- "args": [],
168- "trust": true
169- }
170163 }
171164}`
172165
@@ -204,10 +197,40 @@ if [[ -d /etc/sudoers.d ]]; then
204197 chmod 0440 /etc/sudoers.d/gemini-agent
205198fi`
206199
207- const renderGeminiMcpPlaywrightConfig = ( _config : TemplateConfig ) : string =>
208- String . raw `# Gemini CLI: keep Playwright MCP config in sync (TODO: Gemini CLI MCP integration format)
209- # For now, Gemini CLI uses MCP via ~/.gemini/settings.json or command line.
210- # We'll ensure it has the same Playwright capability as Claude/Codex once format is confirmed.`
200+ const renderGeminiMcpPlaywrightConfig = ( ) : string =>
201+ String . raw `# Gemini CLI: keep Playwright MCP config in sync with container settings
202+ docker_git_sync_gemini_playwright_mcp() {
203+ GEMINI_CONFIG_SETTINGS_FILE="$GEMINI_CONFIG_SETTINGS_FILE" MCP_PLAYWRIGHT_ENABLE="${ "$" } {MCP_PLAYWRIGHT_ENABLE:-0}" node - <<'NODE'
204+ const fs = require("node:fs")
205+ const path = require("node:path")
206+ const settingsPath = process.env.GEMINI_CONFIG_SETTINGS_FILE
207+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value)
208+ if (typeof settingsPath !== "string" || settingsPath.length === 0) process.exit(0)
209+
210+ let settings = {}
211+ try {
212+ const parsed = JSON.parse(fs.readFileSync(settingsPath, "utf8"))
213+ if (isRecord(parsed)) settings = parsed
214+ } catch {}
215+
216+ const nextServers = { ...(isRecord(settings.mcpServers) ? settings.mcpServers : {}) }
217+ if (process.env.MCP_PLAYWRIGHT_ENABLE === "1") {
218+ nextServers.playwright = { command: "docker-git-playwright-mcp", args: [], trust: true }
219+ } else {
220+ delete nextServers.playwright
221+ }
222+
223+ const nextSettings = { ...settings }
224+ Object.keys(nextServers).length > 0 ? nextSettings.mcpServers = nextServers : delete nextSettings.mcpServers
225+
226+ if (JSON.stringify(settings) === JSON.stringify(nextSettings)) process.exit(0)
227+
228+ fs.mkdirSync(path.dirname(settingsPath), { recursive: true })
229+ fs.writeFileSync(settingsPath, JSON.stringify(nextSettings, null, 2) + "\n", { mode: 0o600 })
230+ NODE
231+ }
232+
233+ docker_git_sync_gemini_playwright_mcp`
211234
212235const renderGeminiProfileSetup = ( config : TemplateConfig ) : string =>
213236 String . raw `GEMINI_PROFILE="/etc/profile.d/gemini-config.sh"
@@ -311,7 +334,7 @@ export const renderEntrypointGeminiConfig = (config: TemplateConfig): string =>
311334 [
312335 renderGeminiAuthConfig ( config ) ,
313336 renderGeminiPermissionSettingsConfig ( config ) ,
314- renderGeminiMcpPlaywrightConfig ( config ) ,
337+ renderGeminiMcpPlaywrightConfig ( ) ,
315338 renderGeminiSudoConfig ( config ) ,
316339 renderGeminiProfileSetup ( config ) ,
317340 renderEntrypointGeminiNotice ( config )
0 commit comments