Skip to content

Consume server-side session-expired envelope to auto-reinitialize mid-session #10

Description

@miguelglopes

Context

The remote MCP server now rewrites rmcp's plaintext 404 (Not Found: Session not found) into a structured JSON-RPC error envelope when a request carries an mcp-session-id header that the server has dropped (keep-alive timeout, replica restart, OOM, drain rehash). Source: OutSystems/mcp-server-remote#65.

Today the TypeScript MCP SDK that this plugin / Power uses does not inspect 404 bodies, so users still see Streamable HTTP error: ... Not Found: Session not found and must /mcp reconnect manually. The server change is a producer-side preposition — this issue tracks the consumer side that makes it actually recoverable.

Wire shape

HTTP/1.1 404 Not Found
Content-Type: application/json

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32003,
    "message": "Session expired; reinitialize",
    "data": {
      "reason": "session_expired",
      "resume": {
        "method": "mentor_start",
        "via": "mentor_session_token"
      }
    }
  },
  "id": null
}

Detection rule on the client: status == 404 && body.error.code == -32003. Equivalent: body.error.data.reason == "session_expired".

Asks

  1. Intercept the 404 response, parse the envelope.
  2. On match, run a transparent reinitialize (new mcp-session-id) instead of bubbling the transport error.
  3. If a mentor_session_token from the most recent terminal mentor_get_run.result is in scope, follow the resume.via hint and re-issue the current mentor turn via mentor_start with the resume token. The server now keeps that token valid through the entire MCP_SESSION_INACTIVITY_SECS window (+10 min buffer), so it won't 401 on the resume.
  4. Surface a single subtle UX cue ("reconnected"); don't tear down the conversation.

Out of scope

  • Changing the wire shape (server-side decision).
  • Re-architecting the SDK transport layer for general 404 handling — this is a targeted carve-out for the -32003 envelope only.

Links

  • Server PR: OutSystems/mcp-server-remote#65

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