Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix: detect MCP name collisions from parsed Codex config

Afloat958f66787e23
diff --git a/server/drivers/codex-mcp-names.test.ts b/server/drivers/codex-mcp-names.test.ts
index 4557435808..6fab4362b4 100644
--- a/server/drivers/codex-mcp-names.test.ts
+++ b/server/drivers/codex-mcp-names.test.ts
@@ -64,6 +64,28 @@ describe("codexConfigRunsServer", () => {
return codexConfigMcp({ CODEX_HOME: home });
};
+ it.each([
+ 'mcp_servers = { notes = { url = "https://notes.example/mcp" } }',
+ 'mcp_servers.notes.url = "https://notes.example/mcp"',
+ '[mcp_servers."not\\u0065s"]\nurl = "https://notes.example/mcp"',
+ ])("reserves the parsed server name in %s", (toml) => {
+ const config = configFor(toml);
+ expect([...config.names]).toEqual(["notes"]);
+ expect(mountedMcpServerName("notes", config.names)).toBe("notes_openmausbot");
+ expect(codexConfigRunsServer(config, "notes", { type: "http", url: "https://notes.example/mcp", headers: {} })).toBe(true);
+ });
+
+ it("ignores table-looking text inside strings when the file parses", () => {
+ const config = configFor('instructions = """\n[mcp_servers.decoy]\n"""\n');
+ expect([...config.names]).toEqual([]);
+ });
+
+ it("still reserves header names if an unrelated setting cannot be parsed", () => {
+ const config = configFor('[mcp_servers.notes]\nurl = "https://notes.example/mcp"\nunfinished = [');
+ expect([...config.names]).toEqual(["notes"]);
+ expect(config.tables).toEqual({});
+ });
+
it("knows a server config.toml already starts, as one brought in from there, and nothing else", () => {
const config = configFor([
"[mcp_servers.sentry]", 'command = "npx"', 'args = ["-y", "@sentry/mcp-server", 8080]', "[mcp_servers.sentry.env]", 'SENTRY_TOKEN = "t"',
diff --git a/server/drivers/codex-mcp-names.ts b/server/drivers/codex-mcp-names.ts
index c0454c516a..4882007f7a 100644
--- a/server/drivers/codex-mcp-names.ts
+++ b/server/drivers/codex-mcp-names.ts
@@ -11,7 +11,7 @@ import { parseToml } from "../toml-lite.ts";
const HEADER = /^[ \t]*\[[ \t]*mcp_servers[ \t]*\.[ \t]*(?:"((?:[^"\\]|\\.)*)"|'([^']*)'|([A-Za-z0-9_-]+))[ \t]*[.\]]/gm;
-/** Inline tables are not scanned; a collision there still surfaces as codex's own configuration error. */
+/** Best-effort table-header names when config.toml cannot be parsed. */
export function mcpServerNamesInToml(toml: string): Set<string> {
const names = new Set<string>();
for (const match of toml.matchAll(HEADER)) {
@@ -39,6 +39,7 @@ export function codexConfigMcp(env: Record<string, string | undefined>): CodexCo
try {
const servers = parseToml(text).mcp_servers;
if (isRecord(servers)) tables = servers;
+ return { names: new Set(Object.keys(tables)), tables };
} catch {}
return { names: mcpServerNamesInToml(text), tables };
}