Title: get_file_contents double-base64-encodes binary files, corrupting all images · Issue #3097 · github/github-mcp-server · GitHub
Open Graph Title: get_file_contents double-base64-encodes binary files, corrupting all images · Issue #3097 · github/github-mcp-server
X Title: get_file_contents double-base64-encodes binary files, corrupting all images · Issue #3097 · github/github-mcp-server
Description: Describe the bug get_file_contents double-base64-encodes every binary file it returns. The blob field on the wire contains base64(base64(bytes)) instead of base64(bytes). The practical effect is that no image fetched via get_file_content...
Open Graph Description: Describe the bug get_file_contents double-base64-encodes every binary file it returns. The blob field on the wire contains base64(base64(bytes)) instead of base64(bytes). The practical effect is th...
X Description: Describe the bug get_file_contents double-base64-encodes every binary file it returns. The blob field on the wire contains base64(base64(bytes)) instead of base64(bytes). The practical effect is th...
Opengraph URL: https://github.com/github/github-mcp-server/issues/3097
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"get_file_contents double-base64-encodes binary files, corrupting all images","articleBody":"### Describe the bug\n\n`get_file_contents` double-base64-encodes every binary file it returns. The `blob` field on the wire contains `base64(base64(bytes))` instead of `base64(bytes)`.\n\nThe practical effect is that **no image fetched via `get_file_contents` is usable**. Clients that forward the blob to a model API get a hard rejection, because after the single (correct) decode the payload is still ASCII base64 text rather than image bytes. Against the Copilot API this surfaces as:\n\n```\nCAPIError: 400 The image data you provided does not represent a valid image.\nPlease check your input and try again with one of the supported image formats\n['image/jpeg', 'image/png', 'image/gif', 'image/webp'].\n```\n\nIn agentic clients this is worse than a one-off failure: the corrupt payload persists in conversation history, so every subsequent turn re-sends it and fails identically. The session becomes unusable and the only escape is discarding the turn. We have multiple internal users hitting this, one describing it as \"you've poisoned the entire session and you can no longer move forward.\"\n\n### Affected version\n\nReproduced against the hosted server at `https://api.githubcopilot.com/mcp/` on 2026-08-18. The defect is present in current `main` (`pkg/github/repositories.go`).\n\n### Steps to reproduce the behavior\n\nCall `get_file_contents` on any binary file — this example uses a public 330-byte PNG:\n\n```bash\ncurl -s -X POST https://api.githubcopilot.com/mcp/ \\\n -H \"Authorization: Bearer $GITHUB_TOKEN\" \\\n -H \"Content-Type: application/json\" \\\n -H \"Accept: application/json, text/event-stream\" \\\n -d '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/call\",\"params\":{\"name\":\"get_file_contents\",\n \"arguments\":{\"owner\":\"anomalyco\",\"repo\":\"opencode\",\n \"path\":\"packages/identity/mark-512x512.png\"}}}'\n```\n\nReturned blob (truncated):\n\n```\naVZCT1J3MEtHZ29BQUFBTlNVaEVVZ0FBQWdBQUFBSUFBZ01BQUFDSkZqeHBB…\n```\n\nDecoding it:\n\n```\ndecode once → b'iVBORw0KGgoAAAAN' ← ASCII text, not image bytes\ndecode twice → b'\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR' ← the actual PNG\n```\n\nThe file is 330 bytes, but the blob is 588 characters — consistent with base64 being applied twice.\n\n### Expected vs actual behavior\n\n**Expected:** a single base64 decode of `blob` yields the raw file bytes.\n\n**Actual:** two decodes are required. Any spec-compliant client decoding once receives ASCII base64 text labeled `image/png`.\n\n### Root cause\n\n`pkg/github/repositories.go` (~line 1105):\n\n```go\n// Binary content - encode as base64 blob\nblobContent := base64.StdEncoding.EncodeToString(contentBytes)\nresult := &mcp.ResourceContents{\n URI: resourceURI,\n Blob: []byte(blobContent), // ← already base64, then encoded again\n MIMEType: contentType,\n}\n```\n\n`mcp.ResourceContents.Blob` is typed `[]byte`:\n\n```go\n// modelcontextprotocol/go-sdk v1.7.0 — mcp/content.go:302\ntype ResourceContents struct {\n\tURI string `json:\"uri\"`\n\tMIMEType string `json:\"mimeType,omitempty\"`\n\tText string `json:\"text,omitempty\"`\n\tBlob []byte `json:\"blob,omitzero\"`\n\tMeta Meta `json:\"_meta,omitempty\"`\n}\n```\n\nGo's `encoding/json` marshals a `[]byte` field as base64 automatically, and there is no custom `MarshalJSON` on `ResourceContents`. So the manual `EncodeToString` is applied first, and the marshaler encodes that ASCII string a second time.\n\nThis looks like a migration artifact: under `mark3labs/mcp-go`, `Blob` was a `string`, so manually encoding was correct. `Blob` has been `[]byte` since `modelcontextprotocol/go-sdk` v1.0.0, which turned the same line into double encoding.\n\n### Suggested fix\n\nHand the marshaler the raw bytes and let it do the single encode:\n\n```go\nresult := &mcp.ResourceContents{\n URI: resourceURI,\n Blob: contentBytes,\n MIMEType: contentType,\n}\n```\n\nWorth adding a regression test that round-trips a known PNG through the tool and asserts that a **single** decode of `blob` starts with the PNG magic bytes `89 50 4E 47`. A test asserting only \"blob is non-empty\" or comparing against a re-encoded string will pass while double-encoded.\n\n### Note on a red herring\n\nWe originally chased this through a file that happens to be a git symlink (`sdks/vscode/images/icon.png` → `../../../packages/identity/mark-512x512.png`). The symlink is **not** the cause. The Contents API resolves symlinks transparently, and `http.DetectContentType` correctly identifies the resolved PNG. Both the symlink path and the real file return byte-identical double-encoded blobs. Any binary file reproduces this.\n","author":{"url":"https://github.com/jukasper","@type":"Person","name":"jukasper"},"datePublished":"2026-08-19T01:37:10Z","url":"https://github.com/github/github-mcp-server/issues/3097"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a5e0c65f-8965-3c77-fe96-9b662126f680 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 89BE:1CA0E6:9C7E1C:D1E554:6B063CD9 |
| html-safe-nonce | 2a006bf5fd8b89c020a0b668bda10b7e6efb1f4d80c114defe1b9f3be037c564 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OUJFOjFDQTBFNjo5QzdFMUM6RDFFNTU0OjZCMDYzQ0Q5IiwidmlzaXRvcl9pZCI6IjM5OTYwNTkzMDIyMzM1MjEzNjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9ff61ce46bc0ce0ce9800ae47719dc88d0da50673261070642d66df46bf46fbf |
| hovercard-subject-tag | issue:5188002895 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/github/github-mcp-server/3097/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ff19c1785c37697cf707b956e2a37783b114976a67705e8177264b598dc60369/github/github-mcp-server/issues/3097 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ff19c1785c37697cf707b956e2a37783b114976a67705e8177264b598dc60369/github/github-mcp-server/issues/3097 |
| og:image:alt | Describe the bug get_file_contents double-base64-encodes every binary file it returns. The blob field on the wire contains base64(base64(bytes)) instead of base64(bytes). The practical effect is th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jukasper |
| hostname | github.com |
| expected-hostname | github.com |
| None | dcf72c457c022486d23c3cbb0dd21aba537a87611ca9ddabd1799cf2eaa9b297 |
| turbo-cache-control | no-preview |
| go-import | github.com/github/github-mcp-server git https://github.com/github/github-mcp-server.git |
| octolytics-dimension-user_id | 9919 |
| octolytics-dimension-user_login | github |
| octolytics-dimension-repository_id | 942771284 |
| octolytics-dimension-repository_nwo | github/github-mcp-server |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 942771284 |
| octolytics-dimension-repository_network_root_nwo | github/github-mcp-server |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0f38f5735226749ec5e08a8649dce4cb2613d9ad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width