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:
@@ -85,12 +85,12 @@ Other clients:
|
||||
|
||||
```bash
|
||||
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:
|
||||
- `--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 installer defaults to the latest published MCP package. For release/debug reproducibility, pin an exact version intentionally.
|
||||
|
||||
|
||||
@@ -14,13 +14,13 @@ Other useful commands:
|
||||
|
||||
```bash
|
||||
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 doctor
|
||||
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:
|
||||
- `@latest` is the default user-facing install path
|
||||
|
||||
@@ -261,11 +261,11 @@ function clientConfig(client, args, dbPath) {
|
||||
|
||||
if (client === 'codex') {
|
||||
return {
|
||||
type: 'toml',
|
||||
path: path.join(os.homedir(), '.codex', 'config.toml'),
|
||||
type: 'toml-merge',
|
||||
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`,
|
||||
writable: false,
|
||||
note: 'Codex config is TOML; this installer prints the block instead of mutating existing config.',
|
||||
writable: true,
|
||||
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`);
|
||||
}
|
||||
|
||||
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) {
|
||||
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.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) {
|
||||
writeJsonMerge(config);
|
||||
if (config.type === 'toml-merge') {
|
||||
writeTomlMerge(config);
|
||||
} else {
|
||||
writeJsonMerge(config);
|
||||
}
|
||||
log(`Updated ${config.path}`);
|
||||
} else if (canWrite) {
|
||||
log('Pass --yes to write this config automatically.');
|
||||
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "ra-h-mcp-server",
|
||||
"version": "3.2.0",
|
||||
"version": "3.2.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "ra-h-mcp-server",
|
||||
"version": "3.2.0",
|
||||
"version": "3.2.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@modelcontextprotocol/sdk": "^1.0.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"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.",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
|
||||
+2
-2
@@ -14,10 +14,10 @@ Other clients:
|
||||
|
||||
```bash
|
||||
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:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user