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
+78-1Lines changed: 78 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,83 @@ 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/2025-06-18/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
+
| Level | Severity | Description |
138
+
|-------|----------|-------------|
139
+
|`debug`| 0 | Detailed debugging information |
140
+
|`info`| 1 | General informational messages |
141
+
|`notice`| 2 | Normal but significant events |
142
+
|`warning`| 3 | Warning conditions |
143
+
|`error`| 4 | Error conditions |
144
+
|`critical`| 5 | Critical conditions |
145
+
|`alert`| 6 | Action must be taken immediately |
146
+
|`emergency`| 7 | System is unusable |
147
+
148
+
#### How Logging Works
149
+
150
+
1.**Client Configuration**: The client sends a `logging/setLevel` request to configure the minimum log level
151
+
2.**Server Filtering**: The server only sends log messages at the configured level or higher severity
152
+
3.**Notification Delivery**: Log messages are sent as `notifications/message` to the client
153
+
154
+
For example, if the client sets the level to `"error"` (severity 4), the server will send messages with levels: `error`, `critical`, `alert`, and `emergency`.
155
+
156
+
For more details, see the [MCP Logging specification](https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/logging).
157
+
158
+
**Usage Example:**
159
+
160
+
```ruby
161
+
server =MCP::Server.new(name:"my_server")
162
+
transport =MCP::Server::Transports::StdioTransport.new(server)
163
+
server.transport = transport
164
+
165
+
# The client first configures the logging level (on the client side):
166
+
transport.send_request(
167
+
request: {
168
+
jsonrpc:"2.0",
169
+
method:"logging/setLevel",
170
+
params: { level:"info" },
171
+
id: session_id # Unique request ID within the session
172
+
}
173
+
)
174
+
175
+
# Send log messages at different severity levels
176
+
server.notify_log_message(
177
+
data: { message:"Application started successfully" },
178
+
level:"info"
179
+
)
180
+
181
+
server.notify_log_message(
182
+
data: { message:"Configuration file not found, using defaults" },
183
+
level:"warning"
184
+
)
185
+
186
+
server.notify_log_message(
187
+
data: {
188
+
error:"Database connection failed",
189
+
details: { host:"localhost", port:5432 }
190
+
},
191
+
level:"error",
192
+
logger:"DatabaseLogger"# Optional logger name
193
+
)
194
+
```
195
+
196
+
**Key Features:**
197
+
- 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
198
+
- Server has capability `logging` to send log messages
199
+
- Messages are only sent if a transport is configured
200
+
- Messages are filtered based on the client's configured log level
201
+
- If the log level hasn't been set by the client, no messages will be sent
0 commit comments