[BUG] Streamable HTTP MCP server stays unusable after session expiry (HTTP 404) until manual restart
Maintainer antworten meist innerhalb von 3 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 55/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- typescript
Rechercherichtung
Start in src/services/mcp/McpHub.ts, read callTool() and its existing UnauthorizedError recovery branch, then trace how deleteConnection() and connectToServer() rebuild a connection. Check the Streamable HTTP SDK error type and ensure recovery applies only to a request with an expired session, retries once, and preserves OAuth data. Done means the failed tool call succeeds after a session 404, while a repeated 404 surfaces as an error.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Problem (one or two sentences)
When a stateful Streamable HTTP MCP server restarts or drops its session, Zoo Code keeps sending the old Mcp-Session-Id. The server answers with HTTP 404, and Zoo Code does not start a new session. Every tool call fails until the user clicks Restart in Settings → MCP Servers.
Context (who is affected and when)
This bug affects users who connect Zoo Code to a stateful Streamable HTTP MCP server. It occurs when the server restarts, redeploys, or evicts an idle session. The tool stays in the tool list, so the model keeps calling it and keeps receiving an error. The user must restart the connection by hand after each server restart.
Reproduction steps
- Configure a
streamable-httpMCP server that returns anMcp-Session-Idheader duringinitialize. - Connect Zoo Code to the server. Call one tool. The call succeeds.
- Restart the server process. The old session no longer exists on the server.
- Call the same tool again from a Zoo Code task.
- Observe the error. The MCP panel shows the server as disconnected. The tool is still advertised to the model.
- Open Settings → MCP Servers and click Restart for this server.
- Call the tool again. The call succeeds.
The same sequence occurs without a restart when the server evicts an idle session. Wait for the server's session idle timeout, then call a tool.
Expected result
Zoo Code detects the HTTP 404 for a request that carried an Mcp-Session-Id. Zoo Code starts a new session and retries the failed tool call once. The user does not need to restart the connection.
Actual result
The tool call fails with a Streamable HTTP 404 error. Zoo Code does not reconnect and does not retry. The connection stays unusable until the user clicks Restart in Settings → MCP Servers.
Variations tried (optional)
- Restarting the VS Code window. This works, but it is slower than the Restart button.
- Toggling the server off and on in Settings → MCP Servers. This works.
- Editing the MCP settings file without a config change. This does nothing, because
updateServerConnections()skips servers whose config is unchanged. - Using the
ssetransport instead ofstreamable-http. The SSE transport reconnects automatically throughReconnectingEventSource. The Streamable HTTP transport does not reconnect.
App Version
v3.98.0
API Provider (optional)
Not Applicable / Other
Model Used (optional)
No response
Zoo Code Task Links (optional)
No response
Relevant logs or errors (optional)
Root cause
The MCP specification requires the client to recover from this case. MCP 2025-06-18, Session Management:
When a client receives HTTP 404 in response to a request containing an
Mcp-Session-Id, it MUST start a new session by sending a newInitializeRequestwithout a session ID attached.
Zoo Code does not implement this recovery. Three code paths are involved.
-
The SDK keeps the stale session ID. Zoo Code pins
@modelcontextprotocol/sdk1.32.2. InStreamableHTTPClientTransport.send(),_sessionIdis set only from a successful initialize response. Theif (!response.ok)branch special-cases only 401 and 403. A 404 falls through tothrow new StreamableHTTPError(404, ...). The transport does not clear_sessionIdand does not re-initialize. -
McpHub.callTool()only recovers from 401. Insrc/services/mcp/McpHub.ts,callTool()has a branch forUnauthorizedError. That branch runs the OAuth flow, rebuilds the connection, and retries the call. There is no equivalent branch for a 404 or for a terminated session. -
transport.onclosedoes not reconnect. Forstreamable-http,transport.onclosesetsconnection.server.status = "disconnected"and notifies the webview. It does not rebuild the client or the transport. The SSE branch differs: it usesReconnectingEventSource, so it reconnects on its own.
In addition, getServers() returns all enabled servers regardless of status. The tool therefore stays in the prompt after the session is gone. The model keeps calling a tool that cannot succeed.
Proposed fix
Add a session-expiry branch to callTool(), next to the existing UnauthorizedError branch:
- Catch the error from
connection.client.request(...). - Detect a 404 that belongs to a request with a session ID. With SDK 1.32.2, check
error instanceof StreamableHTTPError && error.code === 404. Do not treat a 404 oninitializeas session expiry. - Call
deleteConnection(name, source). - Call
connectToServer(name, config, source). - Retry the original tool call once. Bound the retry to one attempt, so a repeated 404 still surfaces as an error.
A smaller alternative is to reconnect in transport.onclose with a bounded backoff. That approach also covers the case where no tool call follows the disconnect. The callTool() branch is still needed, because the close event can arrive after the next call starts.
Do not clear OAuth data in this path. restartConnection() currently deletes stored OAuth data for streamable-http servers. A recovery path must not force a new browser login.
Upstream status
The same gap exists in the MCP TypeScript SDK. No fix is merged at the time of this report.
- modelcontextprotocol/typescript-sdk#1476 — original report. Open, labels
bug,P2,ready for work,fix proposed. - modelcontextprotocol/typescript-sdk#3056 — precise analysis. Open, labels
v1andv2. States that no open PR brings 404 re-initialization to v2. - modelcontextprotocol/typescript-sdk#2150 — full re-initialize and retry. Closed, not merged.
- modelcontextprotocol/typescript-sdk#2466 — broader session-ID lifecycle. Withdrawn.
- modelcontextprotocol/typescript-sdk#2660 — minimal fix. Open, label
v2. Clears the stale session ID and throws a distinguishableClientHttpSessionExpired. It does not retry the failed call.
Zoo Code uses the v1 SDK. The open v2 fix will not reach Zoo Code automatically. A Zoo Code-side fix is independent of the SDK migration and works with the current dependency.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 2k
- Forks
- 301
- Ø Merge
- 3 T. 14 Std.
- Gemergte PRs (30 T.)
- 103
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus Zoo-Code-Org/Zoo-Code
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Zoo-Code-Org/Zoo-Code#2773 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Zoo-Code-Org/Zoo-Code#2717 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
Zoo-Code-Org/Zoo-Code#2515 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
fix(scripts): stryker-diff.mjs spawns the extensionless .bin shim and cannot run on WindowsEvtl. vergeben @easonLiangWorldedtech hat das vor 15 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Zoo-Code-Org/Zoo-Code#2514 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
[BUG] search_files hides matching text on long linesEvtl. vergeben @DananjayaNadun hat das vor 9 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
Zoo-Code-Org/Zoo-Code#2496 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 3 Tagen
Alle Issues in Zoo-Code-Org/Zoo-Code
Ähnliche Issues
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
ci
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
ClickHouse/clickhouse-js#1248 ·
Maintainer antworten meist innerhalb von 1 Tag
-
E2E: Darlehen-Test wartet auf die gebuchte Auszahlung, bevor er zur Liquiditätsvorschau wechseltOffentechnik
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
SR5-FoundryVTT/SR5-FoundryVTT#2162 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
AhmedNAgy25/analysor#25 ·
Maintainer antworten meist innerhalb von 1 Tag