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: README.md
+77-1Lines changed: 77 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,6 +113,7 @@ The server provides three notification methods:
113
113
-`notify_tools_list_changed` - Send a notification when the tools list changes
114
114
-`notify_prompts_list_changed` - Send a notification when the prompts list changes
115
115
-`notify_resources_list_changed` - Send a notification when the resources list changes
116
+
-`notify_log_message` - Send a structured logging notification message
116
117
117
118
#### Notification Format
118
119
@@ -121,6 +122,82 @@ Notifications follow the JSON-RPC 2.0 specification and use these method names:
121
122
-`notifications/tools/list_changed`
122
123
-`notifications/prompts/list_changed`
123
124
-`notifications/resources/list_changed`
125
+
-`notifications/message`
126
+
127
+
### Logging
128
+
129
+
The MCP Ruby SDK supports structured logging through the `notify_log_message` method, following the [MCP Logging specification](https://modelcontextprotocol.io/specification/latest/server/utilities/logging).
130
+
131
+
The `notifications/message` notification is used for structured logging between client and server.
132
+
133
+
#### Log Levels
134
+
135
+
The SDK supports 8 log levels with increasing severity:
136
+
137
+
-`debug` - Detailed debugging information
138
+
-`info` - General informational messages
139
+
-`notice` - Normal but significant events
140
+
-`warning` - Warning conditions
141
+
-`error` - Error conditions
142
+
-`critical` - Critical conditions
143
+
-`alert` - Action must be taken immediately
144
+
-`emergency` - System is unusable
145
+
146
+
#### How Logging Works
147
+
148
+
1.**Client Configuration**: The client sends a `logging/setLevel` request to configure the minimum log level
149
+
2.**Server Filtering**: The server only sends log messages at the configured level or higher severity
150
+
3.**Notification Delivery**: Log messages are sent as `notifications/message` to the client
151
+
152
+
For example, if the client sets the level to `"error"` (severity 4), the server will send messages with levels: `error`, `critical`, `alert`, and `emergency`.
153
+
154
+
For more details, see the [MCP Logging specification](https://modelcontextprotocol.io/specification/latest/server/utilities/logging).
155
+
156
+
**Usage Example:**
157
+
158
+
```ruby
159
+
server =MCP::Server.new(name:"my_server")
160
+
transport =MCP::Server::Transports::StdioTransport.new(server)
161
+
server.transport = transport
162
+
163
+
# The client first configures the logging level (on the client side):
164
+
transport.send_request(
165
+
request: {
166
+
jsonrpc:"2.0",
167
+
method:"logging/setLevel",
168
+
params: { level:"info" },
169
+
id: session_id # Unique request ID within the session
170
+
}
171
+
)
172
+
173
+
# Send log messages at different severity levels
174
+
server.notify_log_message(
175
+
data: { message:"Application started successfully" },
176
+
level:"info"
177
+
)
178
+
179
+
server.notify_log_message(
180
+
data: { message:"Configuration file not found, using defaults" },
181
+
level:"warning"
182
+
)
183
+
184
+
server.notify_log_message(
185
+
data: {
186
+
error:"Database connection failed",
187
+
details: { host:"localhost", port:5432 }
188
+
},
189
+
level:"error",
190
+
logger:"DatabaseLogger"# Optional logger name
191
+
)
192
+
```
193
+
194
+
**Key Features:**
195
+
196
+
- Supports 8 log levels (debug, info, notice, warning, error, critical, alert, emergency) based on https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/logging#log-levels
197
+
- Server has capability `logging` to send log messages
198
+
- Messages are only sent if a transport is configured
199
+
- Messages are filtered based on the client's configured log level
200
+
- If the log level hasn't been set by the client, no messages will be sent
124
201
125
202
#### Transport Support
126
203
@@ -153,7 +230,6 @@ transport = MCP::Server::Transports::StreamableHTTPTransport.new(server, statele
153
230
154
231
### Unsupported Features (to be implemented in future versions)
0 commit comments