diff --git a/src/application/ClientConfigurationDocument.ts b/src/application/ClientConfigurationDocument.ts index 00a4e37eed..ce2e56daeb 100644 --- a/src/application/ClientConfigurationDocument.ts +++ b/src/application/ClientConfigurationDocument.ts @@ -32,7 +32,7 @@ import type { SetupClient } from "./SupportedClients.js"; import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js"; export type ClientConfigurationFormat = NonNullable; -export type ClientServersKey = "mcp_servers" | "mcpServers" | "mcp" | "servers"; +type ClientServersKey = "mcp_servers" | "mcpServers" | "mcp" | "servers"; /** * Registration entry dialect. OpenCode V2 reads V1 `mcp.` entries, but a @@ -50,6 +50,8 @@ export interface ClientConfigurationDocument { /** Key path of `servers` in `document`. */ readonly serversPath: readonly string[]; readonly dialect: ClientRegistrationDialect; + /** Member holding explicit environment overrides in a server registration. */ + readonly environmentKey: "env" | "environment"; /** * OpenCode V1 server members beside a native V2 `mcp.servers` table. OpenCode * still loads them, and a native entry with the same name takes precedence. @@ -217,6 +219,7 @@ export const parseZcodeFallbackConfiguration = ( : requireObject(document.mcpServers, "ZCode fallback mcpServers"), serversPath: ["mcpServers"], dialect: "zcode_fallback", + environmentKey: "env", legacyServers: {}, }; }; @@ -235,6 +238,7 @@ export const parseClientConfiguration = ( if (format === "zcode_fallback") return parseZcodeFallbackConfiguration(text); if (format === "dsh") return parseDshCordisDocument(text); const document = parseDocument(text, format); + const environmentKey = format === "opencode" ? "environment" : "env"; const serversKey = clientConfigurationServersKey(format); const value = document[serversKey]; const servers = @@ -251,6 +255,7 @@ export const parseClientConfiguration = ( : requireObject(nested, `"${serversKey}.servers"`), serversPath: [serversKey, "servers"], dialect: format, + environmentKey, legacyServers: {}, }; } @@ -270,6 +275,7 @@ export const parseClientConfiguration = ( servers, serversPath: [serversKey], dialect: format, + environmentKey, legacyServers: {}, }; return { @@ -277,6 +283,7 @@ export const parseClientConfiguration = ( servers: requireObject(native, `"${serversKey}.servers"`), serversPath: [serversKey, "servers"], dialect: "opencode_v2", + environmentKey, legacyServers: Object.fromEntries( Object.entries(servers).filter( ([name]) => !OPENCODE_V2_MCP_SETTINGS.has(name), @@ -1258,7 +1265,7 @@ const tomlServerEntry = ( }; /** Whether Grok Build's root disable list names `serverKey`. */ -export const grokServerListedDisabled = ( +const grokServerListedDisabled = ( document: Record, serverKey: string, ): boolean => @@ -1272,7 +1279,7 @@ export const grokServerListedDisabled = ( export const OMP_DISABLED_SERVERS_KEY = "disabledServers"; /** Whether OMP's root `disabledServers` denylist names `serverKey`. */ -export const ompServerListedDisabled = ( +const ompServerListedDisabled = ( document: Record, serverKey: string, ): boolean => { diff --git a/src/application/ClientConfigurationFiles.ts b/src/application/ClientConfigurationFiles.ts index a0e466766b..c4048e9488 100644 --- a/src/application/ClientConfigurationFiles.ts +++ b/src/application/ClientConfigurationFiles.ts @@ -208,10 +208,7 @@ export const effectiveClientConfiguration = ( const previous = servers[name]; const next = effectiveClientServer(document, name); const merged = mergeConfigurationValue(previous, next); - const key = - document.dialect === "opencode" || document.dialect === "opencode_v2" - ? "environment" - : "env"; + const key = document.environmentKey; if ( name === PRODUCT_IDENTITY.mcpServerKey && isObject(merged) && diff --git a/src/application/ClientRegistrationEnvironment.ts b/src/application/ClientRegistrationEnvironment.ts index 604bc30993..80498a029a 100644 --- a/src/application/ClientRegistrationEnvironment.ts +++ b/src/application/ClientRegistrationEnvironment.ts @@ -97,10 +97,7 @@ export const clientRegistrationEnvironmentDetails = ( ), ); } - const key = - parsed?.dialect === "opencode" || parsed?.dialect === "opencode_v2" - ? "environment" - : "env"; + const key = parsed?.environmentKey ?? "env"; const registration = parsed === undefined ? undefined diff --git a/src/application/DshCordisPatch.ts b/src/application/DshCordisPatch.ts index 339115c5b7..95fc988412 100644 --- a/src/application/DshCordisPatch.ts +++ b/src/application/DshCordisPatch.ts @@ -449,6 +449,7 @@ export const parseDshCordisDocument = ( servers: source.config === undefined ? {} : { rea: source.config }, serversPath: [], dialect: "dsh", + environmentKey: "env", legacyServers: {}, }; };