@@ -8,7 +8,7 @@ This directory contains examples of how to use the Model Context Protocol (MCP)
8
8
A simple server that communicates over standard input/output. This is useful for desktop applications and command-line tools.
9
9
10
10
** Usage:**
11
- ``` bash
11
+ ``` console
12
12
$ ruby examples/stdio_server.rb
13
13
{"jsonrpc":"2.0","id":0,"method":"tools/list"}
14
14
```
@@ -24,7 +24,7 @@ A standalone HTTP server built with Rack that implements the MCP Streamable HTTP
24
24
- Full MCP protocol compliance
25
25
26
26
** Usage:**
27
- ``` bash
27
+ ``` console
28
28
$ ruby examples/http_server.rb
29
29
```
30
30
@@ -40,12 +40,12 @@ A client that demonstrates how to interact with the HTTP server using all MCP pr
40
40
41
41
** Usage:**
42
42
1 . Start the HTTP server in one terminal:
43
- ``` bash
43
+ ``` console
44
44
$ ruby examples/http_server.rb
45
45
```
46
46
47
47
2 . Run the client example in another terminal:
48
- ``` bash
48
+ ``` console
49
49
$ ruby examples/http_client.rb
50
50
```
51
51
@@ -70,7 +70,7 @@ A specialized HTTP server designed to test and demonstrate Server-Sent Events (S
70
70
- ` echo ` - Simple echo tool for basic testing
71
71
72
72
** Usage:**
73
- ``` bash
73
+ ``` console
74
74
$ ruby examples/streamable_http_server.rb
75
75
```
76
76
@@ -87,12 +87,12 @@ An interactive client that connects to the SSE stream and provides a menu-driven
87
87
88
88
** Usage:**
89
89
1 . Start the SSE test server in one terminal:
90
- ``` bash
90
+ ``` console
91
91
$ ruby examples/streamable_http_server.rb
92
92
```
93
93
94
94
2 . Run the SSE test client in another terminal:
95
- ``` bash
95
+ ``` console
96
96
$ ruby examples/streamable_http_client.rb
97
97
```
98
98
@@ -107,19 +107,19 @@ The client will:
107
107
You can also test SSE functionality manually using cURL:
108
108
109
109
1 . Initialize a session:
110
- ``` bash
110
+ ``` console
111
111
SESSION_ID=$(curl -D - -s -o /dev/null -X POST http://localhost:9393 \
112
112
-H "Content-Type: application/json" \
113
113
-d '{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"curl-test","version":"1.0"}}}' | grep -i "Mcp-Session-Id:" | cut -d' ' -f2- | tr -d '\r')
114
114
```
115
115
116
116
2 . Connect to SSE stream (in one terminal):
117
- ``` bash
117
+ ``` console
118
118
curl -i -N -H "Mcp-Session-Id: $SESSION_ID" http://localhost:9393
119
119
```
120
120
121
121
3 . Trigger notifications (in another terminal):
122
- ``` bash
122
+ ``` console
123
123
# Send immediate notification
124
124
curl -i -X POST http://localhost:9393 \
125
125
-H "Content-Type: application/json" \
@@ -151,22 +151,22 @@ The HTTP server implements the MCP Streamable HTTP transport protocol:
151
151
### Example cURL Commands
152
152
153
153
Initialize a session:
154
- ``` bash
154
+ ``` console
155
155
curl -i -X POST http://localhost:9292 \
156
156
-H "Content-Type: application/json" \
157
157
-d '{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'
158
158
```
159
159
160
160
List tools (using the session ID from initialization):
161
- ``` bash
161
+ ``` console
162
162
curl -i -X POST http://localhost:9292 \
163
163
-H "Content-Type: application/json" \
164
164
-H "Mcp-Session-Id: YOUR_SESSION_ID" \
165
165
-d '{"jsonrpc":"2.0","method":"tools/list","id":2}'
166
166
```
167
167
168
168
Call a tool:
169
- ``` bash
169
+ ``` console
170
170
curl -i -X POST http://localhost:9292 \
171
171
-H "Content-Type: application/json" \
172
172
-H "Mcp-Session-Id: YOUR_SESSION_ID" \
0 commit comments