Skip to content

fix: normalize MCP tool results - #31

Merged
bezbac merged 4 commits into
langfuse:mainfrom
Azther0z:fix/mcp-tool-results
Aug 20, 2026
Merged

bezbac merged 4 commits into
langfuse:mainfrom
Azther0z:fix/mcp-tool-results

Conversation

@Azther0z

@Azther0z Azther0z commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes issue #22, where MCP tool results were exported as {}.

OpenCode supplies different result shapes:

  • Native tools: { title, output, metadata, attachments }
  • MCP tools: { content: [...] }

The hook now normalizes these shapes:

  • Native tool behavior remains unchanged.
  • MCP text content is flattened into the recorded output.
  • MCP results without a title use the tool name.
  • Missing results remain empty.
  • Unexpected non-null shapes produce a warning and are recorded as empty output rather than guessed at.

For example, a standard MCP text part such as
{ type: "text", text: "Search result" } is recorded as
"Search result". Non-text parts are represented by markers such as
"[image]" or "[resource]", matching the content-part types handled by
OpenCode's MCP tool processing.

Verification

  • pnpm install
  • pnpm run format
  • pnpm run build
  • pnpm run test:integration
  • 14 integration tests passed

Fixes: #22
Assisted-by: OpenCode

@CLAassistant

CLAassistant commented Aug 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Azther0z Azther0z closed this Aug 19, 2026
@Azther0z
Azther0z deleted the fix/mcp-tool-results branch August 19, 2026 14:21
@Azther0z
Azther0z restored the fix/mcp-tool-results branch August 19, 2026 14:21
@Azther0z Azther0z reopened this Aug 19, 2026
Handle native and MCP result shapes explicitly and warn when a non-null result is unrecognized.

Refs: langfuse#22
@bezbac
bezbac merged commit 491508a into langfuse:main Aug 20, 2026
3 checks passed
@bezbac

bezbac commented Aug 20, 2026

Copy link
Copy Markdown
Member

Thanks for the PR @Azther0z!

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.

MCP tool results are collected as empty {}

3 participants