MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / Log

Method Log

mcp/server.go:1312–1326  ·  view source on GitHub ↗

Log sends a log message to the client. The message is not sent if the client has not called SetLevel, or if its level is below that of the last SetLevel.

(ctx context.Context, params *LoggingMessageParams)

Source from the content-addressed store, hash-verified

1310// The message is not sent if the client has not called SetLevel, or if its level
1311// is below that of the last SetLevel.
1312func (ss *ServerSession) Log(ctx context.Context, params *LoggingMessageParams) error {
1313 ss.mu.Lock()
1314 logLevel := ss.state.LogLevel
1315 ss.mu.Unlock()
1316 if logLevel == "" {
1317 // The spec is unclear, but seems to imply that no log messages are sent until the client
1318 // sets the level.
1319 // TODO(jba): read other SDKs, possibly file an issue.
1320 return nil
1321 }
1322 if compareLevels(params.Level, logLevel) < 0 {
1323 return nil
1324 }
1325 return handleNotify(ctx, notificationLoggingMessage, newServerRequest(ss, orZero[Params](params)))
1326}
1327
1328// AddSendingMiddleware wraps the current sending method handler using the provided
1329// middleware. Middleware is applied from right to left, so that the first one is

Callers 12

TestAuthorizeFunction · 0.80
handleMethod · 0.80
TestEndToEndFunction · 0.80
testClientReplayFunction · 0.80
TestStreamableGETFunction · 0.80
TestServerInterruptFunction · 0.80
childFunction · 0.80
loggingToolFunction · 0.80

Calls 3

compareLevelsFunction · 0.85
handleNotifyFunction · 0.85
newServerRequestFunction · 0.85

Tested by 8

TestAuthorizeFunction · 0.64
TestEndToEndFunction · 0.64
testClientReplayFunction · 0.64
TestStreamableGETFunction · 0.64
TestServerInterruptFunction · 0.64