@@ -9,6 +9,7 @@ This directory contains example implementations of MCP clients and servers using
9
9
- [ Server Supporting SSE via GET] ( #server-supporting-with-sse-via-get-serverstandalonessewithgetstreamablehttpts )
10
10
- [ Server with JSON Response Mode] ( #server-with-json-response-mode-serverjsonresponsestreamablehttpts )
11
11
- [ Client Example - Streamable HTTP] ( #client-clientsimplestreamablehttpts )
12
+ - [ Useful bash commands for testing] ( #useful-commands-for-testing )
12
13
13
14
## Streamable HTTP - single node deployment with basic session state management
14
15
@@ -31,35 +32,6 @@ npx tsx src/examples/server/simpleStreamableHttp.ts
31
32
32
33
The server will start on port 3000. You can test the initialization and tool listing:
33
34
34
- ``` bash
35
- # First initialize the server and save the session ID to a variable
36
- SESSION_ID=$( curl -X POST \
37
- -H " Content-Type: application/json" \
38
- -H " Accept: application/json" \
39
- -H " Accept: text/event-stream" \
40
- -d ' {
41
- "jsonrpc": "2.0",
42
- "method": "initialize",
43
- "params": {
44
- "capabilities": {},
45
- "protocolVersion": "2025-03-26",
46
- "clientInfo": {
47
- "name": "test",
48
- "version": "1.0.0"
49
- }
50
- },
51
- "id": "1"
52
- }' \
53
- -i http://localhost:3000/mcp 2>&1 | grep -i " mcp-session-id" | cut -d' ' -f2 | tr -d ' \r' )
54
- echo " Session ID: $SESSION_ID
55
-
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" \
58
- -H " mcp-session-id: $SESSION_ID " \
59
- -d '{" jsonrpc" :" 2.0" ," method" :" tools/list" ," params" :{}," id" :" 2" }' \
60
- http://localhost:3000/mcp
61
- ` ` `
62
-
63
35
### Server supporting with SSE via GET (` server/standaloneSseWithGetStreamableHttp.ts ` )
64
36
65
37
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).
@@ -83,10 +55,31 @@ A simple MCP server that uses the Streamable HTTP transport with JSON response m
83
55
npx tsx src/examples/server/jsonResponseStreamableHttp.ts
84
56
```
85
57
86
- The server will start on port 3000. You can test the initialization and tool calling:
58
+
59
+ ### Client (` client/simpleStreamableHttp.ts ` )
60
+
61
+ A client that connects to the server, initializes it, and demonstrates how to:
62
+
63
+ - List available tools and call the ` greet ` tool
64
+ - List available prompts and get the ` greeting-template ` prompt
65
+ - List available resources
66
+
67
+ #### Running the client
68
+
69
+ ``` bash
70
+ npx tsx src/examples/client/simpleStreamableHttp.ts
71
+ ```
72
+
73
+ Make sure the server is running before starting the client.
74
+
75
+
76
+ ### Useful commands for testing
77
+
78
+ #### Initialize
79
+ Streamable HTTP transport requires to do the initialization first.
87
80
88
81
``` bash
89
- # Initialize the server and get the session ID from headers
82
+ # First initialize the server and save the session ID to a variable
90
83
SESSION_ID=$( curl -X POST \
91
84
-H " Content-Type: application/json" \
92
85
-H " Accept: application/json" \
@@ -105,8 +98,24 @@ SESSION_ID=$(curl -X POST \
105
98
"id": "1"
106
99
}' \
107
100
-i http://localhost:3000/mcp 2>&1 | grep -i " mcp-session-id" | cut -d' ' -f2 | tr -d ' \r' )
108
- echo " Session ID: $SESSION_ID "
101
+ echo " Session ID: $SESSION_ID
102
+
103
+ ` ` `
104
+
105
+ Once thre is a session we can send POST requests
106
+
107
+ # ### List tools
108
+ ` ` ` bash
109
+ # Then list tools using the saved session ID
110
+ curl -X POST -H " Content-Type: application/json" -H " Accept: application/json, text/event-stream" \
111
+ -H " mcp-session-id: $SESSION_ID " \
112
+ -d '{" jsonrpc" :" 2.0" ," method" :" tools/list" ," params" :{}," id" :" 2" }' \
113
+ http://localhost:3000/mcp
114
+ ` ` `
115
+
116
+ # ### Call tool
109
117
118
+ ` ` ` bash
110
119
# Call the greet tool using the saved session ID
111
120
curl -X POST \
112
121
-H " Content-Type: application/json" \
@@ -126,22 +135,3 @@ curl -X POST \
126
135
}' \
127
136
http://localhost:3000/mcp
128
137
` ` `
129
-
130
-
131
- # ## Client (`client/simpleStreamableHttp.ts`)
132
-
133
- A client that connects to the server, initializes it, and demonstrates how to:
134
-
135
- - List available tools and call the ` greet` tool
136
- - List available prompts and get the ` greeting-template` prompt
137
- - List available resources
138
-
139
- # ### Running the client
140
-
141
- ` ` ` bash
142
- npx tsx src/examples/client/simpleStreamableHttp.ts
143
- ` ` `
144
-
145
- Make sure the server is running before starting the client.
146
-
147
-
0 commit comments