Skip to content

Add bounded GitHub file excerpt MCP wrapper - #50684

Closed
pelikhan with Copilot wants to merge 3 commits into
mainfrom
copilot/deep-report-add-excerpt-range-read-mode
Closed

Add bounded GitHub file excerpt MCP wrapper#50684
pelikhan with Copilot wants to merge 3 commits into
mainfrom
copilot/deep-report-add-excerpt-range-read-mode

Conversation

Copilot AI commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

GitHub MCP get_file_contents only returns whole files, which makes large README-style reads expensive when agents need only a small section. This adds a reusable bounded-read wrapper for workflows that need targeted file context.

  • MCP script wrapper

    • Adds get_file_contents_excerpt to shared/github-mcp-pagination-wrappers.md.
    • Supports byteOffset, maxBytes, startLine, and endLine.
    • Uses gh api with a byte Range header, then optionally filters lines before returning JSON.
  • Workflow adoption

    • Updates the GitHub MCP structural analysis workflow to sample repository file content through the bounded wrapper instead of full get_file_contents.
    • Recompiles affected lock files.
  • Coverage

    • Adds focused tests that verify the shared wrapper schema and exercise bounded output with a mocked gh api response.

Example:

get_file_contents_excerpt:
  owner: github
  repo: gh-aw
  path: README.md
  ref: main
  maxBytes: 4000
  startLine: 1
  endLine: 80

Run: https://github.com/github/gh-aw/actions/runs/31052246569> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 5.39 AIC · ⌖ 7.13 AIC · ⊞ 8.3K ·

Comment /souschef to run again

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add excerpt and range-read mode to MCP get_file_contents Add bounded GitHub file excerpt MCP wrapper Aug 5, 2026
Copilot AI requested a review from pelikhan August 5, 2026 20:05
@pelikhan
pelikhan marked this pull request as ready for review August 5, 2026 21:45
Copilot AI balanced review requested due to automatic review settings August 5, 2026 21:45

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.

🟡 Changes recommended

Cross-repository defaults, special-character paths, and end-only line ranges currently produce incorrect behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

Adds a bounded GitHub file-content wrapper to reduce unnecessary MCP response tokens.

Changes:

  • Adds byte- and line-bounded file excerpts.
  • Adopts the wrapper in structural analysis.
  • Adds focused wrapper tests and recompiles workflows.
File summaries
File Description
.github/workflows/shared/github-mcp-pagination-wrappers.md Defines and documents the wrapper.
.github/workflows/github-mcp-structural-analysis.md Uses bounded excerpts.
.github/workflows/github-mcp-structural-analysis.lock.yml Recompiled workflow.
.github/workflows/deep-report.lock.yml Recompiled imported wrapper.
pkg/workflow/mcp_scripts_shared_wrappers_test.go Tests schema and bounded output.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 3
  • Review effort level: Balanced

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

OWNER="${INPUT_OWNER:-}"
REPO="${INPUT_REPO:-}"
PATH_IN_REPO="${INPUT_PATH:-}"
REF="${INPUT_REF:-${GITHUB_SHA:-}}"
Comment on lines +221 to +228
BYTE_END=$((BYTE_OFFSET + MAX_BYTES))
export OWNER REPO PATH_IN_REPO REF BYTE_OFFSET MAX_BYTES START_LINE END_LINE
gh api \
--method GET \
-H "Accept: application/vnd.github.raw" \
-H "Range: bytes=${BYTE_OFFSET}-${BYTE_END}" \
"repos/${OWNER}/${REPO}/contents/${PATH_IN_REPO}" \
-f "ref=${REF}" > "$RAW_FILE"
Comment on lines +248 to +252
if start_line:
line_start = int(start_line)
line_end = int(end_line) if end_line else line_start + 99
lines = text.splitlines(keepends=True)
text = "".join(lines[line_start - 1:line_end])
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please review the latest PR feedback, refresh this branch if it is behind main, then run the pr-finisher skill and push any follow-up fixes.

Run: https://github.com/github/gh-aw/actions/runs/31052246569

Generated by PR Sous Chef.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 5.39 AIC · ⌖ 7.13 AIC · ⊞ 8.3K ·
Comment /souschef to run again

…line filtering; sort actions-lock containers

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please review the latest PR feedback, refresh this branch if it is behind main, then run the pr-finisher skill and push any follow-up fixes.

  • failed checks:...

Addressed all three review issues and fixed the CI failures:

  1. Cross-repo ref defaultGITHUB_SHA is now only used when ${OWNER}/${REPO} matches ${GITHUB_REPOSITORY}; otherwise the wrapper falls through to the existing gh repo view default-branch lookup.

  2. URL encodingPATH_IN_REPO is now percent-encoded via Python's urllib.parse.quote (preserving / separators) before being inserted into the gh api URL.

  3. endLine without startLine — the Python filtering block now triggers when either start_line or end_line is set, defaulting start_line to 1 when omitted, so endLine-only inputs correctly return lines 1–N.

  4. CI fix — sorted the containers field in .github/aw/actions-lock.json to fix TestActionsLockJSONFieldsAreSorted (the new container added in the initial commit landed at the end instead of in lexicographic order).

Copilot AI requested a review from gh-aw-bot August 5, 2026 22:32
@pelikhan pelikhan closed this Aug 5, 2026
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.

[deep-report] MCP get_file_contents has no excerpt/range-read mode — full-file reads waste ~4,500 tokens on large files

4 participants