Week 14 • Day 3Week 14

Day 3:Week 14, Day 3: `MCP` Transports (`stdio` vs `Streamable HTTP`) & Cursor-Based Pagination

Battle-tested daily lesson note • 100% runnable code, interview Q&A, test suite & interactive quiz

Week 14, Day 3: MCP Transports (stdio vs Streamable HTTP) & Cursor-Based Pagination


1. The Two Official MCP Transports

How do JSON-RPC 2.0 packets travel between the MCP Client and MCP Server?

TransportFraming MechanismWhen to Use & Critical Rules
1. stdio (Standard Input/Output)Newline-delimited JSON (\n) over OS pipes (stdin →\rightarrow Server →\rightarrow stdout).Best for local IDE/desktop tools spawned as child processes. CRITICAL RULE: Never call print() to stdout for debug logging in a stdio MCP server—it corrupts the JSON-RPC stream! Always log to sys.stderr!
2. Streamable HTTPSingle HTTP POST /mcp endpoint returning application/json or upgrading to text/event-stream (SSE).Best for remote, multi-tenant microservice MCP servers deployed on Kubernetes/Cloud Run with OAuth 2.1 Bearer authentication.

2. Cursor-Based Pagination in MCP (nextCursor)

What if an MCP Server exposes 10,000 database resources in resources/list? Returning all 10,000 in a single JSON packet would blow up memory! MCP uses opaque Cursor-Based Pagination:

  • Request: {"method": "resources/list", "params": {"cursor": "eyJvZmZzZXQiOiA1MH0="}}
  • Response: {"resources": [...50 items...], "nextCursor": "eyJvZmZzZXQiOiAxMDB9"} (or omits nextCursor on the final page).

In Simple English: stdio vs Streamable HTTP & Cursor Pagination

  • stdio Transport (Walkie-Talkie Wire): The Host spawns a local script as a child process and talks directly over standard input/output (stdin/stdout). Instant, $0 network overhead, great for developer desktops!
  • Streamable HTTP Transport (Cloud API): Talks to remote shared microservices over HTTPS + Server-Sent Events (SSE), scaling across Kubernetes pods.
  • Cursor Pagination: If an MCP server owns 2,000 tools or database rows, never dump all 2,000 in one giant message! Hand back 50 at a time with a bookmark (nextCursor: "page_2") so payloads stay lean.