Skip to content

Comments

Reduce context for add_issue_comments using minimal types#2063

Open
tommaso-moro wants to merge 2 commits intomainfrom
tommy/reduce-context-for-add-issue-comments
Open

Reduce context for add_issue_comments using minimal types#2063
tommaso-moro wants to merge 2 commits intomainfrom
tommy/reduce-context-for-add-issue-comments

Conversation

@tommaso-moro
Copy link
Contributor

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

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_comment tool.

Since add_issue_comment is a "create" operation, the full github.IssueComment response is replaced with MinimalResponse{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 (as url)

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.IssueComment payload 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

  • Updated AddIssueComment handler in issues.go to return MinimalResponse{ID, URL} instead of raw json.Marshal(createdComment)
  • Updated Test_AddIssueComment in issues_test.go to assert against MinimalResponse fields instead of github.IssueComment

MCP impact

  • No tool or API changes
  • Tool schema or behavior changed — response payload reduced to MinimalResponse
  • 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 marked this pull request as ready for review February 23, 2026 12:34
@tommaso-moro tommaso-moro requested a review from a team as a code owner February 23, 2026 12:34
Copilot AI review requested due to automatic review settings February 23, 2026 12:34
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 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 AddIssueComment handler to return MinimalResponse{ID, URL} instead of the full github.IssueComment
  • Modified test to validate against MinimalResponse fields 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

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