Skip to content

[Bug]: Unguarded output.output access in tool.execute.after hooks crashes all MCP tools #1746

@code-yeongyu

Description

@code-yeongyu

Bug

All external MCP tools crash with TypeError: undefined is not an object (evaluating 'output.output.toLowerCase') since v3.5.0 (and v3.4.1 before it was yanked). Built-in tools (bash, read, write, grep) are unaffected.

Root Cause

Three tool.execute.after hooks access output.output without null/type guards:

File Line Code
src/hooks/comment-checker/hook.ts L95 const outputLower = output.output.toLowerCase()
src/hooks/edit-error-recovery/hook.ts L47 const outputLower = output.output.toLowerCase()
src/hooks/task-resume-info/hook.ts L24-31 output.output.startsWith(), .includes(), .trimEnd()

All three hooks declare output as { title: string; output: string; metadata: unknown }, but for MCP tool results, output.output is undefined.

Contributing upstream factor: AI SDK v6.0.74 changed tool result structure from {output, metadata, title} to {type, value} via createToolModelOutput() in stream-text.ts. This means output.output is now always undefined for MCP tools. See anomalyco/opencode#13042, anomalyco/opencode#12987.

Why v3.5.0 and v3.5.1 still have this

v3.4.1 was yanked for this exact issue, but the hook source code was never patched. v3.5.0 and v3.5.1 shipped with the same unguarded calls.

Workaround

"disabled_hooks": ["comment-checker"]

Or downgrade to v3.4.0 with "auto_update": false.

Suggested Fix

Add null/type guard at the top of each tool.execute.after handler:

if (!output.output || typeof output.output !== "string") return

This single line in each of the three hooks would prevent the crash.

Related

Affected Versions

  • v3.4.1 (yanked)
  • v3.5.0
  • v3.5.1

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions