Skip to content

Reduce context usage when getting issue comments using issue_read#2024

Merged
tommaso-moro merged 1 commit intomainfrom
tommy/reduce-issue-comments-context
Feb 17, 2026
Merged

Reduce context usage when getting issue comments using issue_read#2024
tommaso-moro merged 1 commit intomainfrom
tommy/reduce-issue-comments-context

Conversation

@tommaso-moro
Copy link
Contributor

@tommaso-moro tommaso-moro commented Feb 17, 2026

Summary

This PR reduces the context window usage by when getting issue comments using the issue_read tool. 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 (as MinimalUser), author_association, reactions (but removed the url field from the reactions object), created_at, updated_at

Fields dropped

node_id, full User object (~17 fields reduced to 4 via MinimalUser), API URL strings (url, issue_url), reactions url field

Before

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.IssueComment payload returned by the GitHub API is unnecessarily verbose for model reasoning. Most of its size comes from a full User object (17 fields each) repeated on every comment, API URL strings (url, issue_url) that duplicate information already known from context, and a node_id field 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

  • Added MinimalIssueComment type to minimal_types.go, following the existing MinimalCommit/MinimalRepository/MinimalPullRequest/MinimalIssue pattern
  • Added convertToMinimalIssueComment converter function
  • Updated GetIssueComments to return []MinimalIssueComment via MarshalledTextResult instead of raw json.Marshal(comments)
  • Updated tests to assert against MinimalIssueComment fields

MCP impact

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

Prompts tested (tool changes only)

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 marked this pull request as ready for review February 17, 2026 12:17
@tommaso-moro tommaso-moro requested a review from a team as a code owner February 17, 2026 12:17
Copilot AI review requested due to automatic review settings February 17, 2026 12:17
@tommaso-moro tommaso-moro changed the title use minimal types for issue comments to optimize context usage Reduce context usage when getting issue comments using issue_read Feb 17, 2026
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 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 MinimalIssueComment type following established patterns for MinimalIssue, MinimalPullRequest, and MinimalCommit
  • Implemented converter function convertToMinimalIssueComment that 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 GetIssueComments to 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

@tommaso-moro tommaso-moro merged commit 543a1fa into main Feb 17, 2026
22 checks passed
@tommaso-moro tommaso-moro deleted the tommy/reduce-issue-comments-context branch February 17, 2026 12:36
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.

3 participants