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:
parent
6af642cc79
commit
48879f01c9
2 changed files with 11 additions and 0 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue