Skip to content

[MCP Stateless] Slice B-2: Stateless request routing — skip initialize, add _meta inline + server/discover #1512

Description

@Lexus2016

Parent: #1287 (Slice B decomposition)

This is Slice B-2 of the MCP 2026-07-28 stateless migration. Depends on #1511 (B-1: capability flag + synthesize_capabilities).

Scope (this issue — ≤200 lines)

Add the stateless request path that bypasses the initialize/initialized handshake and routes requests with inline _meta routing context. This is the core behavioral change — the 4 session.initialize() sites and 11 dispatch sites get a flag-gated alternative path.

Specific changes

  1. Skip session.initialize() for stateless servers (4 sites): gate each behind if self._stateless_enabled and self._is_stateless_server: — synthesize the session instead of calling the handshake.

    • Line 2426 (stdio transport)
    • Line 2732 (SSE transport)
    • Line 2789 (streamable_http, new API)
    • Line 2821 (streamablehttp, deprecated API)
  2. server/discover RPC: add a method that calls the new server/discover RPC (introduced in the finalized spec) to obtain server capabilities without a session. This replaces the information previously obtained from the initialize handshake response.

  3. Inline _meta routing: when sending RPCs in stateless mode, embed routing context (Mcp-Method, Mcp-Name) as inline _meta in the request body instead of relying on a pinned session. Cover the critical hot path: call_tool (audit line ~4263).

  4. _get_session_id sites (2 sites): in stateless mode, these should return None / skip the session-id header entirely (SEP-2567 removes Mcp-Session-Id).

Call sites (from Slice A audit)

Group Lines Count
session.initialize() 2426, 2732, 2789, 2821 4
self.session.* dispatches ~4263 (call_tool) + 10 others 11
_get_session_id 2 sites 2
Total 17

What this issue does NOT do

Success criteria

  • session.initialize() is skipped for stateless-flagged servers (4 sites gated)
  • server/discover RPC call implemented and returns capabilities
  • call_tool hot path routes via _meta inline when stateless
  • _get_session_id returns None in stateless mode (2 sites)
  • Existing stateful path fully functional when flag is OFF
  • Fits ≤200-line self-merge cap

Dependencies

Audit reference

Full call-site map: docs/mcp/2026-07-28-stateless-migration-audit.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmcpMCP adapter / protocolneeds-splitWanted, but exceeds one cycle — needs decompositionresearch-drivenCreated by the evolution research cycle

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions