Repository navigation
Conversation
…ces as blobs RepositoryResourceContentsHandler returned every application/* response as text. raw.githubusercontent.com serves binary files such as PDFs and archives as application/octet-stream, so reading them through a repo:// resource put the raw bytes into the text field, where invalid UTF-8 is replaced during JSON encoding and the content cannot be recovered. Return text only for text/* and for text-based application types (application/json, application/xml, application/javascript, and application/*+json or application/*+xml), matching how get_file_contents classifies content, and return everything else as a blob. Other top-level types keep their previous handling (for example image/svg+xml stays a blob), and a Content-Type with a malformed parameter is still classified by its media type. Assisted-by: Claude:claude-opus-5-5
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
repo://repository content resources returned everyapplication/*response as text, so binary files served asapplication/octet-stream(PDFs, archives, etc.) came back as corrupted text. This PR returns only text-based types as text and everything else as a blob.Why
No existing issue. In
RepositoryResourceContentsHandlerthe response type switch iscase strings.HasPrefix(mimeType, "text"), strings.HasPrefix(mimeType, "application"):. raw.githubusercontent.com serves binary files withContent-Type: application/octet-stream(checked withcurl -sIon a PDF in mozilla/pdf.js and a.tar.xzin python/cpython), while text files come back astext/plain; charset=utf-8. Sorepo://owner/repo/contents/file.pdfreturned the bytes inText. Invalid UTF-8 is replaced with U+FFFD when the result is JSON-encoded, so the original file cannot be recovered.get_file_contentsalready classifies content with an allow-list of text types.What changed
pkg/github/repository_resource.go: addisTextMIMEType.text/*stays text. Underapplication/, onlyapplication/json,application/xml,application/javascript,application/*+jsonandapplication/*+xmlare text (the same setget_file_contentsuses, plusapplication/javascript); otherapplication/*types such asapplication/octet-stream,application/pdfandapplication/zipare returned asBlob. Other top-level types keep their previous handling (e.g.image/svg+xmlstays a blob). AContent-Typewith a malformed parameter (e.g.text/plain; charset) is still classified by its media type, as before.pkg/github/repository_resource_test.go: addTest_repositoryResourceContentsHandler_ApplicationTypeswith eight cases: octet-stream, pdf and zip come back as blobs;application/json; charset=utf-8,application/xml,application/vnd.api+jsonandtext/plain; charsetcome back as text;image/svg+xmlstays a blob. Onmainthe three binary cases fail (Should be empty, but was %PDF-1.4...) and the other five pass; with this change all eight pass.MCP impact
No tool changes; the
repo://resource read behavior changed: binaryapplication/*files are returned inblobinstead oftext.Prompts tested (tool changes only)
Security / limits
Tool renaming
deprecated_tool_aliases.goNote: if you're renaming tools, you must add the tool aliases. For more information on how to do so, please refer to the official docs.
Lint & tests
./script/lint./script/testLint: ran the same checks as
script/lintdirectly rather than the script itself:gofmt -lis clean andgolangci-lint run ./...with v2.14.0 (the version pinned inscript/lint) reports 0 issues. Tests:go test ./pkg/github/andgo vet ./pkg/github/pass with Go 1.27.3; the full./script/test(go test -race ./...) was not run.Docs
AI assistance: this change was prepared with Claude (claude-opus-5-5), which found the bug, wrote the fix and tests, ran the checks, and drafted this description.