Skip to content

Commit 1bc98ba

Browse files
GBA63claude
andcommitted
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 anomalyco#6604, anomalyco#13946 Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 206d81e commit 1bc98ba

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

  • packages/opencode/src/cli/cmd

‎packages/opencode/src/cli/cmd/run.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@ function fallback(part: ToolPart) {
6868
const title =
6969
("title" in state && state.title ? state.title : undefined) ||
7070
(input && typeof input === "object" && Object.keys(input).length > 0 ? JSON.stringify(input) : "Unknown")
71-
inline({
72-
icon: "⚙",
73-
title: `${part.tool} ${title}`,
74-
})
71+
const raw = state.status === "completed" && "output" in state ? state.output : undefined
72+
const output = typeof raw === "string" ? raw.trim() : undefined
73+
block(
74+
{
75+
icon: "⚙",
76+
title: `${part.tool} ${title}`,
77+
},
78+
output,
79+
)
7580
}
7681

7782
function glob(info: ToolProps<typeof GlobTool>) {
@@ -582,7 +587,7 @@ export const RunCommand = cmd({
582587
}
583588
await share(sdk, sessionID)
584589

585-
loop().catch((e) => {
590+
const loopPromise = loop().catch((e) => {
586591
console.error(e)
587592
process.exit(1)
588593
})
@@ -606,6 +611,8 @@ export const RunCommand = cmd({
606611
parts: [...files, { type: "text", text: message }],
607612
})
608613
}
614+
615+
await loopPromise
609616
}
610617

611618
if (args.attach) {

0 commit comments

Comments
 (0)