@@ -47,18 +47,16 @@ export class CodexAcpClient {
4747 private readonly codexClient : CodexAppServerClient ;
4848 private readonly config : JsonObject ;
4949 private readonly modelProvider : string | null ;
50- private readonly disableMcpConfigFiltering : boolean ;
5150 private gatewayConfig : GatewayConfig | null ;
5251 private pendingLoginCompleted : Promise < AccountLoginCompletedNotification > | null = null ;
5352 private pendingAccountUpdated : Promise < AccountUpdatedNotification > | null = null ;
5453 private readonly sessionNotificationQueues = new Map < string , Promise < void > > ( ) ;
5554
5655
57- constructor ( codexClient : CodexAppServerClient , codexConfig ?: JsonObject , modelProvider ?: string , disableMcpConfigFiltering = false ) {
56+ constructor ( codexClient : CodexAppServerClient , codexConfig ?: JsonObject , modelProvider ?: string ) {
5857 this . codexClient = codexClient ;
5958 this . config = codexConfig ?? { } ;
6059 this . modelProvider = modelProvider ?? null ;
61- this . disableMcpConfigFiltering = disableMcpConfigFiltering ;
6260 this . gatewayConfig = null ;
6361 }
6462
@@ -314,23 +312,23 @@ export class CodexAcpClient {
314312 return mergedConfig ;
315313 }
316314
317- // Deduplicates new servers against existing config to prevent Codex from deep-merging
318- // incompatible field types (e.g., mixing url and stdio schemas).
319- const existingNames = this . disableMcpConfigFiltering
320- ? new Set < string > ( )
321- : await this . getConfigMcpServerNames ( projectPath ) ;
322315 const requestedServers = mcpServers . map ( mcp => ( {
323316 name : sanitizeMcpServerName ( mcp . name ) ,
324317 server : mcp ,
325318 } ) ) ;
326- const uniqueServers = requestedServers . filter ( mcp => ! existingNames . has ( mcp . name ) ) ;
327- if ( uniqueServers . length === 0 ) {
319+ let serversToConfigure = requestedServers ;
320+ if ( shouldDeduplicateMcpConflicts ( ) ) {
321+ // Prevents Codex from deep-merging incompatible field types, such as url and stdio schemas.
322+ const existingNames = await this . getConfigMcpServerNames ( projectPath ) ;
323+ serversToConfigure = requestedServers . filter ( mcp => ! existingNames . has ( mcp . name ) ) ;
324+ }
325+ if ( serversToConfigure . length === 0 ) {
328326 return mergedConfig ;
329327 }
330328
331329 return {
332330 ...mergedConfig ,
333- "mcp_servers" : Object . fromEntries ( uniqueServers . map ( mcp => [ mcp . name , this . createMcpSeverConfig ( mcp . server ) ] ) ) ,
331+ "mcp_servers" : Object . fromEntries ( serversToConfigure . map ( mcp => [ mcp . name , this . createMcpSeverConfig ( mcp . server ) ] ) ) ,
334332 } ;
335333 }
336334
@@ -720,6 +718,12 @@ function formatUriAsLink(name: string | null | undefined, uri: string): string {
720718 return uri ;
721719}
722720
721+ function shouldDeduplicateMcpConflicts ( ) : boolean {
722+ const disabledByEnv = process . env [ "DISABLE_MCP_CONFIG_FILTERING" ] === "true" ;
723+ const disabledByArg = process . argv . includes ( "--disable-mcp-config-filtering" ) ;
724+ return ! disabledByEnv && ! disabledByArg ;
725+ }
726+
723727interface GatewayConfig {
724728 modelProvider : string ;
725729 config : {
0 commit comments