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 <mkisiel@google.com>
This commit is contained in:
Steven Chen 2026-03-18 09:57:45 +00:00 • committed by GitHub
commit 48879f01c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View file

@ -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))

View file

@ -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
}