feat: return minimal code search results with text match snippets#2476
Open
SamMorrowDrums wants to merge 3 commits into
Open
feat: return minimal code search results with text match snippets#2476SamMorrowDrums wants to merge 3 commits into
SamMorrowDrums wants to merge 3 commits into
Conversation
Return a MinimalCodeSearchResult type from search_code instead of the raw GitHub API CodeSearchResult. This reduces token usage by ~4x by: - Projecting the repository object to just the full_name string instead of the full ~3KB repository payload repeated per result - Enabling the text-match Accept header so code snippets (fragments) are included in results, which were previously missing Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the search_code MCP tool output by returning a trimmed code search response and requesting GitHub text-match snippets, reducing context-window bloat while making search hits more useful.
Changes:
- Enables text-match snippets for GitHub code search requests.
- Adds minimal code search response/result types.
- Updates code search tests to validate the new minimal output and preserved snippets.
Show a summary per file
| File | Description |
|---|---|
pkg/github/search.go |
Requests text matches and maps raw code search results into minimal output. |
pkg/github/search_test.go |
Updates code search assertions for the minimal response shape and snippets. |
pkg/github/minimal_types.go |
Adds minimal code search result structs. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 2
| Order: order, | ||
| Sort: sort, | ||
| Order: order, | ||
| TextMatch: true, |
Comment on lines
+320
to
+326
| minimalResult := &MinimalCodeSearchResult{ | ||
| TotalCount: result.GetTotal(), | ||
| IncompleteResults: result.GetIncompleteResults(), | ||
| Items: minimalItems, | ||
| } | ||
|
|
||
| r, err := json.Marshal(minimalResult) |
The URL is derivable from repository + path + sha, so it's redundant token cost per result. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Address PR review feedback: 1. Add minimal_output parameter (default: true) to search_code, matching the pattern from search_repositories. When false, returns the full GitHub API CodeSearchResult for backward compatibility. 2. Add Accept header assertion to tests via a new withHeaders() helper on partialMock, verifying the text-match Accept header is actually requested (not just mocked in the response). 3. Add test case for minimal_output=false path. Co-authored-by: Copilot <223556219+Copilot@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.
Summary
The
search_codeMCP tool was returning the raw GitHub REST APICodeSearchResult, which includes the full~3KBrepository object repeated per result — and was not requesting text match snippets. This made it the worst option for agent context windows: ~34K tokens for 30 results with no code snippets.This PR fixes both problems:
Changes
MinimalCodeSearchResult/MinimalCodeResulttypes project each result down toname,path,sha,html_url,repository(just the full name string), andtext_matches. This eliminates ~30 duplicated templated URL fields per result.TextMatch: trueonSearchOptions, which causes go-github to send theapplication/vnd.github.v3.text-match+jsonAccept header. Results now include the matched code fragments that were previously missing entirely.Impact
No schema change to the tool inputs — this is purely an output improvement.