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
MCP servers can send logging messages to MCP clients.
454
+
(This form of logging is distinct from server-side logging, where the
455
+
server produces logs that remain server-side, for use by server maintainers.)
456
+
457
+
**Server-side**:
458
+
The minimum log level is part of the server state.
459
+
For stateful sessions, there is no default log level: no log messages will be sent
460
+
until the client calls `SetLevel` (see below).
461
+
For stateful sessions, the level defaults to "info".
462
+
463
+
[`ServerSession.Log`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerSession.Log) is the low-level way for servers to log to clients.
464
+
It sends a logging notification to the client if the level of the message
465
+
is at least the minimum log level.
466
+
467
+
For a simpler API, use [`NewLoggingHandler`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#NewLoggingHandler) to obtain a [`slog.Handler`](https://pkg.go.dev/log/slog#Handler).
468
+
By setting [`LoggingHandlerOptions.MinInterval`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#LoggingHandlerOptions.MinInterval), the handler can be rate-limited
469
+
to avoid spamming clients with too many messages.
470
+
471
+
Servers always report the logging capability.
472
+
473
+
474
+
**Client-side**:
475
+
Set [`ClientOptions.LoggingMessageHandler`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientOptions.LoggingMessageHandler) to receive log messages.
476
+
477
+
Call [`ClientSession.SetLevel`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientSession.SetLevel) to change the log level for a session.
Copy file name to clipboardExpand all lines: internal/docs/server.src.md
+27-1Lines changed: 27 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -215,7 +215,33 @@ requests.
215
215
216
216
### Logging
217
217
218
-
<!-- TODO -->
218
+
MCP servers can send logging messages to MCP clients.
219
+
(This form of logging is distinct from server-side logging, where the
220
+
server produces logs that remain server-side, for use by server maintainers.)
221
+
222
+
**Server-side**:
223
+
The minimum log level is part of the server state.
224
+
For stateful sessions, there is no default log level: no log messages will be sent
225
+
until the client calls `SetLevel` (see below).
226
+
For stateful sessions, the level defaults to "info".
227
+
228
+
[`ServerSession.Log`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerSession.Log) is the low-level way for servers to log to clients.
229
+
It sends a logging notification to the client if the level of the message
230
+
is at least the minimum log level.
231
+
232
+
For a simpler API, use [`NewLoggingHandler`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#NewLoggingHandler) to obtain a [`slog.Handler`](https://pkg.go.dev/log/slog#Handler).
233
+
By setting [`LoggingHandlerOptions.MinInterval`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#LoggingHandlerOptions.MinInterval), the handler can be rate-limited
234
+
to avoid spamming clients with too many messages.
235
+
236
+
Servers always report the logging capability.
237
+
238
+
239
+
**Client-side**:
240
+
Set [`ClientOptions.LoggingMessageHandler`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientOptions.LoggingMessageHandler) to receive log messages.
241
+
242
+
Call [`ClientSession.SetLevel`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientSession.SetLevel) to change the log level for a session.
0 commit comments