@@ -48,19 +48,17 @@ export class CodexAcpClient {
4848 private readonly codexClient : CodexAppServerClient ;
4949 private readonly config : JsonObject ;
5050 private readonly modelProvider : string | null ;
51- private readonly disableMcpConfigFiltering : boolean ;
5251 private gatewayConfig : GatewayConfig | null ;
5352 private pendingLoginCompleted : Promise < AccountLoginCompletedNotification > | null = null ;
5453 private pendingAccountUpdated : Promise < AccountUpdatedNotification > | null = null ;
5554 private readonly sessionNotificationQueues = new Map < string , Promise < void > > ( ) ;
5655 private skillExtraRoots : string [ ] = [ ] ;
5756
5857
59- constructor ( codexClient : CodexAppServerClient , codexConfig ?: JsonObject , modelProvider ?: string , disableMcpConfigFiltering = false ) {
58+ constructor ( codexClient : CodexAppServerClient , codexConfig ?: JsonObject , modelProvider ?: string ) {
6059 this . codexClient = codexClient ;
6160 this . config = codexConfig ?? { } ;
6261 this . modelProvider = modelProvider ?? null ;
63- this . disableMcpConfigFiltering = disableMcpConfigFiltering ;
6462 this . gatewayConfig = null ;
6563 }
6664
@@ -328,23 +326,23 @@ export class CodexAcpClient {
328326 return configWithWorkspaceRoots ;
329327 }
330328
331- // Deduplicates new servers against existing config to prevent Codex from deep-merging
332- // incompatible field types (e.g., mixing url and stdio schemas).
333- const existingNames = this . disableMcpConfigFiltering
334- ? new Set < string > ( )
335- : await this . getConfigMcpServerNames ( projectPath ) ;
336329 const requestedServers = mcpServers . map ( mcp => ( {
337330 name : sanitizeMcpServerName ( mcp . name ) ,
338331 server : mcp ,
339332 } ) ) ;
340- const uniqueServers = requestedServers . filter ( mcp => ! existingNames . has ( mcp . name ) ) ;
341- 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 ) {
342340 return configWithWorkspaceRoots ;
343341 }
344342
345343 return {
346344 ...configWithWorkspaceRoots ,
347- "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 ) ] ) ) ,
348346 } ;
349347 }
350348
@@ -739,6 +737,11 @@ function formatUriAsLink(name: string | null | undefined, uri: string): string {
739737 return uri ;
740738}
741739
740+ function shouldDeduplicateMcpConflicts ( ) : boolean {
741+ const disabledByEnv = process . env [ "DISABLE_MCP_CONFIG_FILTERING" ] === "true" ;
742+ return ! disabledByEnv ;
743+ }
744+
742745interface GatewayConfig {
743746 modelProvider : string ;
744747 config : {
0 commit comments