Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,7 @@ For negotiated supported protocol versions `2026-07-28` or newer, the consolidat
- **pull_request_read** - Get details for a single pull request
- **OAuth Challenge Scopes**: `repo`
- `after`: Cursor for pagination, used only by the get_review_comments method. Pass the endCursor from the previous page's PageInfo to fetch the next page. (string, optional)
- `include_reactions`: Include reaction counts for get_reviews or get_review_comments. Defaults to false. (boolean, optional)
- `method`: Action to specify what pull request data needs to be retrieved from GitHub.
Possible options:
1. get - Get details of a specific pull request.
Expand Down
100 changes: 100 additions & 0 deletions pkg/github/__toolsnaps__/pull_request_read.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"description": "Cursor for pagination, used only by the get_review_comments method. Pass the endCursor from the previous page's PageInfo to fetch the next page.",
"type": "string"
},
"include_reactions": {
"description": "Include reaction counts for get_reviews or get_review_comments. Defaults to false.",
"type": "boolean"
},
"method": {
"description": "Action to specify what pull request data needs to be retrieved from GitHub. \nPossible options: \n 1. get - Get details of a specific pull request.\n 2. get_diff - Get the diff of a pull request.\n 3. get_status - Get combined commit status of a head commit in a pull request.\n 4. get_files - Get the list of files changed in a pull request. Use with pagination parameters to control the number of results returned.\n 5. get_commits - Get the list of commits on a pull request. Use with pagination parameters to control the number of results returned.\n 6. get_review_comments - Get review threads on a pull request. Each thread contains logically grouped review comments made on the same code location during pull request reviews. Returns thread metadata and comments with nullable current and original line-range coordinates (line, start_line, original_line, original_start_line). Current coordinates are omitted when unavailable, such as for outdated comments. Use cursor-based pagination (perPage, after) to control results.\n 7. get_reviews - Get the reviews on a pull request. When asked for review comments, use get_review_comments method. Use with pagination parameters to control the number of results returned.\n 8. get_comments - Get comments on a pull request. Use this if user doesn't specifically want review comments. Use with pagination parameters to control the number of results returned.\n 9. get_check_runs - Get check runs for the head commit of a pull request. Check runs are the individual CI/CD jobs and checks that run on the PR.\n",
"enum": [
Expand Down Expand Up @@ -505,6 +509,54 @@
"path": {
"type": "string"
},
"reactions": {
"additionalProperties": false,
"properties": {
"+1": {
"type": "integer"
},
"-1": {
"type": "integer"
},
"confused": {
"type": "integer"
},
"eyes": {
"type": "integer"
},
"heart": {
"type": "integer"
},
"hooray": {
"type": "integer"
},
"laugh": {
"type": "integer"
},
"rocket": {
"type": "integer"
},
"total_count": {
"description": "Total number of results.",
"type": "integer"
}
},
"required": [
"total_count",
"+1",
"-1",
"laugh",
"confused",
"heart",
"hooray",
"rocket",
"eyes"
],
"type": [
"null",
"object"
]
},
"start_line": {
"description": "One-based diff line number.",
"type": [
Expand Down Expand Up @@ -768,6 +820,54 @@
"id": {
"type": "integer"
},
"reactions": {
"additionalProperties": false,
"properties": {
"+1": {
"type": "integer"
},
"-1": {
"type": "integer"
},
"confused": {
"type": "integer"
},
"eyes": {
"type": "integer"
},
"heart": {
"type": "integer"
},
"hooray": {
"type": "integer"
},
"laugh": {
"type": "integer"
},
"rocket": {
"type": "integer"
},
"total_count": {
"description": "Total number of results.",
"type": "integer"
}
},
"required": [
"total_count",
"+1",
"-1",
"laugh",
"confused",
"heart",
"hooray",
"rocket",
"eyes"
],
"type": [
"null",
"object"
]
},
"state": {
"description": "Review state; empty for a sparse response.",
"enum": [
Expand Down
16 changes: 9 additions & 7 deletions pkg/github/consolidated_pull_request_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import (
)

type PullRequestReadInput struct {
Method string `json:"method"`
Owner string `json:"owner"`
Repo string `json:"repo"`
PullNumber int `json:"pullNumber"`
Page *int `json:"page,omitempty"`
PerPage *int `json:"perPage,omitempty"`
After *string `json:"after,omitempty"`
Method string `json:"method"`
Owner string `json:"owner"`
Repo string `json:"repo"`
PullNumber int `json:"pullNumber"`
Page *int `json:"page,omitempty"`
PerPage *int `json:"perPage,omitempty"`
After *string `json:"after,omitempty"`
IncludeReactions bool `json:"include_reactions,omitempty"`
}

type CreatePullRequestInput struct {
Expand Down Expand Up @@ -415,6 +416,7 @@ var pullRequestArgumentSpecs = map[string]pullRequestArgumentSpec{
"read": {
required: []string{"method", "owner", "repo"}, requiredInts: []string{"pullNumber"},
ints: []string{"page", "perPage"},
bools: []string{"include_reactions"},
methods: []string{"get", "get_diff", "get_status", "get_files", "get_commits", "get_review_comments", "get_reviews", "get_comments", "get_check_runs"},
},
"create": {
Expand Down
47 changes: 25 additions & 22 deletions pkg/github/minimal_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,14 +781,15 @@ type MinimalProjectStatusUpdate struct {

// MinimalPullRequestReview is the trimmed output type for pull request review objects to reduce verbosity.
type MinimalPullRequestReview struct {
ID int64 `json:"id"`
State string `json:"state"`
Body string `json:"body,omitempty"`
HTMLURL string `json:"html_url"`
User *MinimalUser `json:"user,omitempty"`
CommitID string `json:"commit_id,omitempty"`
SubmittedAt string `json:"submitted_at,omitempty"`
AuthorAssociation string `json:"author_association,omitempty"`
ID int64 `json:"id"`
State string `json:"state"`
Body string `json:"body,omitempty"`
HTMLURL string `json:"html_url"`
User *MinimalUser `json:"user,omitempty"`
CommitID string `json:"commit_id,omitempty"`
SubmittedAt string `json:"submitted_at,omitempty"`
AuthorAssociation string `json:"author_association,omitempty"`
Reactions *MinimalReactions `json:"reactions,omitempty"`
}

// Helper functions
Expand Down Expand Up @@ -1947,16 +1948,17 @@ type MinimalPageInfo struct {

// MinimalReviewComment is the trimmed output type for PR review comment objects.
type MinimalReviewComment struct {
Body string `json:"body,omitempty"`
Path string `json:"path"`
Line *int `json:"line,omitempty"`
OriginalLine *int `json:"original_line,omitempty"`
StartLine *int `json:"start_line,omitempty"`
OriginalStartLine *int `json:"original_start_line,omitempty"`
Author string `json:"author,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
HTMLURL string `json:"html_url"`
Body string `json:"body,omitempty"`
Path string `json:"path"`
Line *int `json:"line,omitempty"`
OriginalLine *int `json:"original_line,omitempty"`
StartLine *int `json:"start_line,omitempty"`
OriginalStartLine *int `json:"original_start_line,omitempty"`
Author string `json:"author,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
HTMLURL string `json:"html_url"`
Reactions *MinimalReactions `json:"reactions,omitempty"`
}

// MinimalReviewThread is the trimmed output type for PR review thread objects.
Expand Down Expand Up @@ -2285,10 +2287,11 @@ func convertToMinimalReviewThread(thread reviewThreadNode) MinimalReviewThread {

func convertToMinimalReviewComment(c reviewCommentNode) MinimalReviewComment {
m := MinimalReviewComment{
Body: sanitize.Content(string(c.Body)),
Path: string(c.Path),
Author: string(c.Author.Login),
HTMLURL: c.URL.String(),
Body: sanitize.Content(string(c.Body)),
Path: string(c.Path),
Author: string(c.Author.Login),
HTMLURL: c.URL.String(),
Reactions: summarizeReviewReactions(c.ReactionGroups),
}

if c.Line != nil {
Expand Down
106 changes: 96 additions & 10 deletions pkg/github/pullrequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Possible options:
Type: "number",
Description: "Pull request number",
},
"include_reactions": {
Type: "boolean",
Description: "Include reaction counts for get_reviews or get_review_comments. Defaults to false.",
},
},
Required: []string{"method", "owner", "repo", "pullNumber"},
}
Expand Down Expand Up @@ -148,10 +152,10 @@ Possible options:
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
result, output, err := getPullRequestReviewComments(ctx, gqlClient, deps, owner, repo, pullNumber, cursorPagination)
result, output, err := getPullRequestReviewComments(ctx, gqlClient, deps, owner, repo, pullNumber, cursorPagination, input.IncludeReactions)
return attachIFC(result), output, err
case "get_reviews":
result, output, err := getPullRequestReviews(ctx, client, deps, owner, repo, pullNumber, pagination)
result, output, err := getPullRequestReviews(ctx, client, deps, owner, repo, pullNumber, pagination, input.IncludeReactions)
return attachIFC(result), output, err
case "get_comments":
result, output, err := getIssueComments(ctx, client, deps, owner, repo, pullNumber, pagination)
Expand Down Expand Up @@ -510,9 +514,47 @@ type reviewCommentNode struct {
Author struct {
Login githubv4.String
}
CreatedAt githubv4.DateTime
UpdatedAt githubv4.DateTime
URL githubv4.URI
CreatedAt githubv4.DateTime
UpdatedAt githubv4.DateTime
URL githubv4.URI
ReactionGroups []reviewReactionGroup `graphql:"reactionGroups @include(if: $includeReactions)"`
}

type reviewReactionGroup struct {
Content githubv4.ReactionContent
Users struct {
TotalCount githubv4.Int
} `graphql:"users: reactors(first: 1)"`
}

func summarizeReviewReactions(groups []reviewReactionGroup) *MinimalReactions {
if groups == nil {
return nil
}
summary := &MinimalReactions{}
for _, group := range groups {
count := int(group.Users.TotalCount)
summary.TotalCount += count
switch group.Content {
case githubv4.ReactionContentThumbsUp:
summary.PlusOne = count
case githubv4.ReactionContentThumbsDown:
summary.MinusOne = count
case githubv4.ReactionContentLaugh:
summary.Laugh = count
case githubv4.ReactionContentConfused:
summary.Confused = count
case githubv4.ReactionContentHeart:
summary.Heart = count
case githubv4.ReactionContentHooray:
summary.Hooray = count
case githubv4.ReactionContentRocket:
summary.Rocket = count
case githubv4.ReactionContentEyes:
summary.Eyes = count
}
}
return summary
}

type pageInfoFragment struct {
Expand All @@ -523,11 +565,11 @@ type pageInfoFragment struct {
}

func GetPullRequestReviewComments(ctx context.Context, gqlClient *githubv4.Client, deps ToolDependencies, owner, repo string, pullNumber int, pagination CursorPaginationParams) (*mcp.CallToolResult, error) {
result, _, err := getPullRequestReviewComments(ctx, gqlClient, deps, owner, repo, pullNumber, pagination)
result, _, err := getPullRequestReviewComments(ctx, gqlClient, deps, owner, repo, pullNumber, pagination, false)
return result, err
}

func getPullRequestReviewComments(ctx context.Context, gqlClient *githubv4.Client, deps ToolDependencies, owner, repo string, pullNumber int, pagination CursorPaginationParams) (*mcp.CallToolResult, *PullRequestReadOutput, error) {
func getPullRequestReviewComments(ctx context.Context, gqlClient *githubv4.Client, deps ToolDependencies, owner, repo string, pullNumber int, pagination CursorPaginationParams, includeReactions bool) (*mcp.CallToolResult, *PullRequestReadOutput, error) {
cache, err := deps.GetRepoAccessCache(ctx)
if err != nil {
return nil, nil, fmt.Errorf("failed to get repo access cache: %w", err)
Expand All @@ -547,6 +589,7 @@ func getPullRequestReviewComments(ctx context.Context, gqlClient *githubv4.Clien
"prNum": githubv4.Int(int32(pullNumber)), //nolint:gosec // pullNumber is controlled by user input validation
"first": githubv4.Int(*gqlParams.First),
"commentsPerThread": githubv4.Int(100),
"includeReactions": githubv4.Boolean(includeReactions),
}

// Add cursor if provided
Expand Down Expand Up @@ -599,11 +642,11 @@ func getPullRequestReviewComments(ctx context.Context, gqlClient *githubv4.Clien
}

func GetPullRequestReviews(ctx context.Context, client *github.Client, deps ToolDependencies, owner, repo string, pullNumber int, pagination PaginationParams) (*mcp.CallToolResult, error) {
result, _, err := getPullRequestReviews(ctx, client, deps, owner, repo, pullNumber, pagination)
result, _, err := getPullRequestReviews(ctx, client, deps, owner, repo, pullNumber, pagination, false)
return result, err
}

func getPullRequestReviews(ctx context.Context, client *github.Client, deps ToolDependencies, owner, repo string, pullNumber int, pagination PaginationParams) (*mcp.CallToolResult, *PullRequestReadOutput, error) {
func getPullRequestReviews(ctx context.Context, client *github.Client, deps ToolDependencies, owner, repo string, pullNumber int, pagination PaginationParams, includeReactions bool) (*mcp.CallToolResult, *PullRequestReadOutput, error) {
cache, err := deps.GetRepoAccessCache(ctx)
if err != nil {
return nil, nil, fmt.Errorf("failed to get repo access cache: %w", err)
Expand Down Expand Up @@ -652,14 +695,57 @@ func getPullRequestReviews(ctx context.Context, client *github.Client, deps Tool
reviews = filteredReviews
}

var reactions map[string]*MinimalReactions
if includeReactions {
reactions, err = fetchReviewReactions(ctx, deps, reviews)
if err != nil {
return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "failed to get pull request review reactions", err), nil, nil
}
}
minimalReviews := make([]MinimalPullRequestReview, 0, len(reviews))
for _, review := range reviews {
minimalReviews = append(minimalReviews, convertToMinimalPullRequestReview(review))
minimal := convertToMinimalPullRequestReview(review)
minimal.Reactions = reactions[review.GetNodeID()]
minimalReviews = append(minimalReviews, minimal)
}

return MarshalledTextResult(minimalReviews), &PullRequestReadOutput{Reviews: &minimalReviews}, nil
}

func fetchReviewReactions(ctx context.Context, deps ToolDependencies, reviews []*github.PullRequestReview) (map[string]*MinimalReactions, error) {
ids := make([]githubv4.ID, 0, len(reviews))
for _, review := range reviews {
if id := review.GetNodeID(); id != "" {
ids = append(ids, githubv4.ID(id))
}
}
if len(ids) == 0 {
return nil, nil
}
client, err := deps.GetGQLClient(ctx)
if err != nil {
return nil, err
}
var query struct {
Nodes []struct {
Review struct {
ID githubv4.ID
ReactionGroups []reviewReactionGroup
} `graphql:"... on PullRequestReview"`
} `graphql:"nodes(ids: $ids)"`
}
if err := client.Query(ctx, &query, map[string]any{"ids": ids}); err != nil {
return nil, err
}
reactions := make(map[string]*MinimalReactions, len(query.Nodes))
for _, node := range query.Nodes {
if id, ok := node.Review.ID.(string); ok {
reactions[id] = summarizeReviewReactions(node.Review.ReactionGroups)
}
}
return reactions, nil
}

// PullRequestWriteUIResourceURI is the URI for the create_pull_request tool's MCP App UI resource.
const PullRequestWriteUIResourceURI = "ui://github-mcp-server/pr-write"

Expand Down
Loading