mcp: add support for logging level (SEP-2575) (#997)

## Description

This PR adds the support for logging feature in meta.

Fixes #966
This commit is contained in:
Guglielmo Colombo 2026-06-08 15:56:38 +02:00 • committed by GitHub
commit 00d3642840
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -498,6 +498,7 @@ func extractRequestMeta(rawParams json.RawMessage) Meta {
type validatedMeta struct {
usesNewProtocol bool
initializeParams *InitializeParams
logLevel LoggingLevel
}
// validateRequestMeta inspects a JSON-RPC request to detect whether it follows
@ -518,8 +519,7 @@ func validateRequestMeta(req *jsonrpc.Request) (*validatedMeta, error) {
if !ok {
return &validatedMeta{usesNewProtocol: false, initializeParams: nil}, nil
}
// Notifications do not carry full client identity. In new protocol, only cancel notification
// is allowed in STDIO.
// Notifications do not carry full client identity.
if !req.IsCall() {
return &validatedMeta{usesNewProtocol: true, initializeParams: nil}, nil
}
@ -537,11 +537,12 @@ func validateRequestMeta(req *jsonrpc.Request) (*validatedMeta, error) {
Message: fmt.Sprintf("missing or invalid _meta field %q", MetaKeyClientCapabilities),
}
}
logLevel, _ := decodeMetaValue[LoggingLevel](meta, MetaKeyLogLevel)
return &validatedMeta{usesNewProtocol: true, initializeParams: &InitializeParams{
ProtocolVersion: protocolVersion,
Capabilities: capabilities,
ClientInfo: clientInfo,
}}, nil
}, logLevel: logLevel}, nil
}
// A Request is a method request with parameters and additional information, such as the session.