Skip to content

Commit 3472483

Browse files
committed
Merge remote-tracking branch 'origin/main' into lulu/tool-descriptions
2 parents 26322aa + ea73047 commit 3472483

File tree

4 files changed

+87
-33
lines changed

4 files changed

+87
-33
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ These are one time installations required to be able to test your changes locall
1919

2020
## Submitting a pull request
2121

22-
> **Important**: Please open your pull request against the `next` branch, not `main`. The `next` branch is where we integrate new features and changes before they are merged to `main`.
23-
2422
1. [Fork][fork] and clone the repository
2523
1. Make sure the tests pass on your machine: `go test -v ./...`
2624
1. Make sure linter passes on your machine: `golangci-lint run`
2725
1. Create a new branch: `git checkout -b my-branch-name`
2826
1. Make your change, add tests, and make sure the tests and linter still pass
29-
1. Push to your fork and [submit a pull request][pr] targeting the `next` branch
27+
1. Push to your fork and [submit a pull request][pr] targeting the `main` branch
3028
1. Pat yourself on the back and wait for your pull request to be reviewed and merged.
3129

3230
Here are a few things you can do that will increase the likelihood of your pull request being accepted:

pkg/github/context_tools.go

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,36 @@ package github
22

33
import (
44
"context"
5+
"time"
56

67
ghErrors "github.com/github/github-mcp-server/pkg/errors"
78
"github.com/github/github-mcp-server/pkg/translations"
89
"github.com/mark3labs/mcp-go/mcp"
910
"github.com/mark3labs/mcp-go/server"
1011
)
1112

13+
// UserDetails contains additional fields about a GitHub user not already
14+
// present in MinimalUser. Used by get_me context tool but omitted from search_users.
15+
type UserDetails struct {
16+
Name string `json:"name,omitempty"`
17+
Company string `json:"company,omitempty"`
18+
Blog string `json:"blog,omitempty"`
19+
Location string `json:"location,omitempty"`
20+
Email string `json:"email,omitempty"`
21+
Hireable bool `json:"hireable,omitempty"`
22+
Bio string `json:"bio,omitempty"`
23+
TwitterUsername string `json:"twitter_username,omitempty"`
24+
PublicRepos int `json:"public_repos"`
25+
PublicGists int `json:"public_gists"`
26+
Followers int `json:"followers"`
27+
Following int `json:"following"`
28+
CreatedAt time.Time `json:"created_at"`
29+
UpdatedAt time.Time `json:"updated_at"`
30+
PrivateGists int `json:"private_gists,omitempty"`
31+
TotalPrivateRepos int64 `json:"total_private_repos,omitempty"`
32+
OwnedPrivateRepos int64 `json:"owned_private_repos,omitempty"`
33+
}
34+
1235
// GetMe creates a tool to get details of the authenticated user.
1336
func GetMe(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Tool, server.ToolHandlerFunc) {
1437
tool := mcp.NewTool("get_me",
@@ -38,7 +61,34 @@ func GetMe(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Too
3861
), nil
3962
}
4063

41-
return MarshalledTextResult(user), nil
64+
// Create minimal user representation instead of returning full user object
65+
minimalUser := MinimalUser{
66+
Login: user.GetLogin(),
67+
ID: user.GetID(),
68+
ProfileURL: user.GetHTMLURL(),
69+
AvatarURL: user.GetAvatarURL(),
70+
Details: &UserDetails{
71+
Name: user.GetName(),
72+
Company: user.GetCompany(),
73+
Blog: user.GetBlog(),
74+
Location: user.GetLocation(),
75+
Email: user.GetEmail(),
76+
Hireable: user.GetHireable(),
77+
Bio: user.GetBio(),
78+
TwitterUsername: user.GetTwitterUsername(),
79+
PublicRepos: user.GetPublicRepos(),
80+
PublicGists: user.GetPublicGists(),
81+
Followers: user.GetFollowers(),
82+
Following: user.GetFollowing(),
83+
CreatedAt: user.GetCreatedAt().Time,
84+
UpdatedAt: user.GetUpdatedAt().Time,
85+
PrivateGists: user.GetPrivateGists(),
86+
TotalPrivateRepos: user.GetTotalPrivateRepos(),
87+
OwnedPrivateRepos: user.GetOwnedPrivateRepos(),
88+
},
89+
}
90+
91+
return MarshalledTextResult(minimalUser), nil
4292
})
4393

4494
return tool, handler

pkg/github/context_tools_test.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ func Test_GetMe(t *testing.T) {
2626

2727
// Setup mock user response
2828
mockUser := &github.User{
29-
Login: github.Ptr("testuser"),
30-
Name: github.Ptr("Test User"),
31-
Email: github.Ptr("[email protected]"),
32-
Bio: github.Ptr("GitHub user for testing"),
33-
Company: github.Ptr("Test Company"),
34-
Location: github.Ptr("Test Location"),
35-
HTMLURL: github.Ptr("https://github.com/testuser"),
36-
CreatedAt: &github.Timestamp{Time: time.Now().Add(-365 * 24 * time.Hour)},
37-
Type: github.Ptr("User"),
29+
Login: github.Ptr("testuser"),
30+
Name: github.Ptr("Test User"),
31+
Email: github.Ptr("[email protected]"),
32+
Bio: github.Ptr("GitHub user for testing"),
33+
Company: github.Ptr("Test Company"),
34+
Location: github.Ptr("Test Location"),
35+
HTMLURL: github.Ptr("https://github.com/testuser"),
36+
CreatedAt: &github.Timestamp{Time: time.Now().Add(-365 * 24 * time.Hour)},
37+
Type: github.Ptr("User"),
38+
Hireable: github.Ptr(true),
39+
TwitterUsername: github.Ptr("testuser_twitter"),
3840
Plan: &github.Plan{
3941
Name: github.Ptr("pro"),
4042
},
@@ -117,17 +119,23 @@ func Test_GetMe(t *testing.T) {
117119
}
118120

119121
// Unmarshal and verify the result
120-
var returnedUser github.User
122+
var returnedUser MinimalUser
121123
err = json.Unmarshal([]byte(textContent.Text), &returnedUser)
122124
require.NoError(t, err)
123125

126+
// Verify minimal user details
127+
assert.Equal(t, *tc.expectedUser.Login, returnedUser.Login)
128+
assert.Equal(t, *tc.expectedUser.HTMLURL, returnedUser.ProfileURL)
129+
124130
// Verify user details
125-
assert.Equal(t, *tc.expectedUser.Login, *returnedUser.Login)
126-
assert.Equal(t, *tc.expectedUser.Name, *returnedUser.Name)
127-
assert.Equal(t, *tc.expectedUser.Email, *returnedUser.Email)
128-
assert.Equal(t, *tc.expectedUser.Bio, *returnedUser.Bio)
129-
assert.Equal(t, *tc.expectedUser.HTMLURL, *returnedUser.HTMLURL)
130-
assert.Equal(t, *tc.expectedUser.Type, *returnedUser.Type)
131+
require.NotNil(t, returnedUser.Details)
132+
assert.Equal(t, *tc.expectedUser.Name, returnedUser.Details.Name)
133+
assert.Equal(t, *tc.expectedUser.Email, returnedUser.Details.Email)
134+
assert.Equal(t, *tc.expectedUser.Bio, returnedUser.Details.Bio)
135+
assert.Equal(t, *tc.expectedUser.Company, returnedUser.Details.Company)
136+
assert.Equal(t, *tc.expectedUser.Location, returnedUser.Details.Location)
137+
assert.Equal(t, *tc.expectedUser.Hireable, returnedUser.Details.Hireable)
138+
assert.Equal(t, *tc.expectedUser.TwitterUsername, returnedUser.Details.TwitterUsername)
131139
})
132140
}
133141
}

pkg/github/search.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,13 @@ func SearchCode(getClient GetClientFn, t translations.TranslationHelperFunc) (to
155155
}
156156
}
157157

158+
// MinimalUser is the output type for user and organization search results.
158159
type MinimalUser struct {
159-
Login string `json:"login"`
160-
ID int64 `json:"id,omitempty"`
161-
ProfileURL string `json:"profile_url,omitempty"`
162-
AvatarURL string `json:"avatar_url,omitempty"`
160+
Login string `json:"login"`
161+
ID int64 `json:"id,omitempty"`
162+
ProfileURL string `json:"profile_url,omitempty"`
163+
AvatarURL string `json:"avatar_url,omitempty"`
164+
Details *UserDetails `json:"details,omitempty"` // Optional field for additional user details
163165
}
164166

165167
type MinimalSearchUsersResult struct {
@@ -224,15 +226,11 @@ func userOrOrgHandler(accountType string, getClient GetClientFn) server.ToolHand
224226

225227
for _, user := range result.Users {
226228
if user.Login != nil {
227-
mu := MinimalUser{Login: *user.Login}
228-
if user.ID != nil {
229-
mu.ID = *user.ID
230-
}
231-
if user.HTMLURL != nil {
232-
mu.ProfileURL = *user.HTMLURL
233-
}
234-
if user.AvatarURL != nil {
235-
mu.AvatarURL = *user.AvatarURL
229+
mu := MinimalUser{
230+
Login: user.GetLogin(),
231+
ID: user.GetID(),
232+
ProfileURL: user.GetHTMLURL(),
233+
AvatarURL: user.GetAvatarURL(),
236234
}
237235
minimalUsers = append(minimalUsers, mu)
238236
}

0 commit comments

Comments
 (0)