Skip to content

Commit 8eb4998

Browse files
committed
Refine MCP config conflict deduplication toggle
1 parent 6d19e69 commit 8eb4998

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

src/CodexAcpClient.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
723727
interface GatewayConfig {
724728
modelProvider: string;
725729
config: {

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ function startAcpServer() {
4242
const configString = process.env["CODEX_CONFIG"];
4343
const authRequestString = process.env["DEFAULT_AUTH_REQUEST"];
4444
const modelProvider = process.env["MODEL_PROVIDER"];
45-
const disableMcpConfigFiltering = process.env["DISABLE_MCP_CONFIG_FILTERING"] === "true";
4645
const config = configString ? JSON.parse(configString) : undefined;
4746
const parsedAuthRequest = authRequestString ? JSON.parse(authRequestString) : undefined;
4847
const defaultAuthRequest = parsedAuthRequest && isCodexAuthRequest(parsedAuthRequest) ? parsedAuthRequest : undefined;
@@ -73,7 +72,7 @@ function startAcpServer() {
7372

7473
function createAgent(connection: acp.AgentSideConnection): CodexAcpServer {
7574
const appServerClient = new CodexAppServerClient(codexConnection.connection);
76-
const codexClient = new CodexAcpClient(appServerClient, config, modelProvider, disableMcpConfigFiltering);
75+
const codexClient = new CodexAcpClient(appServerClient, config, modelProvider);
7776
return new CodexAcpServer(connection, codexClient, defaultAuthRequest, () => codexConnection.process.exitCode);
7877
}
7978

0 commit comments

Comments
 (0)