You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Remote MCP server sent HTTP 404 for resources/templates/list -> treated as dead session, infinite reconnect loop #60583
Reported by user: a remote MCP server oscillates between "connected" and "connecting" forever; tools briefly appear and stop being callable.
Server log trace (~/.local/share/opencode/log/opencode.log):
message="mcp connected" server=X tools=69
message="mcp transport error" server=X error="Error POSTing to endpoint: {\"jsonrpc\": \"2.0\", ... \"code\": -32601, \"message\": \"Method 'resources/templates/list' not found\"} (HTTP 404)"
message="mcp session expired, reconnecting" server=X
message="failed to list MCP resource templates" server=X error="MCP server session expired: X"
Root cause (reproduced with raw curl): the upstream server (mcp.forex-gpt.ai/mcp) returns HTTP status 404 together with a valid JSON-RPC error body (code: -32601, Method not found) for resources/templates/list. Per the MCP spec, method-not-found must be HTTP 200 carrying the JSON-RPC error, so OpenCode should tolerate it; instead OpenCode treats the non-2xx transport status as a dead session (mcp transport error -> session expired, reconnecting) and loops forever.
Two issues, either of which resolves it on its own:
OpenCode: treat HTTP 200 + JSON-RPC -32601 in the body (and arguably any JSON-RPC error body regardless of status) for resources probing as non-fatal; do not reconnect on it. Ideally skip resource discovery when the server's initialize capabilities omitted resources.
Upstream (ForexGPT): return 200 for unsupported methods. That one is theirs, but OpenCode being resilient to it would make mixed-ecosystem MCP servers usable.
Reproduction: opencode mcp add forexgpt --url https://mcp.forex-gpt.ai/mcp (or add remote server in opencode.json), then it flips connected/connecting indefinitely while the server answer for initialize is a perfectly valid 200.
Workaround tested and working: wrap the remote in a local stdio bridge that answers resources/* locally and forwards everything else. So no data loss, but a config shim shouldn't be necessary.
Thanks for the detailed report. I was able to reproduce this on 2.2.1, and it still happens on the latest dev (95fc3c87).
Setup: a local mock MCP server over streamable HTTP. It sends an Mcp-Session-Id on initialize and advertises tools and resources. For resources/templates/list it returns HTTP 404 with a valid JSON-RPC -32601 body. I added it as a remote server and opened the TUI. Within 30 seconds the mock received about 2,700 initialize calls (about 90 reconnects per second), and the log showed the same mcp transport error → mcp session expired, reconnecting → mcp connected cycle you posted.
From the code, it looks like a loop:
On a connection with a session id, any 404 is treated as an expired session, even when the body is a JSON-RPC method-not-found error. So OpenCode reconnects even though a failed templates listing is otherwise ignored.
Each reconnect sends a "resources changed" event.
The client reacts by fetching the resource catalog again, which hits the 404 again.
The script and recording below reproduce it. Your stdio bridge workaround (answering resources/* locally) remains the way around it for now.
recording.mp4Reproduction script (drive.ts)
// Reproduces anomalyco/opencode#60583: a legacy streamable-HTTP MCP server (issues Mcp-Session-Id)// that answers resources/templates/list with HTTP 404 + a JSON-RPC -32601 body makes OpenCode// treat the session as expired and reconnect over and over.import{Effect}from"effect"import{OpenCodeDriver}from"opencode-drive"constcounts: Record<string,number>={}letsessions=0constserver=Bun.serve({port: 0,asyncfetch(req){if(req.method==="GET")returnnewResponse(null,{status: 405})if(req.method==="DELETE")returnnewResponse(null,{status: 200})constmsg: any=awaitreq.json()counts[msg.method]=(counts[msg.method]??0)+1if(msg.id===undefined)returnnewResponse(null,{status: 202})constreply=(result: unknown,headers: Record<string,string>={})=>Response.json({jsonrpc: "2.0",id: msg.id, result },{ headers })switch(msg.method){case"initialize":
sessions++returnreply({protocolVersion: msg.params?.protocolVersion??"2025-03-26",capabilities: {tools: {},resources: {}},serverInfo: {name: "mock",version: "1.0.0"},},{"Mcp-Session-Id": `session-${sessions}`},)case"tools/list":
returnreply({tools: [{name: "echo",description: "echo",inputSchema: {type: "object",properties: {}}}]})case"resources/list":
returnreply({resources: []})default:
// Non-compliant but real-world: HTTP 404 carrying a valid JSON-RPC "method not found" error.returnResponse.json({jsonrpc: "2.0",id: msg.id,error: {code: -32601,message: `Method '${msg.method}' not found`}},{status: 404},)}},})exportdefaultOpenCodeDriver.use({
...(process.env.OC_DEV ? {opencode: {dev: process.env.OC_DEV}} : {}),tui: {recording: true},config: {mcp: {servers: {mock: {type: "remote",url: `http://127.0.0.1:${server.port}/mcp`}}}}asany,},({ ui })=>Effect.gen(function*(){yield*ui.screenshot("start")for(leti=1;i<=6;i++){yield*Effect.sleep("5 seconds")yield*Effect.log(`t=${i*5}s sessions(initialize)=${sessions} counts=${JSON.stringify(counts)}`)}yield*ui.screenshot("after-30s")yield*Effect.log(`FINAL initialize calls: ${sessions} (1 expected for a stable connection)`)}),)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
I reproduced this on dev@8b4d98c. I'd like to take it.
I'll start with a failing regression test: a mock streamable-HTTP MCP server with a session id that returns HTTP 404 plus a JSON-RPC -32601 body for resources/templates/list, then assert a single initialize and a live session. Fix direction: classify method-not-found separately from session expiry so the catalog can ignore the unsupported method without reconnecting.
Additional reproduction on OpenCode v2.2.5 (Linux), with the TinyFish remote MCP:
The MCP stays connected and advertises 44 tools; tools/list discovery appears healthy.
For resources/templates/list, the server returns HTTP 400 carrying JSON-RPC error.code = -32601 (Method not found: resources/templates/list).
OpenCode logs both mcp transport error and failed to list MCP resource templates; repeated resource-catalog reads across multiple workspace locations reproduce these warnings.
Unlike the original HTTP 404/session-expiration reproduction here, I have not established a reconnect loop for TinyFish's HTTP 400 case.
Changing mcp.servers.tinyfish.codemode to false does not resolve this behavior; the original setting was restored.
No OAuth secrets were extracted or modified, and the production executable remains the official build.
Suggested narrow client fix: when probing the optional resources/templates/list method, recognize JSON-RPC -32601 (including when enclosed in HTTP 400/404), return an empty template list, and cache that capability as unsupported for the life of the current MCP connection. Reset on reconnect. Preserve resources/list, tools/list, tools/call, supported template lists, OAuth, and other errors such as 401, 429 or non--32601 failures.
I prepared a version-specific source patch and ran 9 synthetic regression cases, but have not run the upstream full test suite or deployed a custom build. Please include HTTP 400 in regression coverage alongside the HTTP 404/session-id case described in this issue.
Activity
opencodejr commentedon Oct 30, 2026
Thanks for the detailed report. I was able to reproduce this on 2.2.1, and it still happens on the latest
dev(95fc3c87).Setup: a local mock MCP server over streamable HTTP. It sends an
Mcp-Session-Idoninitializeand advertisestoolsandresources. Forresources/templates/listit returns HTTP 404 with a valid JSON-RPC-32601body. I added it as a remote server and opened the TUI. Within 30 seconds the mock received about 2,700initializecalls (about 90 reconnects per second), and the log showed the samemcp transport error→mcp session expired, reconnecting→mcp connectedcycle you posted.From the code, it looks like a loop:
The script and recording below reproduce it. Your stdio bridge workaround (answering
resources/*locally) remains the way around it for now.recording.mp4
Reproduction script (drive.ts)
Run it with opencode-drive:
opencode-drive run ./drive.ts. It drivesopencodefrom yourPATH; setOC_DEVto the path of an OpenCode checkout to run that from source instead.Vaili commentedon Oct 31, 2026
I reproduced this on
dev@8b4d98c. I'd like to take it.I'll start with a failing regression test: a mock streamable-HTTP MCP server with a session id that returns HTTP 404 plus a JSON-RPC
-32601body forresources/templates/list, then assert a singleinitializeand a live session. Fix direction: classify method-not-found separately from session expiry so the catalog can ignore the unsupported method without reconnecting.Vaili commentedon Oct 31, 2026
.
nattapon00123 commentedon Oct 31, 2026
Additional reproduction on OpenCode v2.2.5 (Linux), with the TinyFish remote MCP:
tools/listdiscovery appears healthy.resources/templates/list, the server returns HTTP 400 carrying JSON-RPCerror.code = -32601(Method not found: resources/templates/list).mcp transport errorandfailed to list MCP resource templates; repeated resource-catalog reads across multiple workspace locations reproduce these warnings.mcp.servers.tinyfish.codemodetofalsedoes not resolve this behavior; the original setting was restored.Suggested narrow client fix: when probing the optional
resources/templates/listmethod, recognize JSON-RPC-32601(including when enclosed in HTTP 400/404), return an empty template list, and cache that capability as unsupported for the life of the current MCP connection. Reset on reconnect. Preserveresources/list,tools/list,tools/call, supported template lists, OAuth, and other errors such as 401, 429 or non--32601failures.I prepared a version-specific source patch and ran 9 synthetic regression cases, but have not run the upstream full test suite or deployed a custom build. Please include HTTP 400 in regression coverage alongside the HTTP 404/session-id case described in this issue.