← All lessons
Lesson 09Model Context Protocol Advanced Topics
State and the StreamableHTTP transport
Summary audio
Spoken summary — press play to read along: the line being spoken stays near the top.
Study notes
⚙️ Server Flags: Stateless and JSON Response
These flags control how your server handles client connections and data transmission, particularly when scaling.
🌐 Horizontal Scaling Context
- Problem: When a server becomes popular, a single instance cannot handle the traffic.
- Solution: Implement horizontal scaling by running multiple server copies behind a load balancer.
- Challenge: Maintaining client state (e. g. , tracking a continuous connection or multi-step process across different servers) is extremely complex when using a load balancer.
🚩 stateless Flag
Setting this flag to true makes the server unable to track client sessions, which is a trade-off for scalability.
✅ Effects of stateless = true:
- No Session Tracking: The server does not receive or maintain a session ID, meaning it cannot track individual clients.
- Loss of Stateful Features: The server cannot use the gRPC SSE response pathway, limiting features like:
- Sampling
- Progress logging
- Subscriptions
- Efficiency Gain: Eliminates the need for initial client initialization requests, reducing server traffic and complexity.
📦 JSON response Flag
Setting this flag to true changes the format and timing of responses.
✅ Effects of JSON response = true:
- Disables Streaming: POST requests will no longer use Server-Sent Events (SSE).
- Final Result Only: The server waits until the entire tool call or process is complete before sending any response.
- Output: Responses are delivered as plain JSON, without intermediate log statements or streaming updates.
💡 Development Best Practice
- When developing your server locally, always use the transport mechanism (e. g. , HTTP, gRPC) that you plan to use in production to avoid significant issues later.
Takeaways
- Horizontal Scaling: To handle high traffic, servers must use horizontal scaling (multiple instances behind a load balancer), which inherently complicates maintaining client state.
- stateless = true: Setting this flag sacrifices session tracking and all stateful features (e. g. , progress logging, subscriptions) but significantly improves scalability and reduces initial client overhead.
- JSON response = true: This flag disables streaming (SSE) and forces the server to wait until the entire process is complete before sending a single, final response formatted as plain JSON.
- Development Best Practice: Always test your server locally using the exact transport mechanism (HTTP, gRPC, etc. ) intended for production to prevent deployment issues.
Flashcards 7 cards
Question
click to reveal · ←/→
Answer
click to flip back
Knowledge check 6 questions