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 so their users can keep informed of progress.
162
+
(This form of logging is distinct from server-side logging, where the
163
+
server produces logs that remain server-side, for use by server maintainers.)
164
+
165
+
**Server-side**:
166
+
The minimum log level is part of the server state.
167
+
For stateful sessions, there is no default log level: no log messages will be sent
168
+
until the client calls `SetLevel` (see below).
169
+
For stateful sessions, the level defaults to "info".
170
+
171
+
[`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.
172
+
It sends a logging notification to the client if the level of the message
173
+
is at least the minimum log level.
174
+
175
+
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).
176
+
By setting [`LoggingHandlerOptions.MinInterval`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#LoggingHandlerOptions.MinInterval), the handler can be rate-limited
177
+
to avoid spamming clients with too many messages.
178
+
179
+
Servers always report the logging capability.
180
+
181
+
182
+
**Client-side**:
183
+
184
+
Set [`ClientOptions.LoggingMessageHandler`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientOptions.LoggingMessageHandler) to receive log messages.
185
+
186
+
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
+28-1Lines changed: 28 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,34 @@ requests.
56
56
57
57
### Logging
58
58
59
-
<!-- TODO -->
59
+
MCP servers can send logging messages to MCP clients so their users can keep informed of progress.
60
+
(This form of logging is distinct from server-side logging, where the
61
+
server produces logs that remain server-side, for use by server maintainers.)
62
+
63
+
**Server-side**:
64
+
The minimum log level is part of the server state.
65
+
For stateful sessions, there is no default log level: no log messages will be sent
66
+
until the client calls `SetLevel` (see below).
67
+
For stateful sessions, the level defaults to "info".
68
+
69
+
[`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.
70
+
It sends a logging notification to the client if the level of the message
71
+
is at least the minimum log level.
72
+
73
+
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).
74
+
By setting [`LoggingHandlerOptions.MinInterval`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#LoggingHandlerOptions.MinInterval), the handler can be rate-limited
75
+
to avoid spamming clients with too many messages.
76
+
77
+
Servers always report the logging capability.
78
+
79
+
80
+
**Client-side**:
81
+
82
+
Set [`ClientOptions.LoggingMessageHandler`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientOptions.LoggingMessageHandler) to receive log messages.
83
+
84
+
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