fix(opencode): show MCP tool output in non-interactive run mode#14525
Open
GBA63 wants to merge 1 commit intoanomalyco:devfrom
Open
fix(opencode): show MCP tool output in non-interactive run mode#14525GBA63 wants to merge 1 commit intoanomalyco:devfrom
GBA63 wants to merge 1 commit intoanomalyco:devfrom
Conversation
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 <noreply@anthropic.com>
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Author
|
Re: typecheck CI failure The The errors come from a turbo cache miss: since
Other open PRs pass because they get a turbo cache hit for the Our changes pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #6604
Closes #13946
Type of change
What does this PR do?
Two fixes in
packages/opencode/src/cli/cmd/run.ts:1. MCP tool output not shown: The
fallback()handler (used for all MCP tools) only displayed tool name + input JSON viainline(). It never readpart.state.output. Changed to extract output with a runtime type check and display viablock()— same pattern as the existingbash()handler.2. Race condition — premature exit:
loop()was started fire-and-forget while the handler returned right aftersdk.session.prompt()completed its HTTP request. The process could exit before the LLM finished generating. Fixed by storing the loop promise and awaiting it after prompt/command.How did you verify your code works?
bunx tsc --noEmit)bun dev runwith MCP tools (filesystem server) — output now appears@opencode-ai/enterprise(unrelatedcustom-elements.d.tserror on dev branch)Screenshots / recordings
CLI change, no UI affected.
Checklist