fix: auto-write Codex MCP config

- Merge RA-H MCP settings into Codex config.toml when --yes is passed
- Preserve unrelated TOML config while replacing stale RA-H blocks
- Update docs and package version for the Codex auto setup path

Generated with Claude Code
This commit is contained in:
“BeeRad”
2026-04-21 08:49:31 +10:00
parent 21772fcba7
commit 07ca873702
6 changed files with 45 additions and 15 deletions
+2 -2
View File
@@ -85,12 +85,12 @@ Other clients:
```bash ```bash
npx -y ra-h-mcp-server@latest setup --client cursor --yes npx -y ra-h-mcp-server@latest setup --client cursor --yes
npx -y ra-h-mcp-server@latest setup --client codex npx -y ra-h-mcp-server@latest setup --client codex --yes
``` ```
Notes: Notes:
- `--yes` lets the installer write supported client config automatically. - `--yes` lets the installer write supported client config automatically.
- Codex uses TOML config, so the installer prints the block to add. - Codex uses TOML config, so the installer writes `CODEX_HOME/config.toml` or `~/.codex/config.toml`.
- The MCP-only path does not clone this repo and does not start the browser UI. - The MCP-only path does not clone this repo and does not start the browser UI.
- The installer defaults to the latest published MCP package. For release/debug reproducibility, pin an exact version intentionally. - The installer defaults to the latest published MCP package. For release/debug reproducibility, pin an exact version intentionally.
+2 -2
View File
@@ -14,13 +14,13 @@ Other useful commands:
```bash ```bash
npx -y ra-h-mcp-server@latest setup --client cursor --yes npx -y ra-h-mcp-server@latest setup --client cursor --yes
npx -y ra-h-mcp-server@latest setup --client codex npx -y ra-h-mcp-server@latest setup --client codex --yes
npx -y ra-h-mcp-server@latest init-db npx -y ra-h-mcp-server@latest init-db
npx -y ra-h-mcp-server@latest doctor npx -y ra-h-mcp-server@latest doctor
npx -y ra-h-mcp-server@latest print-config --client claude-code npx -y ra-h-mcp-server@latest print-config --client claude-code
``` ```
`--yes` lets the installer write supported JSON client config automatically. Codex uses TOML config, so the installer prints the block to add. `--yes` lets the installer write supported client config automatically. Codex uses TOML config, so the installer writes `CODEX_HOME/config.toml` or `~/.codex/config.toml`.
Important contract: Important contract:
- `@latest` is the default user-facing install path - `@latest` is the default user-facing install path
+35 -5
View File
@@ -261,11 +261,11 @@ function clientConfig(client, args, dbPath) {
if (client === 'codex') { if (client === 'codex') {
return { return {
type: 'toml', type: 'toml-merge',
path: path.join(os.homedir(), '.codex', 'config.toml'), path: path.join(process.env.CODEX_HOME || path.join(os.homedir(), '.codex'), 'config.toml'),
snippet: `[mcp_servers.ra-h]\ncommand = "npx"\nargs = ["-y", "${packageSpec(args)}"]\n\n[mcp_servers.ra-h.env]\nRAH_DB_PATH = "${dbPath.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"\n`, snippet: `[mcp_servers.ra-h]\ncommand = "npx"\nargs = ["-y", "${packageSpec(args)}"]\n\n[mcp_servers.ra-h.env]\nRAH_DB_PATH = "${dbPath.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"\n`,
writable: false, writable: true,
note: 'Codex config is TOML; this installer prints the block instead of mutating existing config.', note: 'Codex config is TOML; pass --yes to merge this block into the Codex config file.',
}; };
} }
@@ -306,6 +306,32 @@ function writeJsonMerge(config) {
fs.writeFileSync(config.path, `${JSON.stringify(next, null, 2)}\n`); fs.writeFileSync(config.path, `${JSON.stringify(next, null, 2)}\n`);
} }
function removeTomlTables(raw, tableNames) {
const tables = new Set(tableNames);
const lines = raw.split(/\r?\n/);
const kept = [];
let skipping = false;
for (const line of lines) {
const match = line.match(/^\s*\[([^\]]+)\]\s*$/);
if (match) {
skipping = tables.has(match[1]);
}
if (!skipping) kept.push(line);
}
return kept.join('\n').trimEnd();
}
function writeTomlMerge(config) {
const current = fs.existsSync(config.path) ? fs.readFileSync(config.path, 'utf8') : '';
const withoutRah = removeTomlTables(current, ['mcp_servers.ra-h', 'mcp_servers.ra-h.env']);
const next = `${withoutRah ? `${withoutRah}\n\n` : ''}${config.snippet.trimEnd()}\n`;
fs.mkdirSync(path.dirname(config.path), { recursive: true });
fs.writeFileSync(config.path, next);
}
function formatSnippet(snippet) { function formatSnippet(snippet) {
return typeof snippet === 'string' ? snippet : JSON.stringify(snippet, null, 2); return typeof snippet === 'string' ? snippet : JSON.stringify(snippet, null, 2);
} }
@@ -404,9 +430,13 @@ function commandSetup(args) {
if (config.path) log(`MCP config target: ${config.path}`); if (config.path) log(`MCP config target: ${config.path}`);
if (config.note) log(config.note); if (config.note) log(config.note);
const canWrite = config.writable && config.type === 'json-merge' && config.path; const canWrite = config.writable && ['json-merge', 'toml-merge'].includes(config.type) && config.path;
if (canWrite && args.yes && !args.printOnly) { if (canWrite && args.yes && !args.printOnly) {
if (config.type === 'toml-merge') {
writeTomlMerge(config);
} else {
writeJsonMerge(config); writeJsonMerge(config);
}
log(`Updated ${config.path}`); log(`Updated ${config.path}`);
} else if (canWrite) { } else if (canWrite) {
log('Pass --yes to write this config automatically.'); log('Pass --yes to write this config automatically.');
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "ra-h-mcp-server", "name": "ra-h-mcp-server",
"version": "3.2.0", "version": "3.2.1",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "ra-h-mcp-server", "name": "ra-h-mcp-server",
"version": "3.2.0", "version": "3.2.1",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@modelcontextprotocol/sdk": "^1.0.0", "@modelcontextprotocol/sdk": "^1.0.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "ra-h-mcp-server", "name": "ra-h-mcp-server",
"version": "3.2.0", "version": "3.2.1",
"description": "Connect Claude Code/Desktop to your RA-H knowledge base. Direct SQLite access to an existing RA-H database.", "description": "Connect Claude Code/Desktop to your RA-H knowledge base. Direct SQLite access to an existing RA-H database.",
"main": "index.js", "main": "index.js",
"bin": { "bin": {
+2 -2
View File
@@ -14,10 +14,10 @@ Other clients:
```bash ```bash
npx -y ra-h-mcp-server@latest setup --client cursor --yes npx -y ra-h-mcp-server@latest setup --client cursor --yes
npx -y ra-h-mcp-server@latest setup --client codex npx -y ra-h-mcp-server@latest setup --client codex --yes
``` ```
`--yes` lets the installer write supported JSON client config automatically. Codex uses TOML config, so the installer prints the block to add. `--yes` lets the installer write supported client config automatically. Codex uses TOML config, so the installer writes `CODEX_HOME/config.toml` or `~/.codex/config.toml`.
Verify the install: Verify the install: