Reduce context for add_issue_comments using minimal types#2063
Open
tommaso-moro wants to merge 2 commits intomainfrom
Open
Reduce context for add_issue_comments using minimal types#2063tommaso-moro wants to merge 2 commits intomainfrom
add_issue_comments using minimal types#2063tommaso-moro wants to merge 2 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces token usage for the add_issue_comment tool response by replacing the full github.IssueComment object (530 tokens) with a MinimalResponse containing only id and url fields (37 tokens), achieving a 93% reduction. This follows the established pattern used by other mutating tools like create_issue, update_issue, create_pull_request, fork_repository, and create_gist.
Changes:
- Updated
AddIssueCommenthandler to returnMinimalResponse{ID, URL}instead of the fullgithub.IssueComment - Modified test to validate against
MinimalResponsefields instead of full comment object
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/github/issues.go | Replaced full github.IssueComment marshaling with MinimalResponse containing formatted ID and HTML URL |
| pkg/github/issues_test.go | Updated test assertions to verify MinimalResponse fields instead of full comment object |
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/orgs/github/projects/21466/views/7?pane=issue&itemId=3977896536&issue=github%7Ccopilot-mcp-core%7C1310
Summary
This PR reduces context window usage when adding issue comments using the
add_issue_commenttool.Since
add_issue_commentis a "create" operation, the fullgithub.IssueCommentresponse is replaced withMinimalResponse{ID, URL}, following the established pattern used by other mutating tools (CreateIssue,UpdateIssue,ForkRepository,CreateGist, etc.). The model already knows everything it sent in the request; the only new information from the API is the comment ID and URL.Tests & Metrics: 93% reduction
Before: 530 tokens
After: 37 tokens
Context reduction: 93%
Tested by adding "Hello World!" as a comment to an issue.
Tokens measured using https://platform.openai.com/tokenizer
BEFORE
Old payload: 530 tokens
{"id":3944417823,"node_id":"IC_kwDOPODl287rGwof","body":"hello, world!","user":{"login":"tommaso-moro","id":37270480,"node_id":"MDQ6VXNlcjM3MjcwNDgw","avatar_url":"https://avatars.githubusercontent.com/u/37270480?u=e3977755cafe4d9d73d5b79b21516a279899edbf\u0026v=4","html_url":"https://github.com/tommaso-moro","gravatar_id":"","type":"User","site_admin":true,"url":"https://api.github.com/users/tommaso-moro","events_url":"https://api.github.com/users/tommaso-moro/events{/privacy}","following_url":"https://api.github.com/users/tommaso-moro/following{/other_user}","followers_url":"https://api.github.com/users/tommaso-moro/followers","gists_url":"https://api.github.com/users/tommaso-moro/gists{/gist_id}","organizations_url":"https://api.github.com/users/tommaso-moro/orgs","received_events_url":"https://api.github.com/users/tommaso-moro/received_events","repos_url":"https://api.github.com/users/tommaso-moro/repos","starred_url":"https://api.github.com/users/tommaso-moro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tommaso-moro/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/tommaso-moro/test-mcp-stuff/issues/comments/3944417823/reactions"},"created_at":"2026-02-23T12:15:13Z","updated_at":"2026-02-23T12:15:13Z","author_association":"OWNER","url":"https://api.github.com/repos/tommaso-moro/test-mcp-stuff/issues/comments/3944417823","html_url":"https://github.com/tommaso-moro/test-mcp-stuff/issues/63#issuecomment-3944417823","issue_url":"https://api.github.com/repos/tommaso-moro/test-mcp-stuff/issues/63"}AFTER
New payload: 37 tokens (93% reduction!)
{"id":"3944415193","url":"https://github.com/tommaso-moro/test-mcp-stuff/issues/63#issuecomment-3944415193"}Fields preserved
id,html_url(asurl)Fields dropped
node_id,body(already known — sent in request),user(nested object with 14 fields — already known),reactions(empty on creation),created_at,updated_at,author_association,url(API URL),issue_url(API URL)Why
The full
github.IssueCommentpayload returned by the GitHub API after creating a comment includes the entire user object (14 fields including API URLs, avatar URLs, gravatar ID), reaction counters (all zero on creation), and multiple API URL strings — none of which provide value to the model. The comment body and authorship are already known from the request context. The only actionable new information is the comment ID (for future edits/deletes) and the HTML URL (for linking).What changed
AddIssueCommenthandler inissues.goto returnMinimalResponse{ID, URL}instead of rawjson.Marshal(createdComment)Test_AddIssueCommentinissues_test.goto assert againstMinimalResponsefields instead ofgithub.IssueCommentMCP impact
MinimalResponseSecurity / 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