Skip to content

Commit 24cf9ff

Browse files
committed
fix: let get_me handle missing arguments
1 parent 7e79ae9 commit 24cf9ff

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

pkg/github/context_tools.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type UserDetails struct {
4343

4444
// GetMe creates a tool to get details of the authenticated user.
4545
func GetMe(t translations.TranslationHelperFunc) inventory.ServerTool {
46-
return NewTool(
46+
return NewToolFromHandler(
4747
ToolsetMetadataContext,
4848
mcp.Tool{
4949
Name: "get_me",
@@ -63,10 +63,10 @@ func GetMe(t translations.TranslationHelperFunc) inventory.ServerTool {
6363
},
6464
},
6565
nil,
66-
func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, _ map[string]any) (*mcp.CallToolResult, any, error) {
66+
func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest) (*mcp.CallToolResult, error) {
6767
client, err := deps.GetClient(ctx)
6868
if err != nil {
69-
return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil
69+
return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil
7070
}
7171

7272
user, res, err := client.Users.Get(ctx, "")
@@ -75,7 +75,7 @@ func GetMe(t translations.TranslationHelperFunc) inventory.ServerTool {
7575
"failed to get user",
7676
res,
7777
err,
78-
), nil, nil
78+
), nil
7979
}
8080

8181
// Create minimal user representation instead of returning full user object
@@ -112,7 +112,7 @@ func GetMe(t translations.TranslationHelperFunc) inventory.ServerTool {
112112
}
113113
result.Meta["ifc"] = ifc.LabelGetMe()
114114
}
115-
return result, nil, nil
115+
return result, nil
116116
},
117117
)
118118
}

pkg/github/context_tools_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/github/github-mcp-server/internal/toolsnaps"
1212
"github.com/github/github-mcp-server/pkg/translations"
1313
"github.com/google/go-github/v87/github"
14+
"github.com/modelcontextprotocol/go-sdk/mcp"
1415
"github.com/shurcooL/githubv4"
1516
"github.com/stretchr/testify/assert"
1617
"github.com/stretchr/testify/require"
@@ -50,6 +51,7 @@ func Test_GetMe(t *testing.T) {
5051
mockedClient *http.Client
5152
clientErr string // if set, GetClient returns this error
5253
requestArgs map[string]any
54+
missingArguments bool
5355
expectToolError bool
5456
expectedUser *github.User
5557
expectedToolErrMsg string
@@ -63,6 +65,15 @@ func Test_GetMe(t *testing.T) {
6365
expectToolError: false,
6466
expectedUser: mockUser,
6567
},
68+
{
69+
name: "successful get user with missing arguments",
70+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
71+
GetUser: mockResponse(t, http.StatusOK, mockUser),
72+
}),
73+
missingArguments: true,
74+
expectToolError: false,
75+
expectedUser: mockUser,
76+
},
6677
{
6778
name: "successful get user with reason",
6879
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
@@ -103,7 +114,16 @@ func Test_GetMe(t *testing.T) {
103114
}
104115
handler := serverTool.Handler(deps)
105116

106-
request := createMCPRequest(tc.requestArgs)
117+
var request mcp.CallToolRequest
118+
if tc.missingArguments {
119+
request = mcp.CallToolRequest{
120+
Params: &mcp.CallToolParamsRaw{
121+
Name: "get_me",
122+
},
123+
}
124+
} else {
125+
request = createMCPRequest(tc.requestArgs)
126+
}
107127
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
108128
require.NoError(t, err)
109129

0 commit comments

Comments
 (0)