Skip to content

Commit 6ce7550

Browse files
committed
Take any ToolHandlerFor
1 parent 2b323c2 commit 6ce7550

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pkg/toolsets/toolsets.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ func NewToolsetDoesNotExistError(name string) *ToolsetDoesNotExistError {
2929
}
3030

3131
type ServerTool struct {
32-
Tool mcp.Tool
33-
Handler mcp.ToolHandlerFor[map[string]any, any]
32+
Tool mcp.Tool
33+
RegisterFunc func(s *mcp.Server)
3434
}
3535

36-
func NewServerTool(tool mcp.Tool, handler mcp.ToolHandlerFor[map[string]any, any]) ServerTool {
37-
return ServerTool{Tool: tool, Handler: handler}
36+
func NewServerTool[In, Out any](tool mcp.Tool, handler mcp.ToolHandlerFor[In, Out]) ServerTool {
37+
return ServerTool{Tool: tool, RegisterFunc: func(s *mcp.Server) {
38+
mcp.AddTool(s, &tool, handler)
39+
}}
3840
}
3941

4042
type ServerResourceTemplate struct {
@@ -98,11 +100,11 @@ func (t *Toolset) RegisterTools(s *mcp.Server) {
98100
return
99101
}
100102
for _, tool := range t.readTools {
101-
mcp.AddTool(s, &tool.Tool, tool.Handler)
103+
tool.RegisterFunc(s)
102104
}
103105
if !t.readOnly {
104106
for _, tool := range t.writeTools {
105-
mcp.AddTool(s, &tool.Tool, tool.Handler)
107+
tool.RegisterFunc(s)
106108
}
107109
}
108110
}

0 commit comments

Comments
 (0)