You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/README.md
+38-15Lines changed: 38 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,41 +5,50 @@ This directory contains examples of how to use the Model Context Protocol (MCP)
5
5
## Available Examples
6
6
7
7
### 1. STDIO Server (`stdio_server.rb`)
8
+
8
9
A simple server that communicates over standard input/output. This is useful for desktop applications and command-line tools.
9
10
10
11
**Usage:**
12
+
11
13
```console
12
14
$ ruby examples/stdio_server.rb
13
15
{"jsonrpc":"2.0","id":0,"method":"tools/list"}
14
16
```
15
17
16
18
### 2. HTTP Server (`http_server.rb`)
19
+
17
20
A standalone HTTP server built with Rack that implements the MCP Streamable HTTP transport protocol. This demonstrates how to create a web-based MCP server with session management and Server-Sent Events (SSE) support.
18
21
19
22
**Features:**
23
+
20
24
- HTTP transport with Server-Sent Events (SSE) for streaming
21
25
- Session management with unique session IDs
22
26
- Example tools, prompts, and resources
23
27
- JSON-RPC 2.0 protocol implementation
24
28
- Full MCP protocol compliance
25
29
26
30
**Usage:**
31
+
27
32
```console
28
33
$ ruby examples/http_server.rb
29
34
```
30
35
31
36
The server will start on `http://localhost:9292` and provide:
37
+
32
38
-**Tools**:
33
39
-`ExampleTool` - adds two numbers
34
40
-`echo` - echoes back messages
35
41
-**Prompts**: `ExamplePrompt` - echoes back arguments as a prompt
36
42
-**Resources**: `test_resource` - returns example content
37
43
38
44
### 3. HTTP Client Example (`http_client.rb`)
45
+
39
46
A client that demonstrates how to interact with the HTTP server using all MCP protocol methods.
40
47
41
48
**Usage:**
49
+
42
50
1. Start the HTTP server in one terminal:
51
+
43
52
```console
44
53
$ ruby examples/http_server.rb
45
54
```
@@ -50,6 +59,7 @@ A client that demonstrates how to interact with the HTTP server using all MCP pr
50
59
```
51
60
52
61
The client will demonstrate:
62
+
53
63
- Session initialization
54
64
- Ping requests
55
65
- Listing and calling tools
@@ -58,35 +68,43 @@ The client will demonstrate:
58
68
- Session cleanup
59
69
60
70
### 4. Streamable HTTP Server (`streamable_http_server.rb`)
71
+
61
72
A specialized HTTP server designed to test and demonstrate Server-Sent Events (SSE) functionality in the MCP protocol.
62
73
63
74
**Features:**
75
+
64
76
- Tools specifically designed to trigger SSE notifications
65
77
- Real-time progress updates and notifications
66
78
- Detailed SSE-specific logging
67
79
68
80
**Available Tools:**
81
+
69
82
-`NotificationTool` - Send custom SSE notifications with optional delays
70
83
-`echo` - Simple echo tool for basic testing
71
84
72
85
**Usage:**
86
+
73
87
```console
74
88
$ ruby examples/streamable_http_server.rb
75
89
```
76
90
77
91
The server will start on `http://localhost:9393` and provide detailed instructions for testing SSE functionality.
0 commit comments