Skip to content

Commit 67d79d4

Browse files
authored
Update server examples and docs (#1285)
1 parent 06a4fd2 commit 67d79d4

File tree

8 files changed

+65
-48
lines changed

8 files changed

+65
-48
lines changed

docs/server.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ Key examples:
3131
- [`jsonResponseStreamableHttp.ts`](../src/examples/server/jsonResponseStreamableHttp.ts)`enableJsonResponse: true`, no SSE
3232
- [`standaloneSseWithGetStreamableHttp.ts`](../src/examples/server/standaloneSseWithGetStreamableHttp.ts) – notifications with Streamable HTTP GET + SSE
3333

34-
See the MCP spec for full transport details:
35-
`https://modelcontextprotocol.io/specification/2025-03-26/basic/transports`
34+
See the MCP spec for full transport details: `https://modelcontextprotocol.io/specification/2025-11-25/basic/transports`
3635

3736
### Stateless vs stateful sessions
3837

src/examples/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ npx tsx src/examples/client/simpleClientCredentials.ts
5050

5151
### Backwards Compatible Client
5252

53-
A client that implements backwards compatibility according to the [MCP specification](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#backwards-compatibility), allowing it to work with both new and legacy servers. This client demonstrates:
53+
A client that implements backwards compatibility according to the [MCP specification](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#backwards-compatibility), allowing it to work with both new and legacy servers. This client demonstrates:
5454

5555
- The client first POSTs an initialize request to the server URL:
5656
- If successful, it uses the Streamable HTTP transport
@@ -83,7 +83,7 @@ These examples demonstrate how to set up an MCP server on a single node with dif
8383

8484
##### Simple Streamable HTTP Server
8585

86-
A server that implements the Streamable HTTP transport (protocol version 2025-03-26).
86+
A server that implements the Streamable HTTP transport (protocol version 2025-11-25).
8787

8888
- Basic server setup with Express and the Streamable HTTP transport
8989
- Session management with an in-memory event store for resumability
@@ -166,7 +166,7 @@ npx tsx src/examples/server/simpleSseServer.ts
166166

167167
#### Streamable Http Backwards Compatible Server with SSE
168168

169-
A server that supports both Streamable HTTP and SSE transports, adhering to the [MCP specification for backwards compatibility](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#backwards-compatibility).
169+
A server that supports both Streamable HTTP and SSE transports, adhering to the [MCP specification for backwards compatibility](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#backwards-compatibility).
170170

171171
- Single MCP server instance with multiple transport options
172172
- Support for Streamable HTTP requests at `/mcp` endpoint (GET/POST/DELETE)
@@ -337,7 +337,7 @@ To test the backwards compatibility features:
337337
# Legacy SSE server (protocol version 2024-11-05)
338338
npx tsx src/examples/server/simpleSseServer.ts
339339

340-
# Streamable HTTP server (protocol version 2025-03-26)
340+
# Streamable HTTP server (protocol version 2025-11-25)
341341
npx tsx src/examples/server/simpleStreamableHttp.ts
342342

343343
# Backwards compatible server (supports both protocols)

src/examples/server/jsonResponseStreamableHttp.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ const getServer = () => {
2121
);
2222

2323
// Register a simple tool that returns a greeting
24-
server.tool(
24+
server.registerTool(
2525
'greet',
26-
'A simple greeting tool',
2726
{
28-
name: z.string().describe('Name to greet')
27+
description: 'A simple greeting tool',
28+
inputSchema: {
29+
name: z.string().describe('Name to greet')
30+
}
2931
},
3032
async ({ name }): Promise<CallToolResult> => {
3133
return {
@@ -40,11 +42,13 @@ const getServer = () => {
4042
);
4143

4244
// Register a tool that sends multiple greetings with notifications
43-
server.tool(
45+
server.registerTool(
4446
'multi-greet',
45-
'A tool that sends different greetings with delays between them',
4647
{
47-
name: z.string().describe('Name to greet')
48+
description: 'A tool that sends different greetings with delays between them',
49+
inputSchema: {
50+
name: z.string().describe('Name to greet')
51+
}
4852
},
4953
async ({ name }, extra): Promise<CallToolResult> => {
5054
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

src/examples/server/simpleSseServer.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ const getServer = () => {
2525
{ capabilities: { logging: {} } }
2626
);
2727

28-
server.tool(
28+
server.registerTool(
2929
'start-notification-stream',
30-
'Starts sending periodic notifications',
3130
{
32-
interval: z.number().describe('Interval in milliseconds between notifications').default(1000),
33-
count: z.number().describe('Number of notifications to send').default(10)
31+
description: 'Starts sending periodic notifications',
32+
inputSchema: {
33+
interval: z.number().describe('Interval in milliseconds between notifications').default(1000),
34+
count: z.number().describe('Number of notifications to send').default(10)
35+
}
3436
},
3537
async ({ interval, count }, extra): Promise<CallToolResult> => {
3638
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

src/examples/server/simpleStatelessStreamableHttp.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ const getServer = () => {
1616
);
1717

1818
// Register a simple prompt
19-
server.prompt(
19+
server.registerPrompt(
2020
'greeting-template',
21-
'A simple greeting prompt template',
2221
{
23-
name: z.string().describe('Name to include in greeting')
22+
description: 'A simple greeting prompt template',
23+
argsSchema: {
24+
name: z.string().describe('Name to include in greeting')
25+
}
2426
},
2527
async ({ name }): Promise<GetPromptResult> => {
2628
return {
@@ -38,12 +40,14 @@ const getServer = () => {
3840
);
3941

4042
// Register a tool specifically for testing resumability
41-
server.tool(
43+
server.registerTool(
4244
'start-notification-stream',
43-
'Starts sending periodic notifications for testing resumability',
4445
{
45-
interval: z.number().describe('Interval in milliseconds between notifications').default(100),
46-
count: z.number().describe('Number of notifications to send (0 for 100)').default(10)
46+
description: 'Starts sending periodic notifications for testing resumability',
47+
inputSchema: {
48+
interval: z.number().describe('Interval in milliseconds between notifications').default(100),
49+
count: z.number().describe('Number of notifications to send (0 for 100)').default(10)
50+
}
4751
},
4852
async ({ interval, count }, extra): Promise<CallToolResult> => {
4953
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
@@ -78,7 +82,7 @@ const getServer = () => {
7882
);
7983

8084
// Create a simple resource at a fixed URI
81-
server.resource(
85+
server.registerResource(
8286
'greeting-resource',
8387
'https://example.com/greetings/default',
8488
{ mimeType: 'text/plain' },

src/examples/server/simpleStreamableHttp.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,18 @@ const getServer = () => {
6767
);
6868

6969
// Register a tool that sends multiple greetings with notifications (with annotations)
70-
server.tool(
70+
server.registerTool(
7171
'multi-greet',
72-
'A tool that sends different greetings with delays between them',
73-
{
74-
name: z.string().describe('Name to greet')
75-
},
7672
{
77-
title: 'Multiple Greeting Tool',
78-
readOnlyHint: true,
79-
openWorldHint: false
73+
description: 'A tool that sends different greetings with delays between them',
74+
inputSchema: {
75+
name: z.string().describe('Name to greet')
76+
},
77+
annotations: {
78+
title: 'Multiple Greeting Tool',
79+
readOnlyHint: true,
80+
openWorldHint: false
81+
}
8082
},
8183
async ({ name }, extra): Promise<CallToolResult> => {
8284
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
@@ -121,11 +123,13 @@ const getServer = () => {
121123
);
122124
// Register a tool that demonstrates form elicitation (user input collection with a schema)
123125
// This creates a closure that captures the server instance
124-
server.tool(
126+
server.registerTool(
125127
'collect-user-info',
126-
'A tool that collects user information through form elicitation',
127128
{
128-
infoType: z.enum(['contact', 'preferences', 'feedback']).describe('Type of information to collect')
129+
description: 'A tool that collects user information through form elicitation',
130+
inputSchema: {
131+
infoType: z.enum(['contact', 'preferences', 'feedback']).describe('Type of information to collect')
132+
}
129133
},
130134
async ({ infoType }, extra): Promise<CallToolResult> => {
131135
let message: string;
@@ -302,12 +306,14 @@ const getServer = () => {
302306
);
303307

304308
// Register a tool specifically for testing resumability
305-
server.tool(
309+
server.registerTool(
306310
'start-notification-stream',
307-
'Starts sending periodic notifications for testing resumability',
308311
{
309-
interval: z.number().describe('Interval in milliseconds between notifications').default(100),
310-
count: z.number().describe('Number of notifications to send (0 for 100)').default(50)
312+
description: 'Starts sending periodic notifications for testing resumability',
313+
inputSchema: {
314+
interval: z.number().describe('Interval in milliseconds between notifications').default(100),
315+
count: z.number().describe('Number of notifications to send (0 for 100)').default(50)
316+
}
311317
},
312318
async ({ interval, count }, extra): Promise<CallToolResult> => {
313319
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

src/examples/server/sseAndStreamableHttpCompatibleServer.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { createMcpExpressApp } from '../../server/express.js';
1111
/**
1212
* This example server demonstrates backwards compatibility with both:
1313
* 1. The deprecated HTTP+SSE transport (protocol version 2024-11-05)
14-
* 2. The Streamable HTTP transport (protocol version 2025-03-26)
14+
* 2. The Streamable HTTP transport (protocol version 2025-11-25)
1515
*
1616
* It maintains a single MCP server instance but exposes two transport options:
1717
* - /mcp: The new Streamable HTTP endpoint (supports GET/POST/DELETE)
@@ -29,12 +29,14 @@ const getServer = () => {
2929
);
3030

3131
// Register a simple tool that sends notifications over time
32-
server.tool(
32+
server.registerTool(
3333
'start-notification-stream',
34-
'Starts sending periodic notifications for testing resumability',
3534
{
36-
interval: z.number().describe('Interval in milliseconds between notifications').default(100),
37-
count: z.number().describe('Number of notifications to send (0 for 100)').default(50)
35+
description: 'Starts sending periodic notifications for testing resumability',
36+
inputSchema: {
37+
interval: z.number().describe('Interval in milliseconds between notifications').default(100),
38+
count: z.number().describe('Number of notifications to send (0 for 100)').default(50)
39+
}
3840
},
3941
async ({ interval, count }, extra): Promise<CallToolResult> => {
4042
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
@@ -77,7 +79,7 @@ const app = createMcpExpressApp();
7779
const transports: Record<string, StreamableHTTPServerTransport | SSEServerTransport> = {};
7880

7981
//=============================================================================
80-
// STREAMABLE HTTP TRANSPORT (PROTOCOL VERSION 2025-03-26)
82+
// STREAMABLE HTTP TRANSPORT (PROTOCOL VERSION 2025-11-25)
8183
//=============================================================================
8284

8385
// Handle all MCP Streamable HTTP requests (GET, POST, DELETE) on a single endpoint
@@ -214,10 +216,10 @@ app.listen(PORT, error => {
214216
==============================================
215217
SUPPORTED TRANSPORT OPTIONS:
216218
217-
1. Streamable Http(Protocol version: 2025-03-26)
219+
1. Streamable Http(Protocol version: 2025-11-25)
218220
Endpoint: /mcp
219221
Methods: GET, POST, DELETE
220-
Usage:
222+
Usage:
221223
- Initialize with POST to /mcp
222224
- Establish SSE stream with GET to /mcp
223225
- Send requests with POST to /mcp

src/examples/server/standaloneSseWithGetStreamableHttp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const transports: { [sessionId: string]: StreamableHTTPServerTransport } = {};
1616

1717
const addResource = (name: string, content: string) => {
1818
const uri = `https://mcp-example.com/dynamic/${encodeURIComponent(name)}`;
19-
server.resource(
19+
server.registerResource(
2020
name,
2121
uri,
2222
{ mimeType: 'text/plain', description: `Dynamic resource: ${name}` },

0 commit comments

Comments
 (0)