Skip to content

Web search fails when an MCP server sends a notification before the response #61887

Done

Description

@tyler5673

Description

WebSearchMcp.parseResponse() decodes every SSE data: field as { result } and fails on the first one that isn't. The MCP Streamable HTTP transport lets a server send JSON-RPC notifications and requests before the response ("The server MAY send JSON-RPC requests and notifications before sending a JSON-RPC response", 2025-03-26 transports), so a logging or progress notification ahead of the result makes the whole web search fail with Missing key at ["result"].

None of the bundled providers send these today (Exa and Firecrawl reply with a single SSE event, Parallel and TinyFish with plain JSON), so this doesn't affect current users. It does block any MCP search server that uses logging or progress notifications.

Disclosure: I work at You.com. We found this while looking at adding You.com as a web search provider. Our MCP server sends a logging notification before each search result.

Plugins

Built-in web search (any MCP-backed provider)

OpenCode version

Current dev (6469454)

Steps to reproduce

From packages/core, run with Bun:

import { Effect, Schema } from "effect"
import { WebSearchMcp } from "@opencode/core/plugin/websearch/mcp"

const output = Schema.Struct({ content: Schema.Array(Schema.Struct({ text: Schema.String })) })
const body = [
  'event: message\ndata: {"jsonrpc":"2.0","method":"notifications/message","params":{"level":"info","data":"Searching"}}\n\n',
  'event: message\ndata: {"jsonrpc":"2.0","id":1,"result":{"content":[{"text":"search result"}]}}\n\n',
].join("")
console.log(await Effect.runPromise(WebSearchMcp.parseResponse(body, output)))

Observed: fails with Missing key at ["result"]. Expected: { content: [{ text: "search result" }] }. Removing the notification event makes the same payload succeed.

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. opencodejr commented on Nov 5, 2026

    @opencodejr
    Contributor

    Thanks for the clear report. I reproduced this on the latest dev (e38c009) by calling WebSearchMcp.parseResponse directly. With only the result event, it returns {"content":[{"text":"search result"}]}. With a notifications/message event before the same result, it fails with Missing key at ["result"]. The script below shows both cases.

    Related:

    Reproduction script (repro.ts)
    // Copy into packages/core of an opencode checkout (after bun install) and run: bun ./repro.ts
    import { Effect, Schema } from "effect"
    import { WebSearchMcp } from "@opencode/core/plugin/websearch/mcp"
    
    const output = Schema.Struct({ content: Schema.Array(Schema.Struct({ text: Schema.String })) })
    const result = 'event: message\ndata: {"jsonrpc":"2.0","id":1,"result":{"content":[{"text":"search result"}]}}\n\n'
    const notification =
      'event: message\ndata: {"jsonrpc":"2.0","method":"notifications/message","params":{"level":"info","data":"Searching"}}\n\n'
    
    for (const [name, body] of [
      ["result only", result],
      ["notification then result", notification + result],
    ] as const) {
      const exit = await Effect.runPromiseExit(WebSearchMcp.parseResponse(body, output))
      console.log(name, "=>", exit._tag === "Success" ? JSON.stringify(exit.value) : String(exit.cause))
    }

    Run it: bun repro.ts

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions