Skip to content

Commit 7b2aecf

Browse files
committed
Refine MCP config conflict deduplication toggle
1 parent b6f8c77 commit 7b2aecf

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

src/CodexAcpClient.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
742745
interface GatewayConfig {
743746
modelProvider: string;
744747
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)