From 207f4336a3cb410338fcc001901ff2b3e1cb2f06 Mon Sep 17 00:00:00 2001 From: haosenwang1018 Date: Thu, 19 Mar 2026 06:46:43 +0000 Subject: [PATCH] fix: await stdout writes for tool output --- src/commands/call.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/commands/call.ts b/src/commands/call.ts index 4579847..2347ec2 100644 --- a/src/commands/call.ts +++ b/src/commands/call.ts @@ -37,6 +37,15 @@ export interface CallOptions { configPath?: string; } +async function writeStdout(text: string): Promise { + await new Promise((resolve, reject) => { + process.stdout.write(`${text}\n`, (error) => { + if (error) reject(error); + else resolve(); + }); + }); +} + /** * Parse target into server and tool name */ @@ -161,9 +170,10 @@ export async function callCommand(options: CallOptions): Promise { try { const result = await connection.callTool(toolName, args); - // Extract text content from MCP response for CLI-friendly output - // Uses formatToolResult which extracts text from MCP content array - console.log(formatToolResult(result)); + // Extract text content from MCP response for CLI-friendly output. + // Write directly to stdout and await the callback so large piped output + // does not get truncated if the process exits immediately afterwards. + await writeStdout(formatToolResult(result)); } catch (error) { // Try to get available tools for better error message let availableTools: string[] | undefined;