Reduce context usage when getting issue comments using issue_read#2024
Merged
tommaso-moro merged 1 commit intomainfrom Feb 17, 2026
Merged
Reduce context usage when getting issue comments using issue_read#2024tommaso-moro merged 1 commit intomainfrom
issue_read#2024tommaso-moro merged 1 commit intomainfrom
Conversation
issue_read
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes token usage for issue comment retrieval by introducing a minimal type pattern. When getting issue comments via the issue_read tool, the PR reduces context window consumption by approximately 57% (from 1500 to 645 tokens in the tested example) by stripping unnecessary fields from the API response while preserving all semantically important information.
Changes:
- Added
MinimalIssueCommenttype following established patterns forMinimalIssue,MinimalPullRequest, andMinimalCommit - Implemented converter function
convertToMinimalIssueCommentthat strips verbose fields (node_id, full User object, API URLs) while preserving essential data (id, body, html_url, minimal user, author_association, reactions, timestamps) - Updated
GetIssueCommentsto return minimal types, benefiting both issue comments and PR comments (which share the same endpoint)
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 MinimalIssueComment type definition and convertToMinimalIssueComment converter function following established minimal type patterns |
| pkg/github/issues.go | Updated GetIssueComments to convert API responses to MinimalIssueComment array using MarshalledTextResult helper |
| pkg/github/issues_test.go | Updated test assertions to expect MinimalIssueComment type instead of full github.IssueComment |
JoannaaKL
approved these changes
Feb 17, 2026
tonytrg
approved these changes
Feb 17, 2026
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.
Summary
This PR reduces the context window usage by when getting issue comments using the
issue_readtool. For example, when tested on this issue #950 we achieved a ~57% reduction in tokens usage.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, some irrelevant fields are removed, and nested objects are largely optimized by keeping only the strictly necessary fields.
Tests & Metrics
Tested using this issue: #950
Results: tokens consumption went from 1500 to 645, achieving a ~57% reduction in tokens usage.
Tokens were measured using the OpenAI Tokenizer
Fields preserved
id,body,html_url,user(asMinimalUser),author_association,reactions(but removed theurlfield from the reactions object),created_at,updated_atFields dropped
node_id, fullUserobject (~17 fields reduced to 4 viaMinimalUser), API URL strings (url,issue_url), reactionsurlfieldBefore
Old payload (1500 tokens)
[ { "id": 3227918923, "node_id": "IC_kwDOODGMVM7AZiJL", "body": "➕ I would find this useful as well, especially for parent child relationships, as we are coming to rely on those internally as opposed to textual links, and Copilot is missing important context from parent issues, or the existence of child issues.", "user": { "login": "C-Ross", "id": 1790229, "node_id": "MDQ6VXNlcjE3OTAyMjk=", "avatar_url": "https://avatars.githubusercontent.com/u/1790229?v=4", "html_url": "https://github.com/C-Ross", "gravatar_id": "", "type": "User", "site_admin": true, "url": "https://api.github.com/users/C-Ross", "events_url": "https://api.github.com/users/C-Ross/events{/privacy}", "following_url": "https://api.github.com/users/C-Ross/following{/other_user}", "followers_url": "https://api.github.com/users/C-Ross/followers", "gists_url": "https://api.github.com/users/C-Ross/gists{/gist_id}", "organizations_url": "https://api.github.com/users/C-Ross/orgs", "received_events_url": "https://api.github.com/users/C-Ross/received_events", "repos_url": "https://api.github.com/users/C-Ross/repos", "starred_url": "https://api.github.com/users/C-Ross/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/C-Ross/subscriptions" }, "reactions": { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "confused": 0, "heart": 0, "hooray": 0, "rocket": 0, "eyes": 0, "url": "https://api.github.com/repos/github/github-mcp-server/issues/comments/3227918923/reactions" }, "created_at": "2025-08-27T12:05:28Z", "updated_at": "2025-08-27T12:05:28Z", "author_association": "MEMBER", "url": "https://api.github.com/repos/github/github-mcp-server/issues/comments/3227918923", "html_url": "https://github.com/github/github-mcp-server/issues/950#issuecomment-3227918923", "issue_url": "https://api.github.com/repos/github/github-mcp-server/issues/950" }, { "id": 3784634143, "node_id": "IC_kwDOODGMVM7hlO8f", "body": "Would be great to not only support reading, but also support updating issue dependencies via MCP.", "user": { "login": "jordanjennings", "id": 1031913, "node_id": "MDQ6VXNlcjEwMzE5MTM=", "avatar_url": "https://avatars.githubusercontent.com/u/1031913?v=4", "html_url": "https://github.com/jordanjennings", "gravatar_id": "", "type": "User", "site_admin": false, "url": "https://api.github.com/users/jordanjennings", "events_url": "https://api.github.com/users/jordanjennings/events{/privacy}", "following_url": "https://api.github.com/users/jordanjennings/following{/other_user}", "followers_url": "https://api.github.com/users/jordanjennings/followers", "gists_url": "https://api.github.com/users/jordanjennings/gists{/gist_id}", "organizations_url": "https://api.github.com/users/jordanjennings/orgs", "received_events_url": "https://api.github.com/users/jordanjennings/received_events", "repos_url": "https://api.github.com/users/jordanjennings/repos", "starred_url": "https://api.github.com/users/jordanjennings/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jordanjennings/subscriptions" }, "reactions": { "total_count": 1, "+1": 1, "-1": 0, "laugh": 0, "confused": 0, "heart": 0, "hooray": 0, "rocket": 0, "eyes": 0, "url": "https://api.github.com/repos/github/github-mcp-server/issues/comments/3784634143/reactions" }, "created_at": "2026-01-22T14:16:35Z", "updated_at": "2026-01-22T14:16:35Z", "author_association": "NONE", "url": "https://api.github.com/repos/github/github-mcp-server/issues/comments/3784634143", "html_url": "https://github.com/github/github-mcp-server/issues/950#issuecomment-3784634143", "issue_url": "https://api.github.com/repos/github/github-mcp-server/issues/950" }, { "id": 3810689057, "node_id": "IC_kwDOODGMVM7jIoAh", "body": "@tommaso-moro you could use my mcp while we are awaiting this to be implemented. link: https://github.com/[chuks-qua/github-issues-mcp-server](https://github.com/chuks-qua/github-issues-mcp-server). \n\ndoes all you need. \n\nI would love this to be assigned to me, although go lang is not my strong suite", "user": { "login": "chuks-qua", "id": 142016413, "node_id": "U_kgDOCHb_nQ", "avatar_url": "https://avatars.githubusercontent.com/u/142016413?v=4", "html_url": "https://github.com/chuks-qua", "gravatar_id": "", "type": "User", "site_admin": false, "url": "https://api.github.com/users/chuks-qua", "events_url": "https://api.github.com/users/chuks-qua/events{/privacy}", "following_url": "https://api.github.com/users/chuks-qua/following{/other_user}", "followers_url": "https://api.github.com/users/chuks-qua/followers", "gists_url": "https://api.github.com/users/chuks-qua/gists{/gist_id}", "organizations_url": "https://api.github.com/users/chuks-qua/orgs", "received_events_url": "https://api.github.com/users/chuks-qua/received_events", "repos_url": "https://api.github.com/users/chuks-qua/repos", "starred_url": "https://api.github.com/users/chuks-qua/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/chuks-qua/subscriptions" }, "reactions": { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "confused": 0, "heart": 0, "hooray": 0, "rocket": 0, "eyes": 0, "url": "https://api.github.com/repos/github/github-mcp-server/issues/comments/3810689057/reactions" }, "created_at": "2026-01-28T11:15:25Z", "updated_at": "2026-01-28T11:15:25Z", "author_association": "NONE", "url": "https://api.github.com/repos/github/github-mcp-server/issues/comments/3810689057", "html_url": "https://github.com/github/github-mcp-server/issues/950#issuecomment-3810689057", "issue_url": "https://api.github.com/repos/github/github-mcp-server/issues/950" } ]After
New payload: 645 tokens
[ { "id": 3227918923, "body": "➕ I would find this useful as well, especially for parent child relationships, as we are coming to rely on those internally as opposed to textual links, and Copilot is missing important context from parent issues, or the existence of child issues.", "html_url": "https://github.com/github/github-mcp-server/issues/950#issuecomment-3227918923", "user": { "login": "C-Ross", "id": 1790229, "profile_url": "https://github.com/C-Ross", "avatar_url": "https://avatars.githubusercontent.com/u/1790229?v=4" }, "author_association": "MEMBER", "reactions": { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "confused": 0, "heart": 0, "hooray": 0, "rocket": 0, "eyes": 0 }, "created_at": "2025-08-27T12:05:28Z", "updated_at": "2025-08-27T12:05:28Z" }, { "id": 3784634143, "body": "Would be great to not only support reading, but also support updating issue dependencies via MCP.", "html_url": "https://github.com/github/github-mcp-server/issues/950#issuecomment-3784634143", "user": { "login": "jordanjennings", "id": 1031913, "profile_url": "https://github.com/jordanjennings", "avatar_url": "https://avatars.githubusercontent.com/u/1031913?v=4" }, "author_association": "NONE", "reactions": { "total_count": 1, "+1": 1, "-1": 0, "laugh": 0, "confused": 0, "heart": 0, "hooray": 0, "rocket": 0, "eyes": 0 }, "created_at": "2026-01-22T14:16:35Z", "updated_at": "2026-01-22T14:16:35Z" }, { "id": 3810689057, "body": "@tommaso-moro you could use my mcp while we are awaiting this to be implemented. link: https://github.com/[chuks-qua/github-issues-mcp-server](https://github.com/chuks-qua/github-issues-mcp-server). \n\ndoes all you need. \n\nI would love this to be assigned to me, although go lang is not my strong suite", "html_url": "https://github.com/github/github-mcp-server/issues/950#issuecomment-3810689057", "user": { "login": "chuks-qua", "id": 142016413, "profile_url": "https://github.com/chuks-qua", "avatar_url": "https://avatars.githubusercontent.com/u/142016413?v=4" }, "author_association": "NONE", "reactions": { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "confused": 0, "heart": 0, "hooray": 0, "rocket": 0, "eyes": 0 }, "created_at": "2026-01-28T11:15:25Z", "updated_at": "2026-01-28T11:15:25Z" } ]Why
The full
github.IssueCommentpayload returned by the GitHub API is unnecessarily verbose for model reasoning. Most of its size comes from a fullUserobject (17 fields each) repeated on every comment, API URL strings (url,issue_url) that duplicate information already known from context, and anode_idfield not useful for model reasoning. Since comments are returned as arrays, the wasted tokens multiply across every comment in the response, making this a high-impact optimization for one of the most frequently called operations.What changed
MinimalIssueCommenttype tominimal_types.go, following the existingMinimalCommit/MinimalRepository/MinimalPullRequest/MinimalIssuepatternconvertToMinimalIssueCommentconverter functionGetIssueCommentsto return[]MinimalIssueCommentviaMarshalledTextResultinstead of rawjson.Marshal(comments)MinimalIssueCommentfieldsMCP impact
Prompts tested (tool changes only)
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