Skip to content

Comments

fix(opencode): show MCP tool output in non-interactive run mode#14525

Open
GBA63 wants to merge 1 commit intoanomalyco:devfrom
GBA63:fix/mcp-tool-output-in-run
Open

fix(opencode): show MCP tool output in non-interactive run mode#14525
GBA63 wants to merge 1 commit intoanomalyco:devfrom
GBA63:fix/mcp-tool-output-in-run

Conversation

@GBA63
Copy link

@GBA63 GBA63 commented Feb 21, 2026

Issue for this PR

Closes #6604
Closes #13946

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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 via inline(). It never read part.state.output. Changed to extract output with a runtime type check and display via block() — same pattern as the existing bash() handler.

2. Race condition — premature exit: loop() was started fire-and-forget while the handler returned right after sdk.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?

  • TypeScript typecheck passes for the opencode package (bunx tsc --noEmit)
  • Tested bun dev run with MCP tools (filesystem server) — output now appears
  • Tested plain knowledge questions — no regression
  • Note: CI typecheck failure is pre-existing in @opencode-ai/enterprise (unrelated custom-elements.d.ts error on dev branch)

Screenshots / recordings

CLI change, no UI affected.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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>
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Feb 21, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@GBA63
Copy link
Author

GBA63 commented Feb 21, 2026

Re: typecheck CI failure

The tsgo --noEmit failure is not caused by this PR. Our change only touches fallback() and the loopPromise pattern in run.ts.

The errors come from a turbo cache miss: since run.ts changed, turbo re-runs typecheck for the entire opencode package, which exposes pre-existing noImplicitAny errors in:

  • src/acp/agent.ts (40+ errors — Parameter 'x' implicitly has an 'any' type)
  • src/acp/session.ts (2 errors)
  • src/cli/cmd/tui/ (multiple files)
  • src/cli/cmd/run.ts lines 382, 400 (pre-existing, not touched by this PR)

Other open PRs pass because they get a turbo cache hit for the opencode package typecheck.

Our changes pass tsc --noEmit and tsgo --noEmit for the code we modified. Happy to rebase if this gets resolved on dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: opencode run exits after compaction when compaction model's token usage exceeds overflow threshold [FEATURE]: MCP Tool Output

1 participant