Skip to content

Commit e43fca1

Browse files
LuluBeatsonSamMorrowDrums
authored andcommitted
embed optional UserDetails in MinimalUser
1 parent 1d057c9 commit e43fca1

File tree

3 files changed

+69
-13
lines changed

3 files changed

+69
-13
lines changed

pkg/github/context_tools.go

Lines changed: 42 additions & 0 deletions
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",
@@ -44,6 +67,25 @@ func GetMe(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Too
4467
ID: user.GetID(),
4568
ProfileURL: user.GetHTMLURL(),
4669
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+
},
4789
}
4890

4991
return MarshalledTextResult(minimalUser), nil

pkg/github/context_tools_test.go

Lines changed: 21 additions & 9 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("test@example.com"),
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("test@example.com"),
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
},
@@ -124,6 +126,16 @@ func Test_GetMe(t *testing.T) {
124126
// Verify minimal user details
125127
assert.Equal(t, *tc.expectedUser.Login, returnedUser.Login)
126128
assert.Equal(t, *tc.expectedUser.HTMLURL, returnedUser.ProfileURL)
129+
130+
// Verify user details
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)
127139
})
128140
}
129141
}

pkg/github/search.go

Lines changed: 6 additions & 4 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 {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy