Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/CodexAcpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,9 +773,16 @@ export class CodexAcpClient {
return configWithWorkspaceRoots;
}

const configuredMcpServers = isJsonObject(configWithWorkspaceRoots["mcp_servers"])
? configWithWorkspaceRoots["mcp_servers"]
: {};

return {
...configWithWorkspaceRoots,
"mcp_servers": Object.fromEntries(serversToConfigure.map(mcp => [mcp.name, this.createMcpSeverConfig(mcp.server)])),
"mcp_servers": {
...configuredMcpServers,
...Object.fromEntries(serversToConfigure.map(mcp => [mcp.name, this.createMcpSeverConfig(mcp.server)])),
},
};
}

Expand Down
52 changes: 52 additions & 0 deletions src/__tests__/CodexACPAgent/CodexAcpClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,58 @@ describe('ACP server test', { timeout: 40_000 }, () => {
});
});

it('preserves MCP servers from CODEX_CONFIG when ACP adds another MCP server', async () => {
const mockFixture = createCodexMockTestFixture();
const codexAcpClient = mockFixture.getCodexAcpClient();
const codexAppServerClient = mockFixture.getCodexAppServerClient();

(codexAcpClient as unknown as {config: Record<string, unknown>}).config = {
mcp_servers: {
node_repl: {
env: {
HTTPS_PROXY: "http://127.0.0.1:7890",
},
},
},
};
vi.spyOn(codexAppServerClient, "listSkills").mockResolvedValue({data: []});
vi.spyOn(codexAppServerClient, "configRead").mockResolvedValue({config: {}} as any);
const threadStartSpy = vi.spyOn(codexAppServerClient, "threadStart").mockResolvedValue({
thread: {id: "thread-id"} as any,
model: "gpt-5",
reasoningEffort: "medium",
serviceTier: null,
} as any);
vi.spyOn(codexAppServerClient, "listModels").mockResolvedValue({
data: [createTestModel({id: "gpt-5"})],
nextCursor: null,
});

await codexAcpClient.newSession({
cwd: "/workspace",
mcpServers: [{
name: "docs",
command: "npx",
args: ["docs-mcp"],
env: [{name: "DOCS_TOKEN", value: "token"}],
}],
});

const threadStartRequest = threadStartSpy.mock.calls[0]![0];
expect(threadStartRequest.config?.["mcp_servers"]).toEqual({
node_repl: {
env: {
HTTPS_PROXY: "http://127.0.0.1:7890",
},
},
docs: {
command: "npx",
args: ["docs-mcp"],
env: {DOCS_TOKEN: "token"},
},
});
});

it('waits for typed mcp startup status updates and returns terminal states', async () => {
const mockFixture = createCodexMockTestFixture();
const codexAcpClient = mockFixture.getCodexAcpClient();
Expand Down