Skip to content

Commit 3704756

Browse files
Update GitHub tools to use content filtering
Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
1 parent 4f1dee2 commit 3704756

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

pkg/github/issues.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
// GetIssue creates a tool to get details of a specific issue in a GitHub repository.
21-
func GetIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
21+
func GetIssue(getClient GetClientFn, getGQLClient GetGQLClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
2222
return mcp.NewTool("get_issue",
2323
mcp.WithDescription(t("TOOL_GET_ISSUE_DESCRIPTION", "Get details of a specific issue in a GitHub repository.")),
2424
mcp.WithToolAnnotation(mcp.ToolAnnotation{
@@ -70,6 +70,13 @@ func GetIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (tool
7070
return mcp.NewToolResultError(fmt.Sprintf("failed to get issue: %s", string(body))), nil
7171
}
7272

73+
// Check if content filtering is enabled and user has push access
74+
if issue.User != nil && issue.User.Login != nil {
75+
if !ShouldIncludeContent(ctx, *issue.User.Login, getGQLClient) {
76+
return mcp.NewToolResultError("Content from this user is filtered due to lack of push access to the trusted repository"), nil
77+
}
78+
}
79+
7380
r, err := json.Marshal(issue)
7481
if err != nil {
7582
return nil, fmt.Errorf("failed to marshal issue: %w", err)
@@ -632,7 +639,7 @@ func UpdateIssue(getClient GetClientFn, t translations.TranslationHelperFunc) (t
632639
}
633640

634641
// GetIssueComments creates a tool to get comments for a GitHub issue.
635-
func GetIssueComments(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
642+
func GetIssueComments(getClient GetClientFn, getGQLClient GetGQLClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
636643
return mcp.NewTool("get_issue_comments",
637644
mcp.WithDescription(t("TOOL_GET_ISSUE_COMMENTS_DESCRIPTION", "Get comments for a specific issue in a GitHub repository.")),
638645
mcp.WithToolAnnotation(mcp.ToolAnnotation{
@@ -705,7 +712,17 @@ func GetIssueComments(getClient GetClientFn, t translations.TranslationHelperFun
705712
return mcp.NewToolResultError(fmt.Sprintf("failed to get issue comments: %s", string(body))), nil
706713
}
707714

708-
r, err := json.Marshal(comments)
715+
// Filter comments based on user permissions
716+
var filteredComments []*github.IssueComment
717+
for _, comment := range comments {
718+
if comment.User != nil && comment.User.Login != nil {
719+
if ShouldIncludeContent(ctx, *comment.User.Login, getGQLClient) {
720+
filteredComments = append(filteredComments, comment)
721+
}
722+
}
723+
}
724+
725+
r, err := json.Marshal(filteredComments)
709726
if err != nil {
710727
return nil, fmt.Errorf("failed to marshal response: %w", err)
711728
}

pkg/github/issues_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import (
2020
func Test_GetIssue(t *testing.T) {
2121
// Verify tool definition once
2222
mockClient := github.NewClient(nil)
23-
tool, _ := GetIssue(stubGetClientFn(mockClient), translations.NullTranslationHelper)
23+
mockGQLClient := githubv4.NewClient(nil)
24+
tool, _ := GetIssue(stubGetClientFn(mockClient), stubGetGQLClientFn(mockGQLClient), translations.NullTranslationHelper)
2425

2526
assert.Equal(t, "get_issue", tool.Name)
2627
assert.NotEmpty(t, tool.Description)
@@ -84,7 +85,8 @@ func Test_GetIssue(t *testing.T) {
8485
t.Run(tc.name, func(t *testing.T) {
8586
// Setup client with mock
8687
client := github.NewClient(tc.mockedClient)
87-
_, handler := GetIssue(stubGetClientFn(client), translations.NullTranslationHelper)
88+
mockGQLClient := githubv4.NewClient(nil)
89+
_, handler := GetIssue(stubGetClientFn(client), stubGetGQLClientFn(mockGQLClient), translations.NullTranslationHelper)
8890

8991
// Create call request
9092
request := createMCPRequest(tc.requestArgs)
@@ -992,7 +994,8 @@ func Test_ParseISOTimestamp(t *testing.T) {
992994
func Test_GetIssueComments(t *testing.T) {
993995
// Verify tool definition once
994996
mockClient := github.NewClient(nil)
995-
tool, _ := GetIssueComments(stubGetClientFn(mockClient), translations.NullTranslationHelper)
997+
mockGQLClient := githubv4.NewClient(nil)
998+
tool, _ := GetIssueComments(stubGetClientFn(mockClient), stubGetGQLClientFn(mockGQLClient), translations.NullTranslationHelper)
996999

9971000
assert.Equal(t, "get_issue_comments", tool.Name)
9981001
assert.NotEmpty(t, tool.Description)
@@ -1092,7 +1095,8 @@ func Test_GetIssueComments(t *testing.T) {
10921095
t.Run(tc.name, func(t *testing.T) {
10931096
// Setup client with mock
10941097
client := github.NewClient(tc.mockedClient)
1095-
_, handler := GetIssueComments(stubGetClientFn(client), translations.NullTranslationHelper)
1098+
mockGQLClient := githubv4.NewClient(nil)
1099+
_, handler := GetIssueComments(stubGetClientFn(client), stubGetGQLClientFn(mockGQLClient), translations.NullTranslationHelper)
10961100

10971101
// Create call request
10981102
request := createMCPRequest(tc.requestArgs)

pkg/github/tools.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ func InitToolsets(passedToolsets []string, readOnly bool, getClient GetClientFn,
4242
)
4343
issues := toolsets.NewToolset("issues", "GitHub Issues related tools").
4444
AddReadTools(
45-
toolsets.NewServerTool(GetIssue(getClient, t)),
45+
toolsets.NewServerTool(GetIssue(getClient, getGQLClient, t)),
4646
toolsets.NewServerTool(SearchIssues(getClient, t)),
4747
toolsets.NewServerTool(ListIssues(getClient, t)),
48-
toolsets.NewServerTool(GetIssueComments(getClient, t)),
48+
toolsets.NewServerTool(GetIssueComments(getClient, getGQLClient, t)),
4949
).
5050
AddWriteTools(
5151
toolsets.NewServerTool(CreateIssue(getClient, t)),

0 commit comments

Comments
 (0)