Skip to content

Commit f197a9f

Browse files
omgitsadsalmaleksiaSamMorrowDrums
authored
Add Tool Handler shim to RegisterFunc (#1536)
* Add tool handler shim to use server.AddTool instead of mcp.AddTool --- Co-authored-by: Ksenia Bobrova <[email protected]> Co-authored-by: Sam Morrow <[email protected]>
1 parent 8dac9b1 commit f197a9f

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

pkg/github/__toolsnaps__/get_me.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"title": "Get my user profile"
55
},
66
"description": "Get details of the authenticated GitHub user. Use this when a request is about the user's own profile for GitHub. Or when information is missing to build other tool calls.",
7-
"inputSchema": null,
7+
"inputSchema": {
8+
"type": "object"
9+
},
810
"name": "get_me"
911
}

pkg/github/context_tools.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ func GetMe(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Too
4343
Title: t("TOOL_GET_ME_USER_TITLE", "Get my user profile"),
4444
ReadOnlyHint: true,
4545
},
46+
InputSchema: &jsonschema.Schema{
47+
Type: "object",
48+
},
4649
},
4750
mcp.ToolHandlerFor[map[string]any, any](func(ctx context.Context, _ *mcp.CallToolRequest, _ map[string]any) (*mcp.CallToolResult, any, error) {
4851
client, err := getClient(ctx)

pkg/toolsets/toolsets.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package toolsets
22

33
import (
4+
"context"
5+
"encoding/json"
46
"fmt"
57
"os"
68
"strings"
@@ -35,9 +37,20 @@ type ServerTool struct {
3537
RegisterFunc func(s *mcp.Server)
3638
}
3739

38-
func NewServerTool[In, Out any](tool mcp.Tool, handler mcp.ToolHandlerFor[In, Out]) ServerTool {
40+
func NewServerTool[In any, Out any](tool mcp.Tool, handler mcp.ToolHandlerFor[In, Out]) ServerTool {
3941
return ServerTool{Tool: tool, RegisterFunc: func(s *mcp.Server) {
40-
mcp.AddTool(s, &tool, handler)
42+
th := func(ctx context.Context, req *mcp.CallToolRequest) (*mcp.CallToolResult, error) {
43+
var arguments In
44+
if err := json.Unmarshal(req.Params.Arguments, &arguments); err != nil {
45+
return nil, err
46+
}
47+
48+
resp, _, err := handler(ctx, req, arguments)
49+
50+
return resp, err
51+
}
52+
53+
s.AddTool(&tool, th)
4154
}}
4255
}
4356

0 commit comments

Comments
 (0)