Skip to content

Fix/3748 omit directory download url - #3848

Open
RealThanhNguyxn wants to merge 9 commits into
github:mainfrom
RealThanhNguyxn:fix/3748-omit-directory-download-url
Open

RealThanhNguyxn wants to merge 9 commits into
github:mainfrom
RealThanhNguyxn:fix/3748-omit-directory-download-url

Conversation

@RealThanhNguyxn

@RealThanhNguyxn RealThanhNguyxn commented Nov 14, 2026 •

Copy link
Copy Markdown

Summary

Fixes #3748.

Omit credential-bearing download_url values from get_file_contents directory listings by default. Callers can still explicitly request this field through fields: ["download_url"].

Why

GitHub's Contents API can return short-lived tokenized raw-content URLs for files in private repositories.

Directory listings generally need metadata such as names, paths, sizes, and SHAs—not bearer URLs that independently grant access to private files and may be exposed in model context, transcripts, or client logs.

The large-file single-file fallback remains unchanged and continues to provide its download URL.

What changed

  • pkg/github/repositories.go: Shallow-copy directory entries and clear DownloadURL before marshaling the default response. Explicit fields projections continue to use the original entries, preserving opt-in behavior without mutating the API response.
  • pkg/github/repositories_test.go: Add regression coverage for default omission, token absence, retained metadata, and clone immutability, including nil entries.
  • pkg/github/typed_compatibility_test.go: Cover default omission and explicit opt-in across legacy (2025-11-25) and modern (2026-07-28) protocol responses, including modern structured output.
  • pkg/github/__toolsnaps__/get_file_contents.snap: Update the input description to document the default behavior.

MCP impact

  • No tool or API changes
  • Tool schema or behavior changed — directory listings omit download_url by default; callers can explicitly request it through fields. The output schema remains unchanged.
  • New tool added

Prompts tested (tool changes only)

  • Default directory listing.
  • Explicit fields: ["download_url"].
  • Legacy and modern protocol compatibility covered by automated tests.

Manual prompt testing has not been performed.

Security / limits

  • No security or limits impact
  • Auth / permissions considered
  • Data exposure, filtering, or token/size limits considered — removes short-lived bearer URLs from default private-repository directory listings.

Tool renaming

  • I am not renaming tools as part of this PR.

Lint & tests

  • Linted locally with ./script/lint
  • Tested locally with ./script/test

Both scripts ran locally on this branch: ./script/lint reports 0 issues and ./script/test (go test -race ./...) passes across all packages.

Docs

  • Not needed
  • Updated — tool input description and generated snapshot document the default omission.

@RealThanhNguyxn
RealThanhNguyxn requested a review from a team as a code owner November 14, 2026 04:34
Copilot AI dynamic review requested due to automatic review settings November 14, 2026 04: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.

🟡 Changes recommended

The README still contradicts the new default behavior, leaving the documentation check failing, and filtered directory telemetry overstates field-selection byte savings.

2 open issues
What changed in this PR

Addresses #3748 by omitting credential-bearing download URLs from default get_file_contents directory listings, reducing exposure in model context and client logs.

Changes:

  • Omits download_url from copied directory entries while preserving explicit fields opt-in and the large-file fallback.
  • Adds regression coverage for omission, metadata preservation, immutability, and protocol compatibility.
  • Updates the tool input description and schema snapshot.
File Description
pkg/​github/​typed_compatibility_test.go Tests default omission and explicit opt-in across legacy and modern protocols.
pkg/​github/​repositories.go Removes download URLs from default directory responses without mutating API entries.
pkg/​github/​repositories_test.go Tests token absence, retained metadata, and clone behavior, including nil entries.
pkg/​github/​__toolsnaps__/​get_file_contents.snap Records the updated field-selection description.

Review effort: Max (dynamic)

Comment on lines +1203 to +1204
} else {
payload = cloneDirectoryEntriesWithoutDownloadURLs(dirContent)
}
schema.Properties["fields"] = fieldsSchemaProperty(
"Subset of fields to return for each entry when the path is a directory. If omitted, all fields are returned. Ignored when the path is a single file. Use this to reduce response size when listing directories and you only need specific fields, e.g. just 'name' and 'type'.",
"Subset of fields to return for each entry when the path is a directory. 'download_url' is omitted by default; request it explicitly in 'fields' when needed. Ignored when the path is a single file. Use this to reduce response size when listing directories and you only need specific fields, e.g. just 'name' and 'type'.",
./script/lint reported two G101 findings on the synthetic tokenized
download URLs added for the default-omission coverage. Annotate both
fixtures with the repository's nolint convention.

- ./script/lint: 0 issues
- ./script/test (go test -race ./...): all packages pass
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.

get_file_contents directory listings put tokenised private-repo download URLs in model context

2 participants