Skip to main content

Core Concept 2: Protocol Lifecycle, Control Boundaries & Transports

Step up to the formal protocol mechanics: trace the 4-phase JSON-RPC 2.0 session lifecycle, control boundaries, bidirectional sampling/elicitation, and transport rules.

Zoom into the formal protocol mechanics underneath every MCP server: the 4-phase JSON-RPC 2.0 session lifecycle, who controls Tools vs. Resources vs. Prompts, bidirectional sampling & elicitation, and operational security pitfalls.

Key Terms in This Lab:ProtocolJSON-RPC 2.0In plain English: Every MCP message is a small JSON object with a "method" (like "tools/call"), "params" (inputs), and an "id" so the reply matches the request. If something fails, it returns a structured "error" object.Analogy: A standardized shipping label with a tracking ID, action requested, and return address.On Azure Stack: Sent over HTTPS POST to Azure APIM, which inspects headers before forwarding JSON-RPC to Python.Core Concepts4-Phase JSON-RPC Session LifecycleIn plain English: Phase 1 negotiates protocol version and capabilities via initialize and notifications/initialized. Phase 2 discovers tools, resources, and prompts (with optional cursor pagination). Phase 3 invokes operations and streams progress/logs. Phase 4 tears down cleanly.Analogy: An air traffic control flight sequence: radio check, flight plan clearance, en-route updates, and runway sign-off.On Azure Stack: Same 4-phase JSON-RPC contract used by Microsoft Agent Framework clients.Core ConceptsPrimitive Control BoundariesIn plain English: Tools (tools/call) are model-controlled executable functions with host approval gates. Resources (resources/read) are application-controlled URI-addressed data. Prompts (prompts/get) are user-controlled workflow commands.Analogy: Tools = pedals the driver presses, Resources = dashboard gauges the car reads, Prompts = presets the passenger taps.On Azure Stack: Enforced identically by FastMCP 4 and Azure AI Foundry hosts.Core ConceptsBidirectional Sampling & ElicitationIn plain English: An MCP session can flow both ways: a server can request client-side LLM completions via sampling or ask the human for structured inputs via elicitation. In distributed stateless cloud deployments, teams pair this pattern with externalized state handles.Analogy: A line cook calling back to the waiter to ask the diner a clarifying question before plating.On Azure Stack: Handled locally in stateful sessions or via stateless InputRequiredResult + Cosmos DB on Azure.Core ConceptsSTDIO Local TransportIn plain English: Most starter MCP servers run locally over Standard Input/Output (STDIO). The Host launches your Python or TypeScript script in the background and streams newline-delimited JSON-RPC messages over stdin and stdout.Analogy: Two engineers passing typed index cards back and forth through a private mail slot on the same desk.On Azure Stack: Local developer inner loop before deploying stateless HTTP to Azure Container Apps.Core ConceptsSTDIO stdout Stream PollutionIn plain English: Because STDIO reserves stdout exclusively for structured JSON-RPC protocol frames, any stray print() in Python or console.log() in Node/TypeScript corrupts message parsing and crashes the client connection.Analogy: Writing doodles across a machine-readable barcode—the scanner rejects the entire package.On Azure Stack: Use sys.stderr / console.error locally; emit structured JSON logs in Azure Container Apps.
Cloud-Agnostic Core Concept · Identical for Azure & GCPJSON-RPC 2.0 · JSON Schema · STDIO & Streamable HTTP
Master once, then apply to either cloud stack
Concept Escalator

1. Visual Analogy · Air Traffic Control Handshake & Clear Cockpit Roles

Intuition First
Start Here · Plain-English Concept Brief
~5 min

What actually travels on the wire during an MCP session—and who controls Tools vs. Resources vs. Prompts?

Once you know how a tiny server works, the next step is understanding the formal session rules underneath it. Instead of ad-hoc messages, MCP uses JSON-RPC 2.0 with strict version negotiation, paginated capability discovery, explicit control boundaries, and structured isError: true diagnostics.

How this fits: This is Core Concept 2 (cloud-agnostic). Mastering JSON-RPC lifecycle phases and control boundaries prepares you for production engineering (C3) and stateless cloud scaling (Lab 1).

  • A session starts with initialize -> server capabilities -> notifications/initialized before any tools/call runs.
  • Model-controlled Tools, App-controlled Resources, and User-controlled Prompts keep authority boundaries explicit.
  • Validate inputs at the boundary, return isError: true instead of crashing, and allowlist URIs to block SSRF.
1. JSON-RPC HandshakeToolsModelResourcesAppPromptsUser

Every flight begins with a strict radio handshake before takeoff, separates pilot controls from air-traffic advisories and passenger requests, and uses structured callsigns so transmissions never collide. MCP does the same over JSON-RPC 2.0.

Engineering Takeaway: Separating Model-controlled Tools, App-controlled Resources, and User-controlled Prompts—plus strict JSON Schema validation and isError: true diagnostics—prevents server crashes and confused-deputy bugs.
Quick Concept Check (Optional)

In MCP control boundaries, which primitive is primarily application-controlled rather than silently invoked by the model?

Step 1 of 3 ready? Move on to see how the pieces connect visually.

Engineering Scratchpad

Auto-saved per lab in mcp_foundry_v1_scratchpads

0 chars saved