Reduce context usage for get_pull-request_reviews#2066
Open
tommaso-moro wants to merge 1 commit intomainfrom
Open
Reduce context usage for get_pull-request_reviews#2066tommaso-moro wants to merge 1 commit intomainfrom
get_pull-request_reviews#2066tommaso-moro wants to merge 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces context window usage by 43% when fetching pull request reviews through the pull_request_read tool's get_pull_request_reviews method. It implements the minimal types pattern that's already established in the codebase for similar operations (issues, pull requests, commits), converting the full github.PullRequestReview objects to a streamlined MinimalPullRequestReview type that preserves essential fields while eliminating API URLs, nested objects, and pointer-wrapped primitives.
Changes:
- Added
MinimalPullRequestReviewtype with essential review fields (ID, state, body, HTML URL, user, commit ID, submitted timestamp, author association) - Implemented
convertToMinimalPullRequestReviewconverter function following existing patterns - Updated
GetPullRequestReviewsto use the new minimal type viaMarshalledTextResult
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/github/minimal_types.go | Added MinimalPullRequestReview struct and convertToMinimalPullRequestReview converter function following established minimal types pattern |
| pkg/github/pullrequests.go | Updated GetPullRequestReviews to convert reviews to minimal type using MarshalledTextResult helper |
| pkg/github/pullrequests_test.go | Updated test assertions to expect MinimalPullRequestReview instead of full github.PullRequestReview objects |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: https://github.com/github/copilot-mcp-core/issues/1315
Summary
This PR reduces the context window usage when fetching pull request reviews using the
pull_request_readtool (get_pull_request_reviews).It does so by using the minimal types pattern (which is already used elsewhere in the codebase for the same reason) to reduce the payload that is sent back to the model when the tool is used. Specifically, the full nested
Userobject is flattened to aMinimalUser, irrelevant API URL fields are removed, and pointer-wrapped primitives are flattened to value types, eliminating unnecessary JSON noise per review entry.Tests & Metrics: >43% context reduction
Before: 10716 tokens
After: 6088 tokens
Context reduction: 43.18%
(PR used for testing: https://github.com/github/github-mcp-server/pull/1957/changes)
Tokens measures using OpenAI's tokenizer.
Fields preserved
id,state,body,html_url,user(asMinimalUser),commit_id,submitted_at,author_associationFields dropped
node_id(internal GitHub identifier, not useful for reasoning),pull_request_url(API URL string, never used by models), fullUserobject (replaced withMinimalUsercontaining onlylogin,id,profile_url,avatar_url)Why
The full
github.PullRequestReviewpayload returned by the GitHub API includes a full nestedUserobject with dozens of fields (avatar URLs, API URLs, permissions, etc.) per review, plus API-internal fields likenode_idandpull_request_url. These add up quickly for PRs with many reviews and waste context window on every call. Additionally, the raw Go types use pointer-wrapped primitives (*string,*int64) which produce noisier JSON than plain value types.What changed
MinimalPullRequestReviewtype tominimal_types.go, following the existingMinimalIssueComment/MinimalPullRequestpattern — includescommit_id,submitted_at, andauthor_associationwhich are relevant for review contextconvertToMinimalPullRequestReviewconverter functionGetPullRequestReviewsto return[]MinimalPullRequestReviewviaMarshalledTextResultinstead of rawjson.Marshal(reviews)MinimalPullRequestReviewfieldsMCP impact
Security / limits
Tool renaming
deprecated_tool_aliases.goNote: if you're renaming tools, you must add the tool aliases. For more information on how to do so, please refer to the official docs.
Lint & tests
./script/lint./script/testDocs