internal/mcp: use RawMessage for tool args

Change the type of CallToolParams.Arguments to json.RawMessage.

Change-Id: Ief16ef261b9f41566a1a16efc60a9382a8d414eb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/672615
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Jonathan Amsterdam 2025-05-14 07:24:51 -04:00
commit bbd253ee4c

View file

@ -40,14 +40,8 @@ func NewTool[TReq any](name, description string, handler func(context.Context, *
panic(err)
}
wrapped := func(ctx context.Context, cc *ServerConnection, params *CallToolParams) (*CallToolResult, error) {
// For simplicity, just marshal and unmarshal the arguments.
// This could be avoided in the future.
rawArgs, err := json.Marshal(params.Arguments)
if err != nil {
return nil, err
}
var v TReq
if err := unmarshalSchema(rawArgs, schema, &v); err != nil {
if err := unmarshalSchema(params.Arguments, schema, &v); err != nil {
return nil, err
}
content, err := handler(ctx, cc, v)