[WIP] Optimize MCP tool response payloads to reduce token usage#11958
Closed
[WIP] Optimize MCP tool response payloads to reduce token usage#11958
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Add comprehensive token usage optimization guide - Update GitHub MCP server skill with token usage warnings - Add Options field to GitHubToolConfig for future response-mode support - Add parseGitHubToolOptions function to parse options configuration Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
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.
MCP Tool Response Payload Optimization
This PR optimizes MCP tool response payloads to reduce token usage for workflows using GitHub MCP tools.
Completed
Optionsfield to GitHubToolConfig to pass configuration to GitHub MCP serverRemaining
Implementation
Since gh-aw cannot intercept runtime responses from the GitHub MCP server (it only generates workflow configuration), this PR:
Key Changes
Code Changes:
GitHubToolOptionsstruct withResponseModefield (future-proofing)parseGitHubTool()functiontools_types.goandtools_parser.goDocumentation Changes:
/docs/src/content/docs/guides/optimizing-token-usage.mdwith:list_code_scanning_alerts,list_pull_requests)skills/github-mcp-server/SKILL.mdwith token optimization warningsToken Optimization Strategies Documented
Original prompt
This section details on the original issue you should resolve
<issue_title>[Code Quality] Optimize MCP tool response payloads to reduce token usage</issue_title>
<issue_description>### Description
MCP structural analysis reveals that two GitHub MCP tools return bloated payloads, consuming excessive tokens and degrading performance.
list_code_scanning_alertsreturns 24K tokens (97KB) andlist_pull_requestsduplicates repository objects in every PR result.Current State
Observed payload sizes (from MCP analysis):
list_code_scanning_alerts: 24,000 tokens (97KB) - largest payloadlist_pull_requests: Heavy due to duplicated repository objects in each PRlist_labels,list_branches,list_workflows(minimal payload bloat)Impact
Token Cost:
Performance:
Efficiency Gap:
list_labels,list_branches,list_discussionsremain highly efficientSuggested Changes
Option 1: Return Selective Fields Only
For
list_code_scanning_alerts:For
list_pull_requests:Option 2: Add Summary Modes
Add optional
modeparameter:mode: "summary"→ Minimal fields (default)mode: "full"→ Complete objects (when needed)Option 3: Pagination with Field Selection
Implement field selection in pagination:
Files Affected
This issue likely requires changes in the GitHub MCP server, not gh-aw directly:
github-mcp-serverrepository (if maintained by GitHub)Investigation needed: Determine if gh-aw can implement response filtering or if upstream changes are required.
Success Criteria
list_code_scanning_alertspayload reduced from 24K tokens to <10K tokenslist_pull_requestseliminates duplicated repository objectsAlternative: Workflow Guidance
If upstream changes aren't feasible, add workflow documentation advising:
list_code_scanning_alertsunless essentialSource
Extracted from DeepReport Intelligence Briefing discussion githubnext/gh-aw#11897
Relevant excerpt:
Comparison:
list_labels,list_branches,list_workflows,list_discussionslist_code_scanning_alerts,list_pull_requestsPriority
High - Direct impact on token costs and performance. Token spend concentration analysis shows this affects high-frequency workflows.
Implementation Estimate
Effort: 2-3 days
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.