@@ -14,12 +14,13 @@ import (
1414 "github.com/shurcooL/githubv4"
1515
1616 ghErrors "github.com/github/github-mcp-server/pkg/errors"
17+ "github.com/github/github-mcp-server/pkg/lockdown"
1718 "github.com/github/github-mcp-server/pkg/sanitize"
1819 "github.com/github/github-mcp-server/pkg/translations"
1920)
2021
2122// GetPullRequest creates a tool to get details of a specific pull request.
22- func PullRequestRead (getClient GetClientFn , t translations.TranslationHelperFunc , flags FeatureFlags ) (mcp.Tool , server.ToolHandlerFunc ) {
23+ func PullRequestRead (getClient GetClientFn , getGQLClient GetGQLClientFn , t translations.TranslationHelperFunc , flags FeatureFlags ) (mcp.Tool , server.ToolHandlerFunc ) {
2324 return mcp .NewTool ("pull_request_read" ,
2425 mcp .WithDescription (t ("TOOL_PULL_REQUEST_READ_DESCRIPTION" , "Get information on a specific pull request in GitHub repository." )),
2526 mcp .WithToolAnnotation (mcp.ToolAnnotation {
@@ -83,29 +84,34 @@ Possible options:
8384 return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
8485 }
8586
87+ gqlClient , err := getGQLClient (ctx )
88+ if err != nil {
89+ return nil , fmt .Errorf ("failed to get GitHub GraphQL client: %w" , err )
90+ }
91+
8692 switch method {
8793
8894 case "get" :
89- return GetPullRequest (ctx , client , owner , repo , pullNumber )
95+ return GetPullRequest (ctx , client , gqlClient , owner , repo , pullNumber , flags )
9096 case "get_diff" :
9197 return GetPullRequestDiff (ctx , client , owner , repo , pullNumber )
9298 case "get_status" :
9399 return GetPullRequestStatus (ctx , client , owner , repo , pullNumber )
94100 case "get_files" :
95101 return GetPullRequestFiles (ctx , client , owner , repo , pullNumber , pagination )
96102 case "get_review_comments" :
97- return GetPullRequestReviewComments (ctx , client , owner , repo , pullNumber , pagination )
103+ return GetPullRequestReviewComments (ctx , client , gqlClient , owner , repo , pullNumber , pagination , flags )
98104 case "get_reviews" :
99- return GetPullRequestReviews (ctx , client , owner , repo , pullNumber )
105+ return GetPullRequestReviews (ctx , client , gqlClient , owner , repo , pullNumber , flags )
100106 case "get_comments" :
101- return GetIssueComments (ctx , client , owner , repo , pullNumber , pagination , flags )
107+ return GetIssueComments (ctx , client , gqlClient , owner , repo , pullNumber , pagination , flags )
102108 default :
103109 return nil , fmt .Errorf ("unknown method: %s" , method )
104110 }
105111 }
106112}
107113
108- func GetPullRequest (ctx context.Context , client * github.Client , owner , repo string , pullNumber int ) (* mcp.CallToolResult , error ) {
114+ func GetPullRequest (ctx context.Context , client * github.Client , gqlClient * githubv4. Client , owner , repo string , pullNumber int , ff FeatureFlags ) (* mcp.CallToolResult , error ) {
109115 pr , resp , err := client .PullRequests .Get (ctx , owner , repo , pullNumber )
110116 if err != nil {
111117 return ghErrors .NewGitHubAPIErrorResponse (ctx ,
@@ -134,6 +140,17 @@ func GetPullRequest(ctx context.Context, client *github.Client, owner, repo stri
134140 }
135141 }
136142
143+ if ff .LockdownMode {
144+ isPrivate , hasPushAccess , err := lockdown .GetRepoAccessInfo (ctx , gqlClient , pr .GetUser ().GetLogin (), owner , repo )
145+ if err != nil {
146+ return nil , fmt .Errorf ("failed to check content removal: %w" , err )
147+ }
148+
149+ if ! isPrivate && ! hasPushAccess {
150+ return mcp .NewToolResultError ("access to pull request is restricted by lockdown mode" ), nil
151+ }
152+ }
153+
137154 r , err := json .Marshal (pr )
138155 if err != nil {
139156 return nil , fmt .Errorf ("failed to marshal response: %w" , err )
@@ -249,7 +266,7 @@ func GetPullRequestFiles(ctx context.Context, client *github.Client, owner, repo
249266 return mcp .NewToolResultText (string (r )), nil
250267}
251268
252- func GetPullRequestReviewComments (ctx context.Context , client * github.Client , owner , repo string , pullNumber int , pagination PaginationParams ) (* mcp.CallToolResult , error ) {
269+ func GetPullRequestReviewComments (ctx context.Context , client * github.Client , gqlClient * githubv4. Client , owner , repo string , pullNumber int , pagination PaginationParams , ff FeatureFlags ) (* mcp.CallToolResult , error ) {
253270 opts := & github.PullRequestListCommentsOptions {
254271 ListOptions : github.ListOptions {
255272 PerPage : pagination .PerPage ,
@@ -275,6 +292,16 @@ func GetPullRequestReviewComments(ctx context.Context, client *github.Client, ow
275292 return mcp .NewToolResultError (fmt .Sprintf ("failed to get pull request review comments: %s" , string (body ))), nil
276293 }
277294
295+ if ff .LockdownMode {
296+ isPrivate , hasPushAccess , err := lockdown .GetRepoAccessInfo (ctx , gqlClient , comments [0 ].GetUser ().GetLogin (), owner , repo )
297+ if err != nil {
298+ return nil , fmt .Errorf ("failed to check content removal: %w" , err )
299+ }
300+ if ! isPrivate && ! hasPushAccess {
301+ return mcp .NewToolResultError ("access to pull request review comments is restricted by lockdown mode" ), nil
302+ }
303+ }
304+
278305 r , err := json .Marshal (comments )
279306 if err != nil {
280307 return nil , fmt .Errorf ("failed to marshal response: %w" , err )
@@ -283,7 +310,7 @@ func GetPullRequestReviewComments(ctx context.Context, client *github.Client, ow
283310 return mcp .NewToolResultText (string (r )), nil
284311}
285312
286- func GetPullRequestReviews (ctx context.Context , client * github.Client , owner , repo string , pullNumber int ) (* mcp.CallToolResult , error ) {
313+ func GetPullRequestReviews (ctx context.Context , client * github.Client , gqlClient * githubv4. Client , owner , repo string , pullNumber int , ff FeatureFlags ) (* mcp.CallToolResult , error ) {
287314 reviews , resp , err := client .PullRequests .ListReviews (ctx , owner , repo , pullNumber , nil )
288315 if err != nil {
289316 return ghErrors .NewGitHubAPIErrorResponse (ctx ,
@@ -302,6 +329,16 @@ func GetPullRequestReviews(ctx context.Context, client *github.Client, owner, re
302329 return mcp .NewToolResultError (fmt .Sprintf ("failed to get pull request reviews: %s" , string (body ))), nil
303330 }
304331
332+ if ff .LockdownMode {
333+ isPrivate , hasPushAccess , err := lockdown .GetRepoAccessInfo (ctx , gqlClient , reviews [0 ].GetUser ().GetLogin (), owner , repo )
334+ if err != nil {
335+ return nil , fmt .Errorf ("failed to check content removal: %w" , err )
336+ }
337+ if ! isPrivate && ! hasPushAccess {
338+ return mcp .NewToolResultError ("access to pull request reviews is restricted by lockdown mode" ), nil
339+ }
340+ }
341+
305342 r , err := json .Marshal (reviews )
306343 if err != nil {
307344 return nil , fmt .Errorf ("failed to marshal response: %w" , err )
0 commit comments