Skip to content

Commit ba9d315

Browse files
committed
Merge branch 'main' of https://github.com/github/github-mcp-server into add-logging-stack-v2
2 parents 4a2f8ed + 543a1fa commit ba9d315

File tree

12 files changed

+384
-65
lines changed

12 files changed

+384
-65
lines changed

pkg/context/token.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,37 @@ import (
66
"github.com/github/github-mcp-server/pkg/utils"
77
)
88

9-
// tokenCtxKey is a context key for authentication token information
10-
type tokenCtx string
11-
12-
var tokenCtxKey tokenCtx = "tokenctx"
9+
type tokenCtxKey struct{}
1310

1411
type TokenInfo struct {
15-
Token string
16-
TokenType utils.TokenType
17-
ScopesFetched bool
18-
Scopes []string
12+
Token string
13+
TokenType utils.TokenType
1914
}
2015

2116
// WithTokenInfo adds TokenInfo to the context
2217
func WithTokenInfo(ctx context.Context, tokenInfo *TokenInfo) context.Context {
23-
return context.WithValue(ctx, tokenCtxKey, tokenInfo)
18+
return context.WithValue(ctx, tokenCtxKey{}, tokenInfo)
2419
}
2520

2621
// GetTokenInfo retrieves the authentication token from the context
2722
func GetTokenInfo(ctx context.Context) (*TokenInfo, bool) {
28-
if tokenInfo, ok := ctx.Value(tokenCtxKey).(*TokenInfo); ok {
23+
if tokenInfo, ok := ctx.Value(tokenCtxKey{}).(*TokenInfo); ok {
2924
return tokenInfo, true
3025
}
3126
return nil, false
3227
}
28+
29+
type tokenScopesKey struct{}
30+
31+
// WithTokenScopes adds token scopes to the context
32+
func WithTokenScopes(ctx context.Context, scopes []string) context.Context {
33+
return context.WithValue(ctx, tokenScopesKey{}, scopes)
34+
}
35+
36+
// GetTokenScopes retrieves token scopes from the context
37+
func GetTokenScopes(ctx context.Context) ([]string, bool) {
38+
if scopes, ok := ctx.Value(tokenScopesKey{}).([]string); ok {
39+
return scopes, true
40+
}
41+
return nil, false
42+
}

pkg/github/issues.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,9 @@ func GetIssue(ctx context.Context, client *github.Client, deps ToolDependencies,
376376
}
377377
}
378378

379-
r, err := json.Marshal(issue)
380-
if err != nil {
381-
return nil, fmt.Errorf("failed to marshal issue: %w", err)
382-
}
379+
minimalIssue := convertToMinimalIssue(issue)
383380

384-
return utils.NewToolResultText(string(r)), nil
381+
return MarshalledTextResult(minimalIssue), nil
385382
}
386383

387384
func GetIssueComments(ctx context.Context, client *github.Client, deps ToolDependencies, owner string, repo string, issueNumber int, pagination PaginationParams) (*mcp.CallToolResult, error) {
@@ -436,12 +433,12 @@ func GetIssueComments(ctx context.Context, client *github.Client, deps ToolDepen
436433
comments = filteredComments
437434
}
438435

439-
r, err := json.Marshal(comments)
440-
if err != nil {
441-
return nil, fmt.Errorf("failed to marshal response: %w", err)
436+
minimalComments := make([]MinimalIssueComment, 0, len(comments))
437+
for _, comment := range comments {
438+
minimalComments = append(minimalComments, convertToMinimalIssueComment(comment))
442439
}
443440

444-
return utils.NewToolResultText(string(r)), nil
441+
return MarshalledTextResult(minimalComments), nil
445442
}
446443

447444
func GetSubIssues(ctx context.Context, client *github.Client, deps ToolDependencies, owner string, repo string, issueNumber int, pagination PaginationParams) (*mcp.CallToolResult, error) {

pkg/github/issues_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -345,15 +345,15 @@ func Test_GetIssue(t *testing.T) {
345345

346346
textContent := getTextResult(t, result)
347347

348-
var returnedIssue github.Issue
348+
var returnedIssue MinimalIssue
349349
err = json.Unmarshal([]byte(textContent.Text), &returnedIssue)
350350
require.NoError(t, err)
351-
assert.Equal(t, *tc.expectedIssue.Number, *returnedIssue.Number)
352-
assert.Equal(t, *tc.expectedIssue.Title, *returnedIssue.Title)
353-
assert.Equal(t, *tc.expectedIssue.Body, *returnedIssue.Body)
354-
assert.Equal(t, *tc.expectedIssue.State, *returnedIssue.State)
355-
assert.Equal(t, *tc.expectedIssue.HTMLURL, *returnedIssue.HTMLURL)
356-
assert.Equal(t, *tc.expectedIssue.User.Login, *returnedIssue.User.Login)
351+
assert.Equal(t, tc.expectedIssue.GetNumber(), returnedIssue.Number)
352+
assert.Equal(t, tc.expectedIssue.GetTitle(), returnedIssue.Title)
353+
assert.Equal(t, tc.expectedIssue.GetBody(), returnedIssue.Body)
354+
assert.Equal(t, tc.expectedIssue.GetState(), returnedIssue.State)
355+
assert.Equal(t, tc.expectedIssue.GetHTMLURL(), returnedIssue.HTMLURL)
356+
assert.Equal(t, tc.expectedIssue.GetUser().GetLogin(), returnedIssue.User.Login)
357357
})
358358
}
359359
}
@@ -2020,16 +2020,16 @@ func Test_GetIssueComments(t *testing.T) {
20202020
textContent := getTextResult(t, result)
20212021

20222022
// Unmarshal and verify the result
2023-
var returnedComments []*github.IssueComment
2023+
var returnedComments []MinimalIssueComment
20242024
err = json.Unmarshal([]byte(textContent.Text), &returnedComments)
20252025
require.NoError(t, err)
20262026
assert.Equal(t, len(tc.expectedComments), len(returnedComments))
20272027
for i := range tc.expectedComments {
20282028
require.NotNil(t, tc.expectedComments[i].User)
20292029
require.NotNil(t, returnedComments[i].User)
2030-
assert.Equal(t, tc.expectedComments[i].GetID(), returnedComments[i].GetID())
2031-
assert.Equal(t, tc.expectedComments[i].GetBody(), returnedComments[i].GetBody())
2032-
assert.Equal(t, tc.expectedComments[i].GetUser().GetLogin(), returnedComments[i].GetUser().GetLogin())
2030+
assert.Equal(t, tc.expectedComments[i].GetID(), returnedComments[i].ID)
2031+
assert.Equal(t, tc.expectedComments[i].GetBody(), returnedComments[i].Body)
2032+
assert.Equal(t, tc.expectedComments[i].GetUser().GetLogin(), returnedComments[i].User.Login)
20332033
}
20342034
})
20352035
}

0 commit comments

Comments
 (0)