Skip to content

Commit d2fc2e8

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/sse-client-refresh-token
2 parents b08ad9f + 222db4a commit d2fc2e8

24 files changed

+2950
-229
lines changed

.github/CODEOWNERS

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# TypeScript SDK Code Owners
2+
3+
# Default owners for everything in the repo
4+
* @modelcontextprotocol/typescript-sdk
5+
6+
# Auth team owns all auth-related code
7+
/src/server/auth/ @modelcontextprotocol/typescript-sdk-auth
8+
/src/client/auth* @modelcontextprotocol/typescript-sdk-auth
9+
/src/shared/auth* @modelcontextprotocol/typescript-sdk-auth
10+
/src/examples/client/simpleOAuthClient.ts @modelcontextprotocol/typescript-sdk-auth
11+
/src/examples/server/demoInMemoryOAuthProvider.ts @modelcontextprotocol/typescript-sdk-auth

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ web_modules/
6969
# Output of 'npm pack'
7070
*.tgz
7171

72+
# Output of 'npm run fetch:spec-types'
73+
spec.types.ts
74+
7275
# Yarn Integrity file
7376
.yarn-integrity
7477

README.md

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The Model Context Protocol allows applications to provide context for LLMs in a
4545
npm install @modelcontextprotocol/sdk
4646
```
4747

48-
> ⚠️ MCP requires Node v18.x up to work fine.
48+
> ⚠️ MCP requires Node.js v18.x or higher to work fine.
4949
5050
## Quick Start
5151

@@ -571,7 +571,6 @@ app.listen(3000);
571571

572572
> [!TIP]
573573
> 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-
> ```
575574
576575

577576
#### CORS Configuration for Browser-Based Clients
@@ -584,8 +583,8 @@ import cors from 'cors';
584583
// Add CORS middleware before your MCP routes
585584
app.use(cors({
586585
origin: '*', // Configure appropriately for production, for example:
587-
// origin: ['https://your-remote-domain.com, https://your-other-remote-domain.com'],
588-
exposedHeaders: ['Mcp-Session-Id']
586+
// origin: ['https://your-remote-domain.com', 'https://your-other-remote-domain.com'],
587+
exposedHeaders: ['Mcp-Session-Id'],
589588
allowedHeaders: ['Content-Type', 'mcp-session-id'],
590589
}));
591590
```
@@ -876,15 +875,15 @@ const putMessageTool = server.tool(
876875
"putMessage",
877876
{ channel: z.string(), message: z.string() },
878877
async ({ channel, message }) => ({
879-
content: [{ type: "text", text: await putMessage(channel, string) }]
878+
content: [{ type: "text", text: await putMessage(channel, message) }]
880879
})
881880
);
882881
// Until we upgrade auth, `putMessage` is disabled (won't show up in listTools)
883882
putMessageTool.disable()
884883

885884
const upgradeAuthTool = server.tool(
886885
"upgradeAuth",
887-
{ permission: z.enum(["write', admin"])},
886+
{ permission: z.enum(["write", "admin"])},
888887
// Any mutations here will automatically emit `listChanged` notifications
889888
async ({ permission }) => {
890889
const { ok, err, previous } = await upgradeAuthAndStoreToken(permission)
@@ -913,6 +912,43 @@ const transport = new StdioServerTransport();
913912
await server.connect(transport);
914913
```
915914

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.
925+
926+
```typescript
927+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
928+
929+
const server = new McpServer(
930+
{
931+
name: "efficient-server",
932+
version: "1.0.0"
933+
},
934+
{
935+
// 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+
916952
### Low-Level Server
917953

918954
For more control, you can use the low-level Server class directly:
@@ -1175,7 +1211,7 @@ This setup allows you to:
11751211

11761212
### Backwards Compatibility
11771213

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
11791215

11801216
#### Client-Side Compatibility
11811217

package-lock.json

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@modelcontextprotocol/sdk",
3-
"version": "1.15.1",
3+
"version": "1.17.0",
44
"description": "Model Context Protocol implementation for TypeScript",
55
"license": "MIT",
66
"author": "Anthropic, PBC (https://anthropic.com)",
@@ -35,6 +35,7 @@
3535
"dist"
3636
],
3737
"scripts": {
38+
"fetch:spec-types": "curl -o spec.types.ts https://raw.githubusercontent.com/modelcontextprotocol/modelcontextprotocol/refs/heads/main/schema/draft/schema.ts",
3839
"build": "npm run build:esm && npm run build:cjs",
3940
"build:esm": "mkdir -p dist/esm && echo '{\"type\": \"module\"}' > dist/esm/package.json && tsc -p tsconfig.prod.json",
4041
"build:esm:w": "npm run build:esm -- -w",
@@ -43,7 +44,7 @@
4344
"examples:simple-server:w": "tsx --watch src/examples/server/simpleStreamableHttp.ts --oauth",
4445
"prepack": "npm run build:esm && npm run build:cjs",
4546
"lint": "eslint src/",
46-
"test": "jest",
47+
"test": "npm run fetch:spec-types && jest",
4748
"start": "npm run server",
4849
"server": "tsx watch --clear-screen=false src/cli.ts server",
4950
"client": "tsx src/cli.ts client"

0 commit comments

Comments
 (0)