From 48879f01c9ca2195ce64b062ab95bc5770f6b9ec Mon Sep 17 00:00:00 2001 From: Steven Chen Date: Wed, 18 Mar 2026 09:57:45 +0000 Subject: [PATCH] mcp: fix setProgressToken when Meta is nil (#846) When `SetProgressToken` is called on a `Params` struct with a nil `Meta` field, the newly created map is never assigned back to the struct via `SetMeta`, causing the progress token to be silently lost. Call `p.SetMeta(m)` after creating the new map so the struct retains the reference. Fixes #845 Co-authored-by: Maciej Kisiel --- mcp/protocol_test.go | 10 ++++++++++ mcp/shared.go | 1 + 2 files changed, 11 insertions(+) diff --git a/mcp/protocol_test.go b/mcp/protocol_test.go index 20f2bb8..751d081 100644 --- a/mcp/protocol_test.go +++ b/mcp/protocol_test.go @@ -64,6 +64,16 @@ func TestParamsMeta(t *testing.T) { t.Errorf("got %v, want `t`", g) } + // The GetProgressToken and SetProgressToken methods work on a params struct that doesn't have a Meta field. + if g := p2.GetProgressToken(); g != nil { + t.Errorf("got %v, want nil", g) + } + + p2.SetProgressToken("t") + if g := p2.GetProgressToken(); g != "t" { + t.Errorf("got %v, want `t`", g) + } + // You can set a progress token to an int, int32 or int64. p.SetProgressToken(int(1)) p.SetProgressToken(int32(1)) diff --git a/mcp/shared.go b/mcp/shared.go index f8c9250..5662b12 100644 --- a/mcp/shared.go +++ b/mcp/shared.go @@ -447,6 +447,7 @@ func setProgressToken(p Params, pt any) { m := p.GetMeta() if m == nil { m = map[string]any{} + p.SetMeta(m) } m[progressTokenKey] = pt }