Skip to content

Commit a5eb42f

Browse files
committed
fix: add debug logging for safe outputs MCP server to improve error tracking
1 parent 68abb6e commit a5eb42f

File tree

5 files changed

+65
-56
lines changed

5 files changed

+65
-56
lines changed

.github/workflows/ci-doctor.lock.yml

Lines changed: 13 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/dev.lock.yml

Lines changed: 13 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cli/workflows/test-claude-missing-tool.lock.yml

Lines changed: 13 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cli/workflows/test-playwright-accessibility-contrast.lock.yml

Lines changed: 13 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/workflow/js/safe_outputs_mcp_server.cjs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const outputFile = process.env.GITHUB_AW_SAFE_OUTPUTS;
77
if (!outputFile)
88
throw new Error("GITHUB_AW_SAFE_OUTPUTS not set, no output file");
99
const SERVER_INFO = { name: "safe-outputs-mcp-server", version: "1.0.0" };
10+
const debug = (msg) => process.stderr.write(`[${SERVER_INFO.name}] ${msg}\n`);
1011
function writeMessage(obj) {
1112
const json = JSON.stringify(obj);
1213
const bytes = encoder.encode(json);
@@ -20,6 +21,7 @@ let buffer = Buffer.alloc(0);
2021
function onData(chunk) {
2122
buffer = Buffer.concat([buffer, chunk]);
2223
while (true) {
24+
debug(`on data buffer length: ${buffer.length} - ${buffer.toString("utf8")}`);
2325
const sep = buffer.indexOf("\r\n\r\n");
2426
if (sep === -1) break;
2527

@@ -50,10 +52,6 @@ function onData(chunk) {
5052
}
5153
}
5254

53-
process.stdin.on("data", onData);
54-
process.stdin.on("error", () => {});
55-
process.stdin.resume();
56-
5755
function replyResult(id, result) {
5856
if (id === undefined || id === null) return; // notification
5957
const res = { jsonrpc: "2.0", id, result };
@@ -316,15 +314,15 @@ const TOOLS = Object.fromEntries(
316314
.map(tool => [tool.name, tool])
317315
);
318316

319-
process.stderr.write(
320-
`[${SERVER_INFO.name}] v${SERVER_INFO.version} ready on stdio\n`
317+
debug(
318+
`v${SERVER_INFO.version} ready on stdio`
321319
);
322-
process.stderr.write(`[${SERVER_INFO.name}] output file: ${outputFile}\n`);
323-
process.stderr.write(
324-
`[${SERVER_INFO.name}] config: ${JSON.stringify(safeOutputsConfig)}\n`
320+
debug(` output file: ${outputFile}`);
321+
debug(
322+
` config: ${JSON.stringify(safeOutputsConfig)}`
325323
);
326-
process.stderr.write(
327-
`[${SERVER_INFO.name}] tools: ${Object.keys(TOOLS).join(", ")}\n`
324+
debug(
325+
` tools: ${Object.keys(TOOLS).join(", ")}`
328326
);
329327
if (!Object.keys(TOOLS).length)
330328
throw new Error("No tools enabled in configuration");
@@ -408,4 +406,7 @@ function handleMessage(req) {
408406
}
409407
}
410408

411-
process.stderr.write(`[${SERVER_INFO.name}] listening...\n`);
409+
process.stdin.on("data", onData);
410+
process.stdin.on("error", (err) => debug(`stdin error: ${err}`));
411+
process.stdin.resume();
412+
debug(`listening...`);

0 commit comments

Comments
 (0)