Skip to content
Agent Field Notes
Course contentsExpand a topic to choose a lesson.

SYSTEMATIC LEARNING / FOUR-LEVEL COURSE

MCP reconnection across protocol versions and business outcomes

Compare MCP 2025-11-25 and 2026-07-28; preserve the legacy fixture while designing stateless requests, task handles and safe write reconciliation.

Learning objectives: Choose recovery from a pinned protocol version and trusted send/outcome evidence. Keep cancellation, request correlation and delivery separate from durable business idempotency.

Content checked: 2026-10-30 · Each level has independent explanations, tasks and inspections

Choose a starting point based on your familiarity with this topic. Current level: Implementation · Build it. After completing the task, continue to the next level. Reading and self-checks alone do not establish mastery.

On this level

Review the prerequisites

Suitable for: Backend developers learning Agent applications.

Protocol era
Legacy initialization/session semantics and modern per-request semantics are separate adapters.
Unknown outcome
A sent write lacks a verified final business result; cancellation or reconnection alone cannot resolve it.
Task handle
An opted-in Tasks extension identifier locates asynchronous work; creation still needs business deduplication.

How does the mechanism work?

Step-by-step explanation
  1. Select the era before recovering

    2025-11-25 can use initialized sessions and optional replay; 2026-07-28 uses per-request metadata and has no Last-Event-ID replay.

  2. Cancellation cannot undo commit

    Modern HTTP SSE close cancels the request, but an already committed action still needs receipt reconciliation.

  3. Extensions have their own contracts

    Tasks is opt-in; core stateless capability declarations do not erase extension lifecycle requirements.

Implementation · Build it

Implement the legacy fixture and the adapter boundary

Objectives of this level: Reproduce the unchanged 13-case contract and specify modern detection separately.

Visual guide · Three identities, three jobs

Three identities, three jobs

Optional transport resumption restores messages only. An unknown sent write still needs same-operation reconciliation; a new session cannot prove noncommit. Select the figure to open it at full size.

Implement the preserved legacy decision fixture

The public 13-case fixture is pinned to a 2025-11-25-style eligibility model, not a 2026-07-28 server, SDK client, OAuth integration or live SSE replay. Its fields intentionally include legacy session IDs and cursors. Do not “update” the function by silently accepting modern traffic: a production adapter must select the era before calling any era-specific policy.

Use Python 3.9+ standard library. Extract the source package and keep lab_runner.py beside cases/. The scaffold refuses overwrites. These existing public assets and their contract are unchanged:

  • https://ai.lwkjob.com/lab/extended-practice/README.md
  • https://ai.lwkjob.com/lab/extended-practice/lab_runner.py
  • https://ai.lwkjob.com/lab/extended-practice/cases/mcp-transport-reconnect.json
  • https://ai.lwkjob.com/downloads/extended-agent-practice-v1.zip
python3 lab_runner.py scaffold --course mcp-transport-reconnect --out reconnect_decision_student.py
python3 lab_runner.py grade --course mcp-transport-reconnect --module reconnect_decision_student.py --out mcp-transport-reconnect-report.json
def reconnect_decision(payload):
    """Implement the public contract; disclose assistance used."""
    raise NotImplementedError("mcp-transport-reconnect")

Exact public function contract

reconnect_decision(payload) accepts exactly: transport (stdio/streamable_http), phase (before_send/after_send/after_response), operation (read/write), session_id/new_session_id/last_event_id/operation_key (null or nonempty string), and resume_supported (strict bool). Validate shape first with ValueError("input_shape"). A write without operation_key raises ValueError("write_key"). In this local contract, stdio must not carry HTTP session IDs, an event cursor or true resume_supported; otherwise raise ValueError("transport_metadata").

Evaluate in order: after_response → accept/response_received; before_send → retry/not_sent; after_send + streamable_http + equal non-null session IDs + resume_supported=True + non-null cursor → resume/stream_cursor. Otherwise read → retry/read_replay and write → reconcile/write_result_unknown. Return exactly action, reason, unchanged operation_key, and last_event_id (original only for resume, null otherwise). Never mutate input or return dict/list aliases to it. The phase, support flag and cursor association are trusted adapter inputs, not facts guessed from a broken connection.

Keep the modern adapter separate

The following pseudocode shows era detection, not a tested implementation. A recognized modern error is evidence of a modern peer even when HTTP status is 400; do not route it through initialize. A modern request needs required _meta on every call, plus mirrored HTTP version/method/name headers where applicable. Header/body mismatch must fail before execution.

# Design pseudocode, not an executable MCP client.
probe = safe_discovery_probe(transport, preferred_version="2026-07-28")
if probe.is_discover_result:
    era = "modern"
    version = choose_mutual(probe.supportedVersions)
elif probe.is_recognized_modern_error:
    era = "modern"  # HeaderMismatch and missing capabilities are not legacy evidence.
    version = correct_request_or_choose_mutual(probe)
elif transport == "stdio" and probe.is_legacy_error_or_bounded_timeout:
    era, version = legacy_initialize_on_same_process()
elif transport == "http" and probe.http_status == 400 and probe.body_is_not_modern_error:
    era, version = legacy_initialize_on_same_origin()
else:
    stop_and_diagnose()  # Auth failures and network ambiguity do not trigger a downgrade.
persist(era, version, server_configuration_revision)
# Probe with discovery, never a business write. Preserve pending operation_id.

Submission and evidence boundary

Run all 13 fixed cases, retain the first red report, repair your own module, and rerun. The runner imports the learner module and records exact expected/actual/error, case/module hashes and Python version. Exit 0 means all fixed contract cases passed; exit 1 means a contract failure; malformed CLI or overwrite refusal uses exit 2. Its five-second guard is not a latency benchmark. Published expected values are teaching data, not evidence of independent mastery.

The grader does not send MCP messages, validate actual tokens/cursors, commit a refund, negotiate a modern extension, or prove remote delivery. An all-green report therefore supports only the old function contract. For real integration, the design layer requires a separate client/server compatibility matrix and fault evidence.

code example

Fixed legacy contract: session-replaced-write-reconcile

This exact fixture input and expectation remain unchanged. It is not a modern request.

{
  "input": {
    "transport": "streamable_http",
    "phase": "after_send",
    "operation": "write",
    "session_id": "session-1",
    "new_session_id": "session-2",
    "resume_supported": true,
    "last_event_id": "stream1-event9",
    "operation_key": "refund-1"
  },
  "expected": {
    "action": "reconcile",
    "reason": "write_result_unknown",
    "operation_key": "refund-1",
    "last_event_id": null
  },
  "error": null
}

Acceptance task for this level

Implement the unchanged reconnect_decision contract, retain the first red report and all-case rerun, then annotate the modern detection pseudocode without claiming it was executed.

Acceptance self-checks

Reading this browser’s record…

Hide the answer and check your understanding

What does an all-green legacy fixture report prove?

Further explanations and practice

When encountering unfamiliar principles, first read the implementation, continuous questioning and migration cases, and then independently explain the premise and boundaries. Answers and notes are saved to the original account record.

All linked explanations and exercises (1 )

Sources and verification scope

The principles are based on public information; the numbers, cases and tasks are the teaching design of this website. Offline experiments verify the range noted on this page, and the learning effect still needs to be judged through independent tasks and feedback.