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

@ -494,7 +494,6 @@ func TestEndToEnd(t *testing.T) {
if result.Action != "accept" {
t.Errorf("got action %q, want %q", result.Action, "accept")
}
})
// Disconnect.
@ -1638,7 +1637,7 @@ func TestPointerArgEquivalence(t *testing.T) {
//
// We handle a few different types of results, to assert they behave the
// same in all cases.
AddTool(s, &Tool{Name: "pointer"}, func(_ context.Context, req *ServerRequest[*CallToolParams], in *input) (*CallToolResult, *output, error) {
AddTool(s, &Tool{Name: "pointer"}, func(_ context.Context, req *CallToolRequest, in *input) (*CallToolResult, *output, error) {
switch in.In {
case "":
return nil, nil, fmt.Errorf("must provide input")
@ -1652,7 +1651,7 @@ func TestPointerArgEquivalence(t *testing.T) {
panic("unreachable")
}
})
AddTool(s, &Tool{Name: "nonpointer"}, func(_ context.Context, req *ServerRequest[*CallToolParams], in input) (*CallToolResult, output, error) {
AddTool(s, &Tool{Name: "nonpointer"}, func(_ context.Context, req *CallToolRequest, in input) (*CallToolResult, output, error) {
switch in.In {
case "":
return nil, output{}, fmt.Errorf("must provide input")