Skip to content

Commit 58d6fbe

Browse files
authored
Merge branch 'main' into feature/tool-output-type-generics
2 parents 6123acc + b28c297 commit 58d6fbe

13 files changed

+473
-118
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@modelcontextprotocol/sdk",
3-
"version": "1.17.4",
3+
"version": "1.18.0",
44
"description": "Model Context Protocol implementation for TypeScript",
55
"license": "MIT",
66
"author": "Anthropic, PBC (https://anthropic.com)",

src/examples/server/jsonResponseStreamableHttp.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,27 @@ const getServer = () => {
4444
{
4545
name: z.string().describe('Name to greet'),
4646
},
47-
async ({ name }, { sendNotification }): Promise<CallToolResult> => {
47+
async ({ name }, extra): Promise<CallToolResult> => {
4848
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
4949

50-
await sendNotification({
51-
method: "notifications/message",
52-
params: { level: "debug", data: `Starting multi-greet for ${name}` }
53-
});
50+
await server.sendLoggingMessage({
51+
level: "debug",
52+
data: `Starting multi-greet for ${name}`
53+
}, extra.sessionId);
5454

5555
await sleep(1000); // Wait 1 second before first greeting
5656

57-
await sendNotification({
58-
method: "notifications/message",
59-
params: { level: "info", data: `Sending first greeting to ${name}` }
60-
});
57+
await server.sendLoggingMessage({
58+
level: "info",
59+
data: `Sending first greeting to ${name}`
60+
}, extra.sessionId);
6161

6262
await sleep(1000); // Wait another second before second greeting
6363

64-
await sendNotification({
65-
method: "notifications/message",
66-
params: { level: "info", data: `Sending second greeting to ${name}` }
67-
});
64+
await server.sendLoggingMessage({
65+
level: "info",
66+
data: `Sending second greeting to ${name}`
67+
}, extra.sessionId);
6868

6969
return {
7070
content: [
@@ -170,4 +170,4 @@ app.listen(PORT, (error) => {
170170
process.on('SIGINT', async () => {
171171
console.log('Shutting down server...');
172172
process.exit(0);
173-
});
173+
});

src/examples/server/simpleSseServer.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { z } from 'zod';
55
import { CallToolResult } from '../../types.js';
66

77
/**
8-
* This example server demonstrates the deprecated HTTP+SSE transport
8+
* This example server demonstrates the deprecated HTTP+SSE transport
99
* (protocol version 2024-11-05). It mainly used for testing backward compatible clients.
10-
*
10+
*
1111
* The server exposes two endpoints:
1212
* - /mcp: For establishing the SSE stream (GET)
1313
* - /messages: For receiving client messages (POST)
14-
*
14+
*
1515
*/
1616

1717
// Create an MCP server instance
@@ -28,32 +28,26 @@ const getServer = () => {
2828
interval: z.number().describe('Interval in milliseconds between notifications').default(1000),
2929
count: z.number().describe('Number of notifications to send').default(10),
3030
},
31-
async ({ interval, count }, { sendNotification }): Promise<CallToolResult> => {
31+
async ({ interval, count }, extra): Promise<CallToolResult> => {
3232
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
3333
let counter = 0;
3434

3535
// Send the initial notification
36-
await sendNotification({
37-
method: "notifications/message",
38-
params: {
39-
level: "info",
40-
data: `Starting notification stream with ${count} messages every ${interval}ms`
41-
}
42-
});
36+
await server.sendLoggingMessage({
37+
level: "info",
38+
data: `Starting notification stream with ${count} messages every ${interval}ms`
39+
}, extra.sessionId);
4340

4441
// Send periodic notifications
4542
while (counter < count) {
4643
counter++;
4744
await sleep(interval);
4845

4946
try {
50-
await sendNotification({
51-
method: "notifications/message",
52-
params: {
47+
await server.sendLoggingMessage({
5348
level: "info",
5449
data: `Notification #${counter} at ${new Date().toISOString()}`
55-
}
56-
});
50+
}, extra.sessionId);
5751
}
5852
catch (error) {
5953
console.error("Error sending notification:", error);
@@ -169,4 +163,4 @@ process.on('SIGINT', async () => {
169163
}
170164
console.log('Server shutdown complete');
171165
process.exit(0);
172-
});
166+
});

src/examples/server/simpleStatelessStreamableHttp.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,17 @@ const getServer = () => {
4242
interval: z.number().describe('Interval in milliseconds between notifications').default(100),
4343
count: z.number().describe('Number of notifications to send (0 for 100)').default(10),
4444
},
45-
async ({ interval, count }, { sendNotification }): Promise<CallToolResult> => {
45+
async ({ interval, count }, extra): Promise<CallToolResult> => {
4646
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
4747
let counter = 0;
4848

4949
while (count === 0 || counter < count) {
5050
counter++;
5151
try {
52-
await sendNotification({
53-
method: "notifications/message",
54-
params: {
55-
level: "info",
56-
data: `Periodic notification #${counter} at ${new Date().toISOString()}`
57-
}
58-
});
52+
await server.sendLoggingMessage({
53+
level: "info",
54+
data: `Periodic notification #${counter} at ${new Date().toISOString()}`
55+
}, extra.sessionId);
5956
}
6057
catch (error) {
6158
console.error("Error sending notification:", error);
@@ -170,4 +167,4 @@ app.listen(PORT, (error) => {
170167
process.on('SIGINT', async () => {
171168
console.log('Shutting down server...');
172169
process.exit(0);
173-
});
170+
});

src/examples/server/simpleStreamableHttp.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ const strictOAuth = process.argv.includes('--oauth-strict');
2121
const getServer = () => {
2222
const server = new McpServer({
2323
name: 'simple-streamable-http-server',
24-
version: '1.0.0'
24+
version: '1.0.0',
25+
icons: [{src: './mcp.svg', sizes: '512x512', mimeType: 'image/svg+xml'}],
26+
websiteUrl: 'https://github.com/modelcontextprotocol/typescript-sdk',
2527
}, { capabilities: { logging: {} } });
2628

2729
// Register a simple tool that returns a greeting
@@ -58,27 +60,27 @@ const getServer = () => {
5860
readOnlyHint: true,
5961
openWorldHint: false
6062
},
61-
async ({ name }, { sendNotification }): Promise<CallToolResult> => {
63+
async ({ name }, extra): Promise<CallToolResult> => {
6264
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
6365

64-
await sendNotification({
65-
method: "notifications/message",
66-
params: { level: "debug", data: `Starting multi-greet for ${name}` }
67-
});
66+
await server.sendLoggingMessage({
67+
level: "debug",
68+
data: `Starting multi-greet for ${name}`
69+
}, extra.sessionId);
6870

6971
await sleep(1000); // Wait 1 second before first greeting
7072

71-
await sendNotification({
72-
method: "notifications/message",
73-
params: { level: "info", data: `Sending first greeting to ${name}` }
74-
});
73+
await server.sendLoggingMessage({
74+
level: "info",
75+
data: `Sending first greeting to ${name}`
76+
}, extra.sessionId);
7577

7678
await sleep(1000); // Wait another second before second greeting
7779

78-
await sendNotification({
79-
method: "notifications/message",
80-
params: { level: "info", data: `Sending second greeting to ${name}` }
81-
});
80+
await server.sendLoggingMessage({
81+
level: "info",
82+
data: `Sending second greeting to ${name}`
83+
}, extra.sessionId);
8284

8385
return {
8486
content: [
@@ -273,20 +275,17 @@ const getServer = () => {
273275
interval: z.number().describe('Interval in milliseconds between notifications').default(100),
274276
count: z.number().describe('Number of notifications to send (0 for 100)').default(50),
275277
},
276-
async ({ interval, count }, { sendNotification }): Promise<CallToolResult> => {
278+
async ({ interval, count }, extra): Promise<CallToolResult> => {
277279
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
278280
let counter = 0;
279281

280282
while (count === 0 || counter < count) {
281283
counter++;
282284
try {
283-
await sendNotification({
284-
method: "notifications/message",
285-
params: {
286-
level: "info",
287-
data: `Periodic notification #${counter} at ${new Date().toISOString()}`
288-
}
289-
});
285+
await server.sendLoggingMessage( {
286+
level: "info",
287+
data: `Periodic notification #${counter} at ${new Date().toISOString()}`
288+
}, extra.sessionId);
290289
}
291290
catch (error) {
292291
console.error("Error sending notification:", error);

src/examples/server/sseAndStreamableHttpCompatibleServer.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import cors from 'cors';
1212
* This example server demonstrates backwards compatibility with both:
1313
* 1. The deprecated HTTP+SSE transport (protocol version 2024-11-05)
1414
* 2. The Streamable HTTP transport (protocol version 2025-03-26)
15-
*
15+
*
1616
* It maintains a single MCP server instance but exposes two transport options:
1717
* - /mcp: The new Streamable HTTP endpoint (supports GET/POST/DELETE)
1818
* - /sse: The deprecated SSE endpoint for older clients (GET to establish stream)
@@ -33,20 +33,17 @@ const getServer = () => {
3333
interval: z.number().describe('Interval in milliseconds between notifications').default(100),
3434
count: z.number().describe('Number of notifications to send (0 for 100)').default(50),
3535
},
36-
async ({ interval, count }, { sendNotification }): Promise<CallToolResult> => {
36+
async ({ interval, count }, extra): Promise<CallToolResult> => {
3737
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
3838
let counter = 0;
3939

4040
while (count === 0 || counter < count) {
4141
counter++;
4242
try {
43-
await sendNotification({
44-
method: "notifications/message",
45-
params: {
46-
level: "info",
47-
data: `Periodic notification #${counter} at ${new Date().toISOString()}`
48-
}
49-
});
43+
await server.sendLoggingMessage({
44+
level: "info",
45+
data: `Periodic notification #${counter} at ${new Date().toISOString()}`
46+
}, extra.sessionId);
5047
}
5148
catch (error) {
5249
console.error("Error sending notification:", error);
@@ -254,4 +251,4 @@ process.on('SIGINT', async () => {
254251
}
255252
console.log('Server shutdown complete');
256253
process.exit(0);
257-
});
254+
});

0 commit comments

Comments
 (0)