You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 03-GettingStarted/06-http-streaming/README.md
+29-15Lines changed: 29 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,9 @@ This chapter provides a comprehensive guide to implementing secure, scalable, an
4
4
5
5
---
6
6
7
-
## 1. Transport Mechanisms and Streaming in MCP
7
+
## Transport Mechanisms and Streaming in MCP
8
+
9
+
This section explores the different transport mechanisms available in MCP and their role in enabling streaming capabilities for real-time communication between clients and servers.
8
10
9
11
### What is a Transport Mechanism?
10
12
A transport mechanism defines how data is exchanged between the client and server. MCP supports multiple transport types to suit different environments and requirements:
@@ -13,7 +15,7 @@ A transport mechanism defines how data is exchanged between the client and serve
13
15
-**SSE (Server-Sent Events)**: Allows servers to push real-time updates to clients over HTTP. Good for web UIs, but limited in scalability and flexibility.
14
16
-**Streamable HTTP**: Modern HTTP-based streaming transport, supporting notifications and better scalability. Recommended for most production and cloud scenarios.
15
17
16
-
####Comparison Table
18
+
### Comparison Table
17
19
| Transport | Real-time Updates | Streaming | Scalability | Use Case |
@@ -24,20 +26,20 @@ A transport mechanism defines how data is exchanged between the client and serve
24
26
25
27
---
26
28
27
-
## 2. Streaming: Concepts and Motivation
29
+
## Streaming: Concepts and Motivation
28
30
29
31
**Streaming** is a technique in network programming that allows data to be sent and received in small, manageable chunks or as a sequence of events, rather than waiting for an entire response to be ready. This is especially useful for:
30
32
31
33
- Large files or datasets
32
34
- Real-time updates (e.g., chat, progress bars)
33
35
- Long-running computations where you want to keep the user informed
34
36
35
-
####Key Concepts
37
+
### Key Concepts
36
38
- Data is delivered progressively, not all at once
37
39
- The client can process data as it arrives
38
40
- Reduces perceived latency and improves user experience
39
41
40
-
####Why use streaming?
42
+
### Why use streaming?
41
43
- Users get feedback immediately, not just at the end
42
44
- Enables real-time applications and responsive UIs
43
45
- More efficient use of network and compute resources
@@ -124,16 +126,18 @@ Based on what we've observed:
124
126
125
127
---
126
128
127
-
## 3. Streaming in MCP
129
+
## Streaming in MCP
130
+
131
+
Understanding how streaming works within the MCP framework is essential for building responsive applications that provide real-time feedback to users during long-running operations.
128
132
129
133
In MCP, streaming is not about sending the main response in chunks, but about sending **notifications** to the client while a tool is processing a request. These notifications can include progress updates, logs, or other events.
130
134
131
-
####Key differences from traditional streaming
135
+
### Key differences from traditional streaming
132
136
- The main result is still sent as a single response
133
137
- Notifications are sent as separate messages during processing
134
138
- The client must be able to handle and display these notifications
135
139
136
-
####What is a Notification?
140
+
### What is a Notification?
137
141
A notification is a message sent from the server to the client to inform about progress, status, or other events during a long-running operation. Notifications improve transparency and user experience.
138
142
139
143
##### Why use notifications?
@@ -143,7 +147,9 @@ A notification is a message sent from the server to the client to inform about p
143
147
144
148
---
145
149
146
-
## 4. Implementing Notifications in MCP
150
+
## Implementing Notifications in MCP
151
+
152
+
This section demonstrates how to implement real-time notifications in your MCP applications, covering both server-side notification sending and client-side message handling.
147
153
148
154
### Server-side: Sending Notifications
149
155
To send notifications from your MCP tool, use the context object (usually `ctx`) to call methods like `ctx.info()` or `ctx.log()`. These send messages to the client as the server processes a request.
@@ -172,7 +178,9 @@ To enable notifications, ensure your server uses a streaming transport (like `st
172
178
173
179
---
174
180
175
-
## 5. Streamable HTTP Transport
181
+
## Streamable HTTP Transport
182
+
183
+
This section provides detailed coverage of Streamable HTTP, the recommended transport mechanism for production MCP deployments, including its architecture, benefits, and implementation details.
176
184
177
185
### What is Streamable HTTP?
178
186
Streamable HTTP is a transport mechanism in MCP that uses HTTP POST requests and supports streaming notifications (such as progress updates) from the server to the client. It is designed for modern web and cloud environments.
@@ -200,7 +208,9 @@ Streamable HTTP is a transport mechanism in MCP that uses HTTP POST requests and
200
208
201
209
---
202
210
203
-
## 6. Security Considerations
211
+
## Security Considerations
212
+
213
+
When implementing MCP servers with HTTP-based transports, security becomes a paramount concern that requires careful attention to multiple attack vectors and protection mechanisms.
204
214
205
215
### Overview
206
216
Security is critical when exposing MCP servers over HTTP. Streamable HTTP introduces new attack surfaces and requires careful configuration.
@@ -223,7 +233,7 @@ Security is critical when exposing MCP servers over HTTP. Streamable HTTP introd
223
233
224
234
---
225
235
226
-
## 7. Implementation Guide
236
+
## Implementation Guide
227
237
228
238
This section provides a step-by-step guide to building, running, and understanding an MCP streaming server and client using the streamable HTTP transport.
229
239
@@ -338,7 +348,9 @@ This section provides a step-by-step guide to building, running, and understandi
338
348
339
349
---
340
350
341
-
## 8. Upgrading from SSE to Streamable HTTP
351
+
## Upgrading from SSE to Streamable HTTP
352
+
353
+
For applications currently using Server-Sent Events (SSE), migrating to Streamable HTTP provides enhanced capabilities and better long-term sustainability for your MCP implementations.
342
354
343
355
### Why Upgrade?
344
356
- Streamable HTTP offers better scalability, compatibility, and richer notification support than SSE.
@@ -360,7 +372,7 @@ This section provides a step-by-step guide to building, running, and understandi
360
372
361
373
---
362
374
363
-
## 9. Progress Notifications & Scenarios
375
+
## Progress Notifications & Scenarios
364
376
365
377
This section explains the concept of progress notifications in MCP, why they matter, and how to implement them using Streamable HTTP. You'll also find a practical assignment to reinforce your understanding.
366
378
@@ -413,7 +425,9 @@ Build an MCP server and client where the server processes a list of items (e.g.,
413
425
414
426
You can use the code samples above as a starting point, or refer to the provided [server.py](./server.py) and [client.py](./client.py) in this chapter for a complete implementation.
415
427
416
-
## 10. Further Reading & What Next?
428
+
## Further Reading & What Next?
429
+
430
+
To continue your journey with MCP streaming and expand your knowledge, this section provides additional resources and suggested next steps for building more advanced applications.
417
431
418
432
### Further Reading
419
433
-[Microsoft: Introduction to HTTP Streaming](https://learn.microsoft.com/aspnet/core/fundamentals/http-requests?view=aspnetcore-8.0&WT.mc_id=%3Fwt.mc_id%3DMVP_452430#streaming)
0 commit comments