Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3704756

Browse files
Update GitHub tools to use content filtering
Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
1 parent4f1dee2 commit3704756

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-
funcGetIssue(getClientGetClientFn,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
21+
funcGetIssue(getClientGetClientFn,getGQLClientGetGQLClientFn,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
2222
returnmcp.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
returnmcp.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+
ifissue.User!=nil&&issue.User.Login!=nil {
75+
if!ShouldIncludeContent(ctx,*issue.User.Login,getGQLClient) {
76+
returnmcp.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
iferr!=nil {
7582
returnnil,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-
funcGetIssueComments(getClientGetClientFn,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
642+
funcGetIssueComments(getClientGetClientFn,getGQLClientGetGQLClientFn,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
636643
returnmcp.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
returnmcp.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+
varfilteredComments []*github.IssueComment
717+
for_,comment:=rangecomments {
718+
ifcomment.User!=nil&&comment.User.Login!=nil {
719+
ifShouldIncludeContent(ctx,*comment.User.Login,getGQLClient) {
720+
filteredComments=append(filteredComments,comment)
721+
}
722+
}
723+
}
724+
725+
r,err:=json.Marshal(filteredComments)
709726
iferr!=nil {
710727
returnnil,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
funcTest_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
funcTest_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)

[8]ページ先頭

©2009-2025 Movatter.jp