@@ -326,21 +326,23 @@ export class CodexAcpClient {
326326 return configWithWorkspaceRoots ;
327327 }
328328
329- // Deduplicates new servers against existing config to prevent Codex from deep-merging
330- // incompatible field types (e.g., mixing url and stdio schemas).
331- const existingNames = await this . getConfigMcpServerNames ( projectPath ) ;
332329 const requestedServers = mcpServers . map ( mcp => ( {
333330 name : sanitizeMcpServerName ( mcp . name ) ,
334331 server : mcp ,
335332 } ) ) ;
336- const uniqueServers = requestedServers . filter ( mcp => ! existingNames . has ( mcp . name ) ) ;
337- if ( uniqueServers . length === 0 ) {
333+ let serversToConfigure = requestedServers ;
334+ if ( shouldDeduplicateMcpConflicts ( ) ) {
335+ // Prevents Codex from deep-merging incompatible field types, such as url and stdio schemas.
336+ const existingNames = await this . getConfigMcpServerNames ( projectPath ) ;
337+ serversToConfigure = requestedServers . filter ( mcp => ! existingNames . has ( mcp . name ) ) ;
338+ }
339+ if ( serversToConfigure . length === 0 ) {
338340 return configWithWorkspaceRoots ;
339341 }
340342
341343 return {
342344 ...configWithWorkspaceRoots ,
343- "mcp_servers" : Object . fromEntries ( uniqueServers . map ( mcp => [ mcp . name , this . createMcpSeverConfig ( mcp . server ) ] ) ) ,
345+ "mcp_servers" : Object . fromEntries ( serversToConfigure . map ( mcp => [ mcp . name , this . createMcpSeverConfig ( mcp . server ) ] ) ) ,
344346 } ;
345347 }
346348
@@ -739,6 +741,11 @@ function formatUriAsLink(name: string | null | undefined, uri: string): string {
739741 return uri ;
740742}
741743
744+ function shouldDeduplicateMcpConflicts ( ) : boolean {
745+ const disabledByEnv = process . env [ "DISABLE_MCP_CONFIG_FILTERING" ] === "true" ;
746+ return ! disabledByEnv ;
747+ }
748+
742749interface GatewayConfig {
743750 modelProvider : string ;
744751 config : {
0 commit comments