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: README.md
+43-7Lines changed: 43 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,7 +45,7 @@ The Model Context Protocol allows applications to provide context for LLMs in a
45
45
npm install @modelcontextprotocol/sdk
46
46
```
47
47
48
-
> ⚠️ MCP requires Node v18.x up to work fine.
48
+
> ⚠️ MCP requires Node.js v18.x or higher to work fine.
49
49
50
50
## Quick Start
51
51
@@ -571,7 +571,6 @@ app.listen(3000);
571
571
572
572
> [!TIP]
573
573
> When using this in a remote environment, make sure to allow the header parameter `mcp-session-id` in CORS. Otherwise, it may result in a `Bad Request: No valid session ID provided` error. Read the following section for examples.
574
-
> ```
575
574
576
575
577
576
#### CORS Configuration for Browser-Based Clients
@@ -584,8 +583,8 @@ import cors from 'cors';
584
583
// Add CORS middleware before your MCP routes
585
584
app.use(cors({
586
585
origin: '*', // Configure appropriately for production, for example:
@@ -913,6 +912,43 @@ const transport = new StdioServerTransport();
913
912
awaitserver.connect(transport);
914
913
```
915
914
915
+
### Improving Network Efficiency with Notification Debouncing
916
+
917
+
When performing bulk updates that trigger notifications (e.g., enabling or disabling multiple tools in a loop), the SDK can send a large number of messages in a short period. To improve performance and reduce network traffic, you can enable notification debouncing.
918
+
919
+
This feature coalesces multiple, rapid calls for the same notification type into a single message. For example, if you disable five tools in a row, only one `notifications/tools/list_changed` message will be sent instead of five.
920
+
921
+
> [!IMPORTANT]
922
+
> This feature is designed for "simple" notifications that do not carry unique data in their parameters. To prevent silent data loss, debouncing is **automatically bypassed** for any notification that contains a `params` object or a `relatedRequestId`. Such notifications will always be sent immediately.
923
+
924
+
This is an opt-in feature configured during server initialization.
// Enable notification debouncing for specific methods
936
+
debouncedNotificationMethods: [
937
+
'notifications/tools/list_changed',
938
+
'notifications/resources/list_changed',
939
+
'notifications/prompts/list_changed'
940
+
]
941
+
}
942
+
);
943
+
944
+
// Now, any rapid changes to tools, resources, or prompts will result
945
+
// in a single, consolidated notification for each type.
946
+
server.registerTool("tool1", ...).disable();
947
+
server.registerTool("tool2", ...).disable();
948
+
server.registerTool("tool3", ...).disable();
949
+
// Only one 'notifications/tools/list_changed' is sent.
950
+
```
951
+
916
952
### Low-Level Server
917
953
918
954
For more control, you can use the low-level Server class directly:
@@ -1175,7 +1211,7 @@ This setup allows you to:
1175
1211
1176
1212
### Backwards Compatibility
1177
1213
1178
-
Clients and servers with StreamableHttp tranport can maintain [backwards compatibility](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#backwards-compatibility) with the deprecated HTTP+SSE transport (from protocol version 2024-11-05) as follows
1214
+
Clients and servers with StreamableHttp transport can maintain [backwards compatibility](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#backwards-compatibility) with the deprecated HTTP+SSE transport (from protocol version 2024-11-05) as follows
0 commit comments