Skip to content

mcp: server/discover probe answered with HTTP 500 hard-fails; no legacy fallback despite docs #66101

Description

@johannespfrang-h-d

Summary

Remote MCP servers that answer the server/discover probe with an HTTP 5xx (the common Spring AI / mcp-java response for unimplemented methods) fail to connect with Version negotiation failed: the server answered the probe with HTTP 500. The documented auto-mode "falls back to legacy when the server does not support it" behavior does not trigger, and per the docs the default should be legacy (plain initialize) — yet the client probes by default. A plain initialize handshake against the same server succeeds, so the server is usable.

Environment

  • opencode version: 2.4.1 (install channel: latest; binary updated 2026-11-23 16:19 local time)
  • OS: Darwin 27.2.0 (macOS, arm64)
  • Terminal: TERM_PROGRAM=vscode, TERM=xterm-256color
  • Shell: /bin/zsh (login), bash 5.3.20 in shell config
  • Active plugins: none found in config

Reproduction

  1. Configure a remote MCP server whose implementation has no server/discover handler and surfaces unknown methods as HTTP 500. A live public example: https://mcp.mate-ds.de/mate-mcp (unauthenticated).

    Probe behavior (verifies server health and the failure shape):

    # 500 + "Missing handler for request type: server/discover"
    curl -i -X POST https://mcp.mate-ds.de/mate-mcp \
      -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' \
      -d '{"jsonrpc":"2.0","id":1,"method":"server/discover","params":{}}'
    
    # 200, valid InitializeResult (protocolVersion 2025-06-18) — server works via legacy handshake
    curl -i -X POST https://mcp.mate-ds.de/mate-mcp \
      -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' \
      -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"probe","version":"1.0.0"}}}'
  2. Add to project config (v2 nested form):

    {
      "mcp": {
        "servers": {
          "mate-design-system": {
            "type": "remote",
            "url": "https://mcp.mate-ds.de/mate-mcp",
            "enabled": true
          }
        }
      }
    }
  3. Run opencode mcp list.

Result is consistent, 100% reproducible; reproduces in fresh sessions and fresh opencode serve instances.

Expected Behavior

Per https://opencode.ai/docs/mcp-servers:

  • legacy is the default: "OpenCode opens every server with the classic MCP initialize handshake by default." — the observed default probes with server/discover instead.
  • auto "probes with server/discover … and falls back to legacy when the server does not support it" — an HTTP 500 answer to a method the server does not implement is "does not support it" in practice; no fallback occurs.

The default flip to auto appears intentional (commit bda12b51 updated the schema description accordingly) — the core ask is that a 5xx probe answer triggers the documented "falls back to legacy when the server does not support it" behavior, as #39354 requested for JSON-RPC error answers. Secondary ask: the docs page still describes legacy as the default and should be reconciled with the schema.

Actual Behavior

✗ mate-design-system  failed: Version negotiation failed: the server answered the probe with HTTP 500

Log: three connect attempts (~150 ms apart), then mcp connect failed. No fallback to initialize. Same URL connects fine when protocol: "legacy" is set explicitly (verified: 17 tools listed).

Additional Context

  • Regression commit identified: bda12b51 "feat(mcp): negotiate the newest protocol by default" (feat(mcp): negotiate the newest protocol by default #65282), shipped in v2.4.0 (2026-11-23). It flipped the default to auto (config.protocol ?? "auto") and added auto→legacy fallback for local stdio on ConnectionClosed/EraNegotiationFailed ("Some legacy servers exit on the auto probe's unknown request"), but for remote HTTP the fallback only catches RequestTimeout (unanswered probe). A probe answered with HTTP 5xx falls through as fatal. The remote gap is the same "server does not support it" situation the stdio path already covers.
    • Note: the same commit updated the schema description to "auto" (default), but the docs page (opencode.ai/docs/mcp-servers) still states legacy/initialize is the default.
  • Regression window confirmed: connections with v2.3.2 succeeded until 2026-11-23 12:02 UTC (v2.4.0 released 09:22 UTC); failures began the same evening after updating. The server side never changed (its repository contains no server/discover handler at any revision).
  • Related: v1.18.8 remote MCP fails: server/discover probe rejected by server (-32700), no fallback to classic initialize #39354 (fixed via PR fix(mcp): restore legacy SDK compatibility #39373) made JSON-RPC-error probe answers fall back; HTTP 5xx answers still hard-fail. Many real-world servers answer unknown JSON-RPC methods with 5xx (Spring AI 2.0 WebMvcStatelessServerTransport does), so the fallback rarely gets its "clean" signal. MCP 2026-07-28's own compatibility matrix ("Modern client → Legacy server: Fails") makes these collisions common during the transition.
  • Workaround that works: "protocol": "legacy" in the v2 nested mcp.servers.<name> form — verified connecting (tools=17).
  • Secondary, confusing: the same protocol key is silently dropped when the deprecated flat form "mcp": { "<name>": { … } } is used — connection keeps probing with no warning. Verified by A/B in one process: nested+protocol → connected; flat+protocol → probe 500. At minimum this should warn or error.
  • Also observed: opencode reload re-fires MCP connects but from the stale config snapshot (still probing after a config change was written); a full opencode service restart was needed for some sessions. Additionally, MCP_PROTOCOL_NEGOTIATION=legacy (string present in the binary) had no observable effect on remote connects.

Activity

  1. added
    area/mcp
    type/bug
    version/v2
    on Nov 24, 2026
  2. opencodejr commented on Nov 24, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report. I reproduced this with the released CLI against your public server, with nothing mocked.

    • On 2.4.1, with no protocol set, the server answers the server/discover probe with HTTP 500. opencode mcp list then shows ✗ mate-design-system failed: Version negotiation failed: the server answered the probe with HTTP 500. The service log shows two connect retries and then mcp connect failed, and initialize is never tried.
    • With "protocol": "legacy" the same server shows ✓ connected.
    • On 2.3.2 the same config connects with no protocol set, so this is a regression.
    • It still happens on the latest dev (87dd60cbe), which I ran from source.

    The script below reproduces it. It writes the nested mcp.servers config, runs opencode mcp list and compares the default protocol with legacy. Until this is fixed, the workaround you found ("protocol": "legacy" in the nested mcp.servers.<name> form) works.

    I only tested the main failure, not the flat config form, opencode reload or MCP_PROTOCOL_NEGOTIATION.

    Reproduction script (repro.sh)
    #!/bin/sh
    # Reproduces #66101: a remote MCP server that answers server/discover with HTTP 500
    # fails under the default protocol instead of falling back to legacy `initialize`.
    # Usage: sh repro.sh            (released CLI on PATH)
    #   from source: start "<cli> serve --port 4999" first, then SERVER_ARGS="--server http://127.0.0.1:4999"
    #        OPENCODE="bun --conditions=browser --preload=<repo>/packages/tui/node_modules/@opentui/solid/scripts/preload.js <repo>/packages/cli/src/index.ts" sh repro.sh
    OPENCODE=${OPENCODE:-opencode}
    URL=https://mcp.mate-ds.de/mate-mcp
    echo "--- probe answered by the server:"
    curl -s -o /dev/null -w "server/discover -> HTTP %{http_code}\n" -X POST "$URL" -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' -d '{"jsonrpc":"2.0","id":1,"method":"server/discover","params":{}}'
    for mode in default legacy; do
      dir=$(mktemp -d /tmp/oc-mcp-XXXX); cd "$dir"; git init -q
      if [ "$mode" = default ]; then P=""; else P=', "protocol": "legacy"'; fi
      printf '{ "mcp": { "servers": { "mate-design-system": { "type": "remote", "url": "%s"%s } } } }\n' "$URL" "$P" > opencode.json
      echo "=== protocol: $mode ($(cat opencode.json))"
      $OPENCODE --version
      $OPENCODE mcp list $SERVER_ARGS >/dev/null 2>&1   # first call loads the directory and starts connecting
      sleep 6
      $OPENCODE mcp list $SERVER_ARGS 2>&1
      cd /; rm -rf "$dir"
    done

    Run it: sh repro.sh

  3. ransagy commented on Nov 24, 2026

    @ransagy

    A second failure shape from the same regression, where the probe succeeds and
    the fallback never gets a chance: Railway's hosted MCP (https://mcp.railway.com).

    It answers server/discover with supportedVersions: ["2026-07-28"], so 2.4.1
    commits to the modern revision. It then opens subscriptions/listen, gets the
    ack, and tools/list never returns — 30s startup timeout, mcp connect failed,
    Railway tools dropped from the session. Same server with protocol: "legacy":
    85 tools in ~2.2s.

    Against the Railway proxy, stdin kept open:

    Sequence Result
    initialize + tools/list 85 tools, ~0.7s
    server/discover + tools/list 85 tools, ~0.8s
    server/discover + subscriptions/listen + tools/list no reply

    So the 5xx fallback fixes one case, but auto can also negotiate successfully
    and then fail at catalog time with no path back. Falling back (or retrying
    initialize) when the modern-era catalog fails would cover this one.

    opencode 2.4.1, Railway CLI 5.71.0 and 5.75.0. Filed on the Railway side:
    railwayapp/cli#1376

  4. batestguy commented on Nov 26, 2026

    @batestguy

    Same root cause on a different transport, plus a second trigger that is easy to reproduce — posting in case it narrows the fix down.

    Environment: opencode 2.4.2 (latest, npm @opencode/cli), Windows 11. Two local stdio servers built on the mcp 2.0.0 Python SDK (rmcp 0.11.0 and mcp-server-motherduck 1.1.1) both failed; two older local servers (@upstash/context7-mcp, @playwright/mcp) were unaffected, because they answer server/discover with "method not found" and stay on the legacy path.

    Trigger: the mcp block was still in the v1 flat shape, server names directly under mcp:

    { "mcp": { "rmcp": { "type": "local", "command": ["rmcp", "start"], "protocol": "legacy" } } }

    That shape still launches the server, but the per-server protocol is dropped during normalisation, so the client probes with server/discover even though the documented default is legacy. The tell is opencode debug config: it prints no protocol key for those servers. Moved under the v2 shape ("mcp": { "servers": { ... } }), the identical "protocol": "legacy" is honoured and both servers connect immediately.

    Why it hard-fails instead of falling back: mcp 2.0.0's server runner picks the connection era from the first frame (opens_modern = opening.method != "initialize" and _has_modern_envelope(...)), so the probe locks the connection to 2026-07-28 and the initialize that follows is refused:

    connection is serving the 2026-07-28 protocol; the initialize handshake is not accepted; the server supports 2026-07-28.
    

    Two things that may be worth handling independently of transport:

    1. "protocol" written in the flat shape is silently ignored rather than rejected or warned about. A setting that cannot take effect is worse than an error, because the failure surfaces as a server-side handshake problem.
    2. On the servers that do answer the probe, the reply is logged as Received a response for an unknown message ID: server-discover-probe-1 — the probe reply is not tracked, which may be why the documented fallback does not engage cleanly.

    Workaround for anyone hitting this with local servers: move the block under mcp.servers, set "protocol": "legacy", then confirm with opencode debug config that the key survives, not just that the server starts.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/mcpplatform/macosreproducedtype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions