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:
parent
8f11a86898
commit
7bfde44981
1 changed files with 17 additions and 22 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue