mcp: change tool handler design (#325)
Change the design of tool handlers by removing genericity from the common path. - `ToolHandler` gets the args as a `json.RawMessage`. Using Server.AddTool does no unmarshaling or schema validation. - `ToolHandlerFor`, installed with `AddTool`, are the only generic pieces. TODO: uncomment and fix some tests
This commit is contained in:
parent
79f063bc98
commit
32cf71de3a
1 changed files with 789 additions and 966 deletions
|
|
@ -24,9 +24,14 @@ func TestList(t *testing.T) {
|
|||
t.Run("tools", func(t *testing.T) {
|
||||
var wantTools []*mcp.Tool
|
||||
for _, name := range []string{"apple", "banana", "cherry"} {
|
||||
t := &mcp.Tool{Name: name, Description: name + " tool"}
|
||||
wantTools = append(wantTools, t)
|
||||
mcp.AddTool(server, t, SayHi)
|
||||
tt := &mcp.Tool{Name: name, Description: name + " tool"}
|
||||
mcp.AddTool(server, tt, SayHi)
|
||||
is, err := jsonschema.For[SayHiParams](nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tt.InputSchema = is
|
||||
wantTools = append(wantTools, tt)
|
||||
}
|
||||
t.Run("list", func(t *testing.T) {
|
||||
res, err := clientSession.ListTools(ctx, nil)
|
||||
|
|
|
|||
Loading…
Reference in a new issue