Skip to content

Comments

Reduce context usage for get_pull-request_reviews#2066

Open
tommaso-moro wants to merge 1 commit intomainfrom
tommy/pr-reviews-context-reduction
Open

Reduce context usage for get_pull-request_reviews#2066
tommaso-moro wants to merge 1 commit intomainfrom
tommy/pr-reviews-context-reduction

Conversation

@tommaso-moro
Copy link
Contributor

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_read tool (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 User object is flattened to a MinimalUser, 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 (as MinimalUser), commit_id, submitted_at, author_association

Fields dropped

node_id (internal GitHub identifier, not useful for reasoning), pull_request_url (API URL string, never used by models), full User object (replaced with MinimalUser containing only login, id, profile_url, avatar_url)

Why

The full github.PullRequestReview payload returned by the GitHub API includes a full nested User object with dozens of fields (avatar URLs, API URLs, permissions, etc.) per review, plus API-internal fields like node_id and pull_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

  • Added MinimalPullRequestReview type to minimal_types.go, following the existing MinimalIssueComment/MinimalPullRequest pattern — includes commit_id, submitted_at, and author_association which are relevant for review context
  • Added convertToMinimalPullRequestReview converter function
  • Updated GetPullRequestReviews to return []MinimalPullRequestReview via MarshalledTextResult instead of raw json.Marshal(reviews)
  • Updated tests to assert against MinimalPullRequestReview fields

MCP impact

  • No tool or API changes
  • Tool schema or behavior changed
  • New tool added

Security / limits

  • No security or limits impact
  • Auth / permissions considered
  • Data exposure, filtering, or token/size limits considered

Tool renaming

  • I am renaming tools as part of this PR (e.g. a part of a consolidation effort)
    • I have added the new tool aliases in deprecated_tool_aliases.go
  • I am not renaming tools as part of this PR

Note: 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

  • Linted locally with ./script/lint
  • Tested locally with ./script/test

Docs

  • Not needed
  • Updated (README / docs / examples)

@tommaso-moro tommaso-moro requested a review from a team as a code owner February 23, 2026 14:18
Copilot AI review requested due to automatic review settings February 23, 2026 14:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MinimalPullRequestReview type with essential review fields (ID, state, body, HTML URL, user, commit ID, submitted timestamp, author association)
  • Implemented convertToMinimalPullRequestReview converter function following existing patterns
  • Updated GetPullRequestReviews to use the new minimal type via MarshalledTextResult

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant