mcp: statically type the server-side tool params (#378)

Introduce CallToolParamsRaw on the server side, so that tool handlers
see in the type system that a tool's arguments are a json.RawMessage.

Fixes #377.
This commit is contained in:
Jonathan Amsterdam 2025-08-30 08:16:06 -04:00 • committed by GitHub
commit 7bfde44981
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9,7 +9,6 @@ import (
"context"
"encoding/base64"
"encoding/gob"
"encoding/json"
"fmt"
"iter"
"maps"
@ -234,10 +233,9 @@ func toolForErr[In, Out any](t *Tool, h ToolHandlerFor[In, Out]) (*Tool, ToolHan
th := func(ctx context.Context, req *CallToolRequest) (*CallToolResult, error) {
// Unmarshal and validate args.
rawArgs := req.Params.Arguments.(json.RawMessage)
var in In
if rawArgs != nil {
if err := unmarshalSchema(rawArgs, inputResolved, &in); err != nil {
if req.Params.Arguments != nil {
if err := unmarshalSchema(req.Params.Arguments, inputResolved, &in); err != nil {
return nil, err
}
}