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

@ -21,6 +21,7 @@ func TestValidateRequestMeta(t *testing.T) {
isNotification bool
params any
wantUsesNew bool
wantLogLevel LoggingLevel
wantErrContains string
}{
{
@ -101,6 +102,35 @@ func TestValidateRequestMeta(t *testing.T) {
params: json.RawMessage(`{"_meta": "not an object", "name": "x"}`),
wantUsesNew: false,
},
{
name: "new protocol with logLevel",
method: methodCallTool,
params: map[string]any{
"_meta": map[string]any{
MetaKeyProtocolVersion: protocolVersion20260630,
MetaKeyClientInfo: map[string]any{"name": "c", "version": "1"},
MetaKeyClientCapabilities: map[string]any{},
MetaKeyLogLevel: "warning",
},
"name": "x",
},
wantUsesNew: true,
wantLogLevel: "warning",
},
{
name: "new protocol without logLevel",
method: methodCallTool,
params: map[string]any{
"_meta": map[string]any{
MetaKeyProtocolVersion: protocolVersion20260630,
MetaKeyClientInfo: map[string]any{"name": "c", "version": "1"},
MetaKeyClientCapabilities: map[string]any{},
},
"name": "x",
},
wantUsesNew: true,
wantLogLevel: "",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
@ -127,6 +157,9 @@ func TestValidateRequestMeta(t *testing.T) {
if usesNew != tc.wantUsesNew {
t.Errorf("usesNewProtocol = %v, want %v", usesNew, tc.wantUsesNew)
}
if vmeta != nil && vmeta.logLevel != tc.wantLogLevel {
t.Errorf("logLevel = %q, want %q", vmeta.logLevel, tc.wantLogLevel)
}
if tc.wantErrContains == "" {
if err != nil {
t.Errorf("unexpected error: %v", err)