Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/github/context_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type UserDetails struct {

// GetMe creates a tool to get details of the authenticated user.
func GetMe(t translations.TranslationHelperFunc) inventory.ServerTool {
return NewTool(
return NewToolFromHandler(
ToolsetMetadataContext,
mcp.Tool{
Name: "get_me",
Expand All @@ -63,10 +63,10 @@ func GetMe(t translations.TranslationHelperFunc) inventory.ServerTool {
},
},
nil,
func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, _ map[string]any) (*mcp.CallToolResult, any, error) {
func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest) (*mcp.CallToolResult, error) {
client, err := deps.GetClient(ctx)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil
return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil
}

user, res, err := client.Users.Get(ctx, "")
Expand All @@ -75,7 +75,7 @@ func GetMe(t translations.TranslationHelperFunc) inventory.ServerTool {
"failed to get user",
res,
err,
), nil, nil
), nil
}

// Create minimal user representation instead of returning full user object
Expand Down Expand Up @@ -112,7 +112,7 @@ func GetMe(t translations.TranslationHelperFunc) inventory.ServerTool {
}
result.Meta["ifc"] = ifc.LabelGetMe()
}
return result, nil, nil
return result, nil
},
)
}
Expand Down
22 changes: 21 additions & 1 deletion pkg/github/context_tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/github/github-mcp-server/internal/toolsnaps"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/go-github/v87/github"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/shurcooL/githubv4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -50,6 +51,7 @@ func Test_GetMe(t *testing.T) {
mockedClient *http.Client
clientErr string // if set, GetClient returns this error
requestArgs map[string]any
missingArguments bool
expectToolError bool
expectedUser *github.User
expectedToolErrMsg string
Expand All @@ -63,6 +65,15 @@ func Test_GetMe(t *testing.T) {
expectToolError: false,
expectedUser: mockUser,
},
{
name: "successful get user with missing arguments",
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
GetUser: mockResponse(t, http.StatusOK, mockUser),
}),
missingArguments: true,
expectToolError: false,
expectedUser: mockUser,
},
{
name: "successful get user with reason",
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
Expand Down Expand Up @@ -103,7 +114,16 @@ func Test_GetMe(t *testing.T) {
}
handler := serverTool.Handler(deps)

request := createMCPRequest(tc.requestArgs)
var request mcp.CallToolRequest
if tc.missingArguments {
request = mcp.CallToolRequest{
Params: &mcp.CallToolParamsRaw{
Name: "get_me",
},
}
} else {
request = createMCPRequest(tc.requestArgs)
}
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
require.NoError(t, err)

Expand Down