Skip to content

Commit 0c1a4f2

Browse files
committed
add get sse to README
1 parent 111586c commit 0c1a4f2

File tree

1 file changed

+57
-40
lines changed

1 file changed

+57
-40
lines changed

src/examples/README.md

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,37 @@
22

33
This directory contains example implementations of MCP clients and servers using the TypeScript SDK.
44

5+
## Table of Contents
6+
7+
- [Streamable HTTP Servers - Single Node Deployment](#streamable-http---single-node-deployment-with-basic-session-state-management)
8+
- [Simple Server with Streamable HTTP](#simple-server-with-streamable-http-transport-serversimplestreamablehttpts)
9+
- [Server Supporting SSE via GET](#server-supporting-with-sse-via-get-serverstandalonessewithgetstreamablehttpts)
10+
- [Server with JSON Response Mode](#server-with-json-response-mode-serverjsonresponsestreamablehttpts)
11+
- [Client Example - Streamable HTTP](#client-clientsimplestreamablehttpts)
12+
513
## Streamable HTTP - single node deployment with basic session state management
614

7-
Multi node with stete management example will be added soon after we add support.
15+
Multi node with state management example will be added soon after we add support.
816

9-
### Server with JSON response mode (`server/jsonResponseStreamableHttp.ts`)
1017

11-
A simple MCP server that uses the Streamable HTTP transport with JSON response mode enabled, implemented with Express. The server provides a simple `greet` tool that returns a greeting for a name.
18+
### Simple Server with Streamable Http transport (`server/simpleStreamableHttp.ts`)
19+
20+
A simple MCP server that uses the Streamable HTTP transport, implemented with Express. The server provides:
21+
22+
- A simple `greet` tool that returns a greeting for a name
23+
- A `greeting-template` prompt that generates a greeting template
24+
- A static `greeting-resource` resource
1225

1326
#### Running the server
1427

1528
```bash
16-
npx tsx src/examples/server/jsonResponseStreamableHttp.ts
29+
npx tsx src/examples/server/simpleStreamableHttp.ts
1730
```
1831

19-
The server will start on port 3000. You can test the initialization and tool calling:
32+
The server will start on port 3000. You can test the initialization and tool listing:
2033

2134
```bash
22-
# Initialize the server and get the session ID from headers
35+
# First initialize the server and save the session ID to a variable
2336
SESSION_ID=$(curl -X POST \
2437
-H "Content-Type: application/json" \
2538
-H "Accept: application/json" \
@@ -38,48 +51,42 @@ SESSION_ID=$(curl -X POST \
3851
"id": "1"
3952
}' \
4053
-i http://localhost:3000/mcp 2>&1 | grep -i "mcp-session-id" | cut -d' ' -f2 | tr -d '\r')
41-
echo "Session ID: $SESSION_ID"
54+
echo "Session ID: $SESSION_ID
4255
43-
# Call the greet tool using the saved session ID
44-
curl -X POST \
45-
-H "Content-Type: application/json" \
46-
-H "Accept: application/json" \
47-
-H "Accept: text/event-stream" \
56+
# Then list tools using the saved session ID
57+
curl -X POST -H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" \
4858
-H "mcp-session-id: $SESSION_ID" \
49-
-d '{
50-
"jsonrpc": "2.0",
51-
"method": "tools/call",
52-
"params": {
53-
"name": "greet",
54-
"arguments": {
55-
"name": "World"
56-
}
57-
},
58-
"id": "2"
59-
}' \
59+
-d '{"jsonrpc":"2.0","method":"tools/list","params":{},"id":"2"}' \
6060
http://localhost:3000/mcp
6161
```
6262
63-
Note that in this example, we're using plain JSON response mode by setting `Accept: application/json` header.
63+
### Server supporting with SSE via GET (`server/standaloneSseWithGetStreamableHttp.ts`)
6464
65-
### Server (`server/simpleStreamableHttp.ts`)
65+
An MCP server that demonstrates how to support SSE notifications via GET requests using the Streamable HTTP transport with Express. The server dynamically adds resources at regular intervals and supports notifications for resource list changes (server notifications are available through the standalone SSE connection established by GET request).
6666
67-
A simple MCP server that uses the Streamable HTTP transport, implemented with Express. The server provides:
67+
#### Running the server
6868
69-
- A simple `greet` tool that returns a greeting for a name
70-
- A `greeting-template` prompt that generates a greeting template
71-
- A static `greeting-resource` resource
69+
```bash
70+
npx tsx src/examples/server/standaloneSseWithGetStreamableHttp.ts
71+
```
72+
73+
The server will start on port 3000 and automatically create new resources every 5 seconds.
74+
75+
### Server with JSON response mode (`server/jsonResponseStreamableHttp.ts`)
76+
77+
This is not recommented way to use the transport, as its quite limiting and not supporting features like logging and progress notifications on tool execution.
78+
A simple MCP server that uses the Streamable HTTP transport with JSON response mode enabled, implemented with Express. The server provides a simple `greet` tool that returns a greeting for a name.
7279
7380
#### Running the server
7481
7582
```bash
76-
npx tsx src/examples/server/simpleStreamableHttp.ts
83+
npx tsx src/examples/server/jsonResponseStreamableHttp.ts
7784
```
7885
79-
The server will start on port 3000. You can test the initialization and tool listing:
86+
The server will start on port 3000. You can test the initialization and tool calling:
8087
8188
```bash
82-
# First initialize the server and save the session ID to a variable
89+
# Initialize the server and get the session ID from headers
8390
SESSION_ID=$(curl -X POST \
8491
-H "Content-Type: application/json" \
8592
-H "Accept: application/json" \
@@ -98,15 +105,29 @@ SESSION_ID=$(curl -X POST \
98105
"id": "1"
99106
}' \
100107
-i http://localhost:3000/mcp 2>&1 | grep -i "mcp-session-id" | cut -d' ' -f2 | tr -d '\r')
101-
echo "Session ID: $SESSION_ID
108+
echo "Session ID: $SESSION_ID"
102109
103-
# Then list tools using the saved session ID
104-
curl -X POST -H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" \
110+
# Call the greet tool using the saved session ID
111+
curl -X POST \
112+
-H "Content-Type: application/json" \
113+
-H "Accept: application/json" \
114+
-H "Accept: text/event-stream" \
105115
-H "mcp-session-id: $SESSION_ID" \
106-
-d '{"jsonrpc":"2.0","method":"tools/list","params":{},"id":"2"}' \
116+
-d '{
117+
"jsonrpc": "2.0",
118+
"method": "tools/call",
119+
"params": {
120+
"name": "greet",
121+
"arguments": {
122+
"name": "World"
123+
}
124+
},
125+
"id": "2"
126+
}' \
107127
http://localhost:3000/mcp
108128
```
109129
130+
110131
### Client (`client/simpleStreamableHttp.ts`)
111132
112133
A client that connects to the server, initializes it, and demonstrates how to:
@@ -123,8 +144,4 @@ npx tsx src/examples/client/simpleStreamableHttp.ts
123144
124145
Make sure the server is running before starting the client.
125146
126-
## Notes
127147
128-
- These examples demonstrate the basic usage of the Streamable HTTP transport
129-
- The server manages sessions between the calls
130-
- The client handles both direct HTTP responses and SSE streaming responses

0 commit comments

Comments
 (0)