From 1bc98baab9482397ff9de51a5406e21ba8465a22 Mon Sep 17 00:00:00 2001 From: Gerhard Baumeister Date: Sat, 21 Feb 2026 06:29:10 +0100 Subject: [PATCH] fix(opencode): show MCP tool output in non-interactive run mode The fallback() handler for MCP tools in `opencode run` only displayed the tool name and input JSON via inline(), but never showed tool results. This changes it to use block() with the tool output, matching the existing bash() handler pattern. Also fixes a race condition where the event loop was fire-and-forget (loop().catch(...)) while the handler returned after sdk.session.prompt() completed its HTTP request. This caused the process to exit before the LLM finished generating, losing tool results and the final text response. The loop promise is now properly awaited. Fixes #6604, #13946 Co-Authored-By: Claude Opus 4.6 --- packages/opencode/src/cli/cmd/run.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/opencode/src/cli/cmd/run.ts b/packages/opencode/src/cli/cmd/run.ts index f3781f1abd86..29ed47c210ac 100644 --- a/packages/opencode/src/cli/cmd/run.ts +++ b/packages/opencode/src/cli/cmd/run.ts @@ -68,10 +68,15 @@ function fallback(part: ToolPart) { const title = ("title" in state && state.title ? state.title : undefined) || (input && typeof input === "object" && Object.keys(input).length > 0 ? JSON.stringify(input) : "Unknown") - inline({ - icon: "⚙", - title: `${part.tool} ${title}`, - }) + const raw = state.status === "completed" && "output" in state ? state.output : undefined + const output = typeof raw === "string" ? raw.trim() : undefined + block( + { + icon: "⚙", + title: `${part.tool} ${title}`, + }, + output, + ) } function glob(info: ToolProps) { @@ -582,7 +587,7 @@ export const RunCommand = cmd({ } await share(sdk, sessionID) - loop().catch((e) => { + const loopPromise = loop().catch((e) => { console.error(e) process.exit(1) }) @@ -606,6 +611,8 @@ export const RunCommand = cmd({ parts: [...files, { type: "text", text: message }], }) } + + await loopPromise } if (args.attach) {