Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(init): an inline mcp_servers table is kept as written [A9,I1]

Corey Olson4699805089a5
diff --git a/src/init.js b/src/init.js
index f4c790c4..c0a2df4a 100644
--- a/src/init.js
+++ b/src/init.js
@@ -493,6 +493,27 @@ export function codexHasMcpServer(contents, name) {
return false;
}
+/**
+ * Whether a Codex config.toml defines mcp_servers itself as an inline table (`mcp_servers = { ... }`). TOML never adds
+ * to an inline table, so an appended [mcp_servers.<name>] table would make the whole file invalid (#961).
+ *
+ * @param {string} contents
+ * @returns {boolean}
+ */
+export function codexMcpServersInline(contents) {
+ let table = [];
+ for (const raw of String(contents).split(/\r?\n/u)) {
+ const line = withoutTomlComment(raw).trim();
+ const header = /^\[\[?(.+?)\]\]?$/u.exec(line);
+ if (header) { table = tomlKeyParts(header[1]) ?? []; continue; }
+ const equals = line.indexOf('=');
+ if (equals < 1) continue;
+ const path = [...table, ...(tomlKeyParts(line.slice(0, equals)) ?? [null])];
+ if (path.length === 1 && path[0] === 'mcp_servers' && line.slice(equals + 1).trim().startsWith('{')) return true;
+ }
+ return false;
+}
+
/**
* Register pullboard mcp for Claude Code (.mcp.json) and Codex (.codex/config.toml), merging with any servers already
* there and never replacing a pullboard entry or a file it cannot read, so an agent can work the loop through MCP (#961).
@@ -523,6 +544,9 @@ function writeMcpConfig(root, onWrite) {
const contents = existsSync(codex) ? readFileSync(codex, 'utf8') : '';
if (codexHasMcpServer(contents, 'pullboard')) {
notes.push('kept the Codex MCP server in .codex/config.toml');
+ } else if (codexMcpServersInline(contents)) {
+ // Rewriting the person's inline table would change bytes they wrote; they add the entry where TOML allows it.
+ notes.push(`kept .codex/config.toml, whose mcp_servers is an inline table; add pullboard = { command = "sh", args = ["-c", ${JSON.stringify(MCP_COMMAND)}] } inside it so Codex runs pullboard mcp`);
} else {
// A new table at the end is valid TOML after any existing content, so nothing already there is rewritten.
const prefix = contents && !contents.endsWith('\n') ? `${contents}\n` : contents;
diff --git a/test/init-permissions.test.js b/test/init-permissions.test.js
index c32f27e9..99bdaf6e 100644
--- a/test/init-permissions.test.js
+++ b/test/init-permissions.test.js
@@ -223,3 +223,18 @@ test('init keeps an existing Codex pullboard server in any TOML form and adds no
assert.ok(after.startsWith(other), 'the existing config is kept');
assert.match(after.slice(other.length), /^\n\[mcp_servers\.pullboard\]\ncommand = "sh"\n/u, 'the pullboard server is appended once');
});
+
+test('init leaves an inline mcp_servers table as written and names the entry to add [A9,I1]', (t) => {
+ // TOML never adds to an inline table, so appending [mcp_servers.pullboard] after one makes the file invalid.
+ for (const existing of ['mcp_servers = { other = { command = "other-server", args = ["serve"] } }\n', 'mcp_servers = {}\n']) {
+ const box = initFixture(t);
+ mkdirSync(join(box.root, '.codex'), { recursive: true });
+ writeFileSync(join(box.root, '.codex', 'config.toml'), existing);
+ const initialized = box.init();
+ assert.equal(initialized.code, 0, initialized.stderr);
+ assert.equal(readFileSync(join(box.root, '.codex', 'config.toml'), 'utf8'), existing, 'the inline table is byte for byte as it was');
+ const note = initialized.document.notes.find(entry => entry.startsWith('kept .codex/config.toml, whose mcp_servers is an inline table'));
+ assert.ok(note, 'init says why it kept the file');
+ assert.match(note, /add pullboard = \{ command = "sh", args = \["-c", "[^\n]+"\] \} inside it/u, 'and names the exact entry to add');
+ }
+});