Skip to content

feat: return minimal code search results with text match snippets - #2476

Merged
JoannaaKL merged 4 commits into
mainfrom
sammorrowdrums/add-minimal-code-search-type
May 14, 2026
Merged

JoannaaKL merged 4 commits into
mainfrom
sammorrowdrums/add-minimal-code-search-type

Conversation

@SamMorrowDrums

Copy link
Copy Markdown
Collaborator

Summary

The search_code MCP tool was returning the raw GitHub REST API CodeSearchResult, which includes the full ~3KB repository 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

  • Minimal output type — New MinimalCodeSearchResult / MinimalCodeResult types project each result down to name, path, sha, html_url, repository (just the full name string), and text_matches. This eliminates ~30 duplicated templated URL fields per result.
  • Text match snippets — Enables TextMatch: true on SearchOptions, which causes go-github to send the application/vnd.github.v3.text-match+json Accept header. Results now include the matched code fragments that were previously missing entirely.
  • Tests updated — Assertions verify the minimal shape and that text match fragments are preserved.

Impact

Metric Before After
~Tokens per 30 results ~34K ~8-9K
Code snippets included
Repository bloat per hit ~3KB full object ~30 bytes (full name string)

No schema change to the tool inputs — this is purely an output improvement.

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>
Copilot AI review requested due to automatic review settings May 13, 2026 22:34
@SamMorrowDrums
SamMorrowDrums requested a review from a team as a code owner May 13, 2026 22:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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

Comment thread pkg/github/search.go
Comment thread pkg/github/search.go
SamMorrowDrums and others added 3 commits May 14, 2026 00:45
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>
The full CodeResult only adds a bloated Repository object (~3KB of
template URLs) and a derivable HTMLURL. Nothing in the full output is
useful beyond what the minimal type already provides, so always return
the compact form.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JoannaaKL
JoannaaKL merged commit fbf68b2 into main May 14, 2026
18 checks passed
@JoannaaKL
JoannaaKL deleted the sammorrowdrums/add-minimal-code-search-type branch May 14, 2026 10:07
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
github-mcp-server 1.0.5

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## What's Changed
* Add ifc label for list_issues tool by @gokhanarkan in github/github-mcp-server#2453
* Add ifc label for get_file_contents tool by @gokhanarkan in github/github-mcp-server#2454
* Add missing pagination on get_reviews by @RossTarrant in github/github-mcp-server#2367
* Add optional `rationale` parameter to `update_issue_type` tool by @alondahari in github/github-mcp-server#2458
* Add ifc label for search_issues tool by @gokhanarkan in github/github-mcp-server#2456
* Add ifc label for issue_read tool by @gokhanarkan in github/github-mcp-server#2457
* Add ifc label for search_repositories tool by @gokhanarkan in github/github-mcp-server#2459
* Return minimal code search results with text match snippets by @SamMorrowDrums in github/github-mcp-server#2476
* Replace ingress IFC reader list with private marker by @gokhanarkan in github/github-mcp-server#2478
* Document Copilot Spaces PAT requirements by @Bestra in github/github-mcp-server#2479
* Add tool to list repo collaborators by @JoannaaKL in github/github-mcp-server#2477
* Add tool for discussion comment write operations by @RossTarrant in github/github-mcp-server#2427
* Upgrade go-github to v 0.87 by @iulia-b in github/github-mcp-server#2452

## New Contributors
* @alondahari made their first contribution in github/github-mcp-server#2458
* @Bestra made their first contribution in github/github-mcp-server#2479

**Full Changelog**: https://github.com/github/github-mcp-server/compare/v1.0.4...v1.0.5</pre>
  <p>View the full release notes at <a href="https://github.com/github/github-mcp-server/releases/tag/v1.0.5">https://github.com/github/github-mcp-server/releases/tag/v1.0.5</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!3094
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