From 341c42c62f0413dbc5da979097ac05c59e5baede Mon Sep 17 00:00:00 2001 From: SonicKang Date: Tue, 17 Mar 2026 14:46:53 +0800 Subject: [PATCH] fix(opencode): use 'environment' instead of 'env' for MCP config (#29) OpenCode config schema uses 'environment' property for MCP server environment variables, not 'env'. Schema reference: https://opencode.ai/config.json --- src/doctor.test.ts | 2 +- src/doctor.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doctor.test.ts b/src/doctor.test.ts index de57ba3..3673ff8 100644 --- a/src/doctor.test.ts +++ b/src/doctor.test.ts @@ -81,7 +81,7 @@ describe('json token helpers', () => { }, }), 'abc123'); const parsed = JSON.parse(next); - expect(parsed.mcp.playwright.env.PLAYWRIGHT_MCP_EXTENSION_TOKEN).toBe('abc123'); + expect(parsed.mcp.playwright.environment.PLAYWRIGHT_MCP_EXTENSION_TOKEN).toBe('abc123'); }); }); diff --git a/src/doctor.ts b/src/doctor.ts index 9e3719b..9e7f43a 100644 --- a/src/doctor.ts +++ b/src/doctor.ts @@ -157,7 +157,7 @@ function readJsonConfigToken(content: string): string | null { function readTokenFromJsonObject(parsed: any): string | null { const direct = parsed?.mcpServers?.[PLAYWRIGHT_SERVER_NAME]?.env?.[PLAYWRIGHT_TOKEN_ENV]; if (typeof direct === 'string' && direct) return direct; - const opencode = parsed?.mcp?.[PLAYWRIGHT_SERVER_NAME]?.env?.[PLAYWRIGHT_TOKEN_ENV]; + const opencode = parsed?.mcp?.[PLAYWRIGHT_SERVER_NAME]?.environment?.[PLAYWRIGHT_TOKEN_ENV]; if (typeof opencode === 'string' && opencode) return opencode; return null; } @@ -178,8 +178,8 @@ export function upsertJsonConfigToken(content: string, token: string): string { enabled: true, type: 'local', }; - parsed.mcp[PLAYWRIGHT_SERVER_NAME].env = parsed.mcp[PLAYWRIGHT_SERVER_NAME].env ?? {}; - parsed.mcp[PLAYWRIGHT_SERVER_NAME].env[PLAYWRIGHT_TOKEN_ENV] = token; + parsed.mcp[PLAYWRIGHT_SERVER_NAME].environment = parsed.mcp[PLAYWRIGHT_SERVER_NAME].environment ?? {}; + parsed.mcp[PLAYWRIGHT_SERVER_NAME].environment[PLAYWRIGHT_TOKEN_ENV] = token; } return `${JSON.stringify(parsed, null, 2)}\n`; }