Skip to content

McpServer.layerHttpRouter emits JSON-RPC batches (arrays) over HTTP — breaks MCP 2025-06-18 Streamable HTTP clients (Claude Desktop/Code) #6274

Closed

Description

@milkyskies

What version of @effect/ai are you using?

@effect/[email protected] (also present on 0.36.0 / main), [email protected], @effect/[email protected], @effect/[email protected], runtime Bun 1.2.x.

What's the problem?

McpServer.layerHttpRouter (and layerHttp) serve MCP over Effect's generic JSON-RPC RPC protocol (RpcServer.layerProtocolHttpRouter + RpcSerialization.layerJsonRpc). At the HTTP wire level this diverges from the MCP Streamable HTTP transport in three ways, and the first one causes spec-conformant clients (e.g. Claude Desktop, Claude Code) to reject the endpoint outright with "Couldn't connect to the server / not a valid MCP server":

  1. Responses are JSON-RPC batches (arrays). A single request gets a single-element array back. MCP 2025-06-18 removed JSON-RPC batching (spec changelog — "Remove support for JSON-RPC batching"), so a client built to that revision expects a single response object and chokes on the array.
  2. No Mcp-Session-Id response header is returned on initialize, so the session lifecycle can't be established by clients that rely on it.
  3. GET /mcp returns 404 rather than opening an SSE stream or returning 405 Method Not Allowed, so the optional server→client stream is indistinguishable from "endpoint doesn't exist."

Reproduction

A minimal server using McpServer.layerHttpRouter({ name, version, path: "/mcp" }) on port 3000, then:

curl -s -i -X POST http://localhost:3000/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":"0"}}}'

Actual response:

HTTP/1.1 200 OK
content-type: application/json
(no Mcp-Session-Id header)

[{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2024-11-05","capabilities":{...},"serverInfo":{...}}}]

…and curl -i http://localhost:3000/mcp (GET) → HTTP/1.1 404.

Expected behavior

Per the 2025-06-18 Streamable HTTP transport:

  • A POST carrying a single JSON-RPC request returns a single JSON-RPC response object ({ ... }), not a one-element array, when responding with Content-Type: application/json.
  • initialize returns an Mcp-Session-Id header when the server is stateful.
  • GET either opens a text/event-stream or returns 405, not 404.

Activity

  1. Ben-Home commented on Jun 14, 2026

    @Ben-Home

    Great catch on the JSON-RPC batch divergence. This is a clear spec compliance issue — MCP 2025-06-18 explicitly removed JSON-RPC batching, and Claude Desktop/Code enforce this strictly.

    The root cause in Effect's stack:

    RpcSerialization.layerJsonRpc implements generic JSON-RPC 2.0 semantics, where batching is valid. But MCP runs a subset of JSON-RPC — no batching, no notifications for requests, and explicit session management via Mcp-Session-Id. When McpServer.layerHttpRouter delegates to the generic RPC layer without a transport-specific serialization mode, the batch wrapper leaks through.

    Where to fix it:

    The cleanest approach is adding an MCP-specific serialization layer that wraps RpcSerialization.layerJsonRpc but unwraps single-element arrays at the boundary:

    // In @effect/ai/src/McpServer.ts or similar:
    const McpSerialization = RpcSerialization.layerJsonRpc.pipe(
      Layer.map(serialization => ({
        ...serialization,
        // Unwrap single-element batches for MCP compliance
        encode: (response) => {
          const encoded = serialization.encode(response);
          if (Array.isArray(encoded) && encoded.length === 1) return encoded[0];
          return encoded;
        }
      }))
    );
    

    The other two issues you flagged (missing Mcp-Session-Id header, non-standard endpoint path) will also block Claude clients — the session ID is required after initialize for stateful transports. Worth fixing all three in one pass since they're all in the HTTP transport layer.

    This tripped us up building MCP servers at corpusiq.io too — we added a pre-flight validation that checks response shape against the spec revision before deploying any transport change.

  2. milkyskies commented on Jun 16, 2026

    @milkyskies
    ContributorAuthor

    @Ben-Home
    Oh wow, thank you!

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions