MCP: operator stderr logging is permanently silenced after the first generate_skill / pack_remote_repository call
What happens
Once an agent calls the generate_skill (or pack_remote_repository) MCP tool once, the
repomix MCP server stops emitting any operator diagnostic on stderr for the rest of the
session — including logger.error() output from completely unrelated tools. The tools keep
working and keep returning correct results, so nothing looks broken to the agent; only the
human sitting on the server side loses visibility, permanently for that session.
Mechanism
runCli()drives the shared module-level logger singleton to the level implied by its options and never restores it:src/cli/cliRun.ts:348-349(if (options.quiet) logger.setLogLevel(repomixLogLevels.SILENT)), and the same for--stdoutatsrc/cli/cliRun.ts:357-358. The singleton issrc/shared/logger.ts:89.- Two MCP tools call it that way:
src/mcp/tools/generateSkillTool.ts:127+:130andsrc/mcp/tools/packRemoteRepositoryTool.ts:109+:112, both withquiet: true. - For a one-shot CLI run this is invisible, because the process exits right after. The MCP server is long-lived, so the level change outlives the call.
src/mcp/tools/packCodebaseTool.ts:185-194already documents this exact hazard and works around it locally with a save/restoretry/finally.pack_codebasetherefore behaves; the other two tools do not.
So the invariant the maintainers wrote down for pack_codebase is simply not enforced for the
two sibling packing tools.
How to reproduce
Requires a built checkout (npm run build). fixture is any small directory with at least one
file to pack; the tools need a normalized absolute path.
// repro.mjs -> node repro.mjs <repoDir> <fixtureDir>
import { spawn } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
const [repo, fixture] = [process.argv[2], process.argv[3]];
const child = spawn(process.execPath, [path.join(repo, 'bin', 'repomix.cjs'), '--mcp'],
{ cwd: fixture, stdio: ['pipe', 'pipe', 'pipe'] });
const dir = path.normalize(fixture);
let stderrBuf = '', outBuf = '';
const waiters = [];
child.stderr.on('data', (d) => { stderrBuf += d; });
child.stdout.on('data', (d) => {
outBuf += d;
let i;
while ((i = outBuf.indexOf('\n')) >= 0) {
const line = outBuf.slice(0, i).trim();
outBuf = outBuf.slice(i + 1);
if (!line) continue;
let msg;
try { msg = JSON.parse(line); } catch { continue; }
for (let j = waiters.length - 1; j >= 0; j--) {
if (waiters[j].id === msg.id) { waiters[j].resolve(msg); waiters.splice(j, 1); }
}
}
});
let id = 0;
const rpc = (method, params) => {
const mid = ++id;
child.stdin.write(JSON.stringify({ jsonrpc: '2.0', id: mid, method, params }) + '\n');
return new Promise((r) => waiters.push({ id: mid, resolve: r }));
};
const settle = (ms = 700) => new Promise((r) => setTimeout(r, ms));
await rpc('initialize', { protocolVersion: '2024-11-05', capabilities: {},
clientInfo: { name: 'probe', version: '1.0.0' } });
child.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }) + '\n');
// pack_codebase registers an outputId (and saves/restores the log level itself, so it is clean)
const outId = (await rpc('tools/call',
{ name: 'pack_codebase', arguments: { directory: dir, topFilesLength: 1 } })).result.structuredContent.outputId;
// an invalid regex makes grep_repomix_output log its failure via logger.error AND return an error
const badGrep = () => rpc('tools/call', { name: 'grep_repomix_output',
arguments: { outputId: outId, pattern: '[unclosed', contextLines: 1 } });
const probe = async (label) => {
const mark = stderrBuf.length;
await badGrep();
await settle();
console.log(label, stderrBuf.slice(mark).includes('Error in grep_repomix_output search'));
};
await probe('[control] logger.error reached operator stderr:');
// generate_skill refuses to overwrite an existing skill dir and returns before reaching
// runCli, so drop it first to keep this repro repeatable
fs.rmSync(path.join(fixture, '.claude', 'skills', 'probe-skill'), { recursive: true, force: true });
await rpc('tools/call', { name: 'generate_skill', arguments: { directory: dir, skillName: 'probe-skill' } });
await probe('[after ] logger.error reached operator stderr:');
child.kill();Measured on repomix 1.18.0 (main @ 9f01703a), Node v24.18.0, Windows 11:
[control] logger.error reached operator stderr: true
[after ] logger.error reached operator stderr: falseThe failing grep_repomix_output call is byte-identical in both probes — the only difference is
that one generate_skill call happened in between. It also never recovers: a later
pack_codebase call (which restores the level it saved) leaves the logger at whatever level
that call saw, i.e. still SILENT, so the blindness is permanent for the session.
Suggested fix
Lift packCodebaseTool's save/restore into the shared MCP helper module and route all three
packing tools through it, so a fourth quiet tool cannot reintroduce the blind spot. Fix: #1865. One caveat worth writing down, raised in review there: restoring per call is not enough,
because the MCP SDK starts each tool handler without waiting for the previous one, so two overlapping
quiet packs have the second save the SILENT level the first just installed and hand that back. The
wrapper therefore counts in-flight packs and restores only when the last one finishes — verified with
two concurrent generate_skill calls over stdio. (The alternative — restoring the level inside runCli itself — was not chosen because the
CLI/library caller owns the process lifetime there and the mutation is harmless once the process
exits; it would also silently change behaviour for --stdout consumers.)
Found while driving the real stdio server, not from reading the code alone. Written by sxh313 with help from an AI coding agent (Qoder); the repro above was executed on a clean build.
Source: yamadashy/repomix