eca icon indicating copy to clipboard operation
eca copied to clipboard

MCP Streamable HTTP client fails against Z.AI web_search_prime gateway: initialize times out (SSE parsing)

Open qwota opened this issue 2 months ago • 3 comments

Describe the bug

Connecting to Z.AI's hosted MCP server (https://api.z.ai/api/mcp/web_search_prime/mcp) configured via url + headers always fails: initialize never resolves and the server ends up failed after the 60s timeout. The endpoint itself is fine — the same POST succeeds via curl, and the server connects through the mcp-remote stdio bridge.

The failure comes from the bundled MCP HTTP client (plumcp) rejecting the gateway's SSE encoding. The server sends valid SSE:

id:1
event:message
data:{"jsonrpc":"2.0","id":1,"result":{...}}

but plumcp only accepts chunks whose first line is exactly event: message. The unparseable event then surfaces as a non-JSON-RPC "message" {:mcp-session-id "..."} ((assoc nil :mcp-session-id ...)), the reader thread dies, and the pending initialize future hangs until timeout.

To Reproduce

  1. Add to config:
"mcpServers": {
  "web-search-prime": {
    "url": "https://api.z.ai/api/mcp/web_search_prime/mcp",
    "headers": { "Authorization": "Bearer <REDACTED>" }
  }
}
  1. Start ECA, wait ~60s.
  2. Log shows:
INFO  [MCP] Creating HTTP transport for server 'web-search-prime' at https://api.z.ai/api/mcp/web_search_prime/mcp
Exception in thread "" clojure.lang.ExceptionInfo: Expected JSON-RPC message to be a request, notification or response {:found {:mcp-session-id "..."}}
    at plumcp.core.client.http_client_transport$make_streamable_http_transport$receive_msg.invoke(http_client_transport.cljc:86)
    at plumcp.core.support.http_client_java$make_ring_response$on_sse.invoke(http_client_java.clj:208)
ERROR [MCP] Could not initialize MCP server web-search-prime: MCP initialize returned no result
  1. Sanity checks (both succeed, so the server is healthy):
    • curl -i -X POST <url> -H "Authorization: Bearer <key>" -H "Accept: text/event-stream, application/json" -H "Content-Type: application/json" -d '{...initialize...}' → 200 + valid JSON-RPC result.
    • npx -y mcp-remote <url> --header "Authorization: Bearer <key>" → connects, tools work.

Expected behavior

Server starts and its tools are listed.

Doctor

ECA server: 0.158.1, OS: Windows 11, Java: 24.0.2, client: emacs
MCP: web-search-prime — failed, 0 tools

Additional context

  • Root cause lives upstream in plumcp (parse-sse-event-lines requires event: message with a space as the first chunk line; SSE spec says the space is optional and field order is free). Happy to file details there too. https://github.com/plumce/plumcp/issues/12
  • Working workaround for now: stdio bridge. Note for Windows: "command": "npx" fails with CreateProcess error=2, npx.cmd is required.
"web-search-prime": {
  "command": "npx.cmd",
  "args": [
    "-y", "mcp-remote",
    "https://api.z.ai/api/mcp/web_search_prime/mcp",
    "--header", "Authorization: Bearer <REDACTED>"
  ]
}

qwota avatar Sep 07 '26 13:09 qwota

The related bug in PluMCP https://github.com/plumce/plumcp/issues/12 is now fixed and released as version 0.2.3.

kumarshantanu avatar Sep 13 '26 04:09 kumarshantanu

Will bump, thank you!

ericdallo avatar Sep 14 '26 17:09 ericdallo

Checked → it works!

qwota avatar Sep 15 '26 07:09 qwota