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
- Supports instrumentation callbacks for monitoring
78
+
79
+
**Usage Example:**
80
+
81
+
```ruby
82
+
# Client request
83
+
{
84
+
"jsonrpc": "2.0",
85
+
"id": 1,
86
+
"method": "add",
87
+
"params": { "a": 5, "b": 3 }
88
+
}
89
+
90
+
# Server response
91
+
{
92
+
"jsonrpc": "2.0",
93
+
"id": 1,
94
+
"result": 8
95
+
}
96
+
```
97
+
98
+
**Error Handling:**
99
+
100
+
- Raises `MCP::Server::MethodAlreadyDefinedError` if trying to override an existing method
101
+
- Supports the same exception reporting and instrumentation as standard methods
102
+
50
103
### Notifications
51
104
52
105
The server supports sending notifications to clients when lists of tools, prompts, or resources change. This enables real-time updates without polling.
53
106
54
107
#### Notification Methods
55
108
56
109
The server provides three notification methods:
110
+
57
111
-`notify_tools_list_changed()` - Send a notification when the tools list changes
58
112
-`notify_prompts_list_changed()` - Send a notification when the prompts list changes
59
113
-`notify_resources_list_changed()` - Send a notification when the resources list changes
60
114
61
115
#### Notification Format
62
116
63
117
Notifications follow the JSON-RPC 2.0 specification and use these method names:
118
+
64
119
-`notifications/tools/list_changed`
65
120
-`notifications/prompts/list_changed`
66
121
-`notifications/resources/list_changed`
@@ -212,11 +267,13 @@ server = MCP::Server.new(
212
267
The `server_context` is a user-defined hash that is passed into the server instance and made available to tools, prompts, and exception/instrumentation callbacks. It can be used to provide contextual information such as authentication state, user IDs, or request-specific data.
213
268
214
269
**Type:**
270
+
215
271
```ruby
216
272
server_context: { [String, Symbol] => Any }
217
273
```
218
274
219
275
**Example:**
276
+
220
277
```ruby
221
278
server =MCP::Server.new(
222
279
name:"my_server",
@@ -236,6 +293,7 @@ The exception reporter receives:
236
293
-`server_context`: The context hash provided to the server
0 commit comments