internal/mcp: add a test for complete mapping of CallToolParams fields

Add a test to verify that the toWireParams helper maps all fields of
CallToolParams.

Change-Id: I81c28791734d60c793c76809c6b93d27e78c3c36
Reviewed-on: https://go-review.googlesource.com/c/tools/+/677975
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
Rob Findley 2025-06-02 14:45:53 +00:00 • committed by Robert Findley
commit facec97821

View file

@ -7,6 +7,7 @@ package mcp
import (
"context"
"fmt"
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
@ -199,3 +200,28 @@ func TestClientPaginateVariousPageSizes(t *testing.T) {
})
}
}
func TestToWireParams(t *testing.T) {
// This test verifies that toWireParams maps all fields.
// The Meta and Arguments fields are not comparable, so can't be checked by
// this simple test. However, this test will fail if new fields are added,
// and not handled by toWireParams.
params := &CallToolParams[struct{}]{
Name: "tool",
}
wireParams, err := toWireParams(params)
if err != nil {
t.Fatal(err)
}
v := reflect.ValueOf(wireParams).Elem()
for i := range v.Type().NumField() {
f := v.Type().Field(i)
if f.Name == "Meta" || f.Name == "Arguments" {
continue // not comparable
}
fv := v.Field(i)
if fv.Interface() == reflect.Zero(f.Type).Interface() {
t.Fatalf("toWireParams: unmapped field %q", f.Name)
}
}
}