Title: Bug: create_or_update_file SHA validation uses ETag instead of blob SHA, causing spurious failures · Issue #2133 · github/github-mcp-server · GitHub
Open Graph Title: Bug: create_or_update_file SHA validation uses ETag instead of blob SHA, causing spurious failures · Issue #2133 · github/github-mcp-server
X Title: Bug: create_or_update_file SHA validation uses ETag instead of blob SHA, causing spurious failures · Issue #2133 · github/github-mcp-server
Description: Summary create_or_update_file has multiple bugs in its SHA validation logic that cause it to fail on legitimate update operations. The tool should be split into separate create_file and update_file tools, or the validation logic needs si...
Open Graph Description: Summary create_or_update_file has multiple bugs in its SHA validation logic that cause it to fail on legitimate update operations. The tool should be split into separate create_file and update_file...
X Description: Summary create_or_update_file has multiple bugs in its SHA validation logic that cause it to fail on legitimate update operations. The tool should be split into separate create_file and update_file...
Opengraph URL: https://github.com/github/github-mcp-server/issues/2133
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bug: create_or_update_file SHA validation uses ETag instead of blob SHA, causing spurious failures","articleBody":"## Summary\n\n`create_or_update_file` has multiple bugs in its SHA validation logic that cause it to fail on legitimate update operations. The tool should be split into separate `create_file` and `update_file` tools, or the validation logic needs significant fixes.\n\n## Bug Details\n\n### 1. ETag vs Blob SHA Mismatch (Critical)\n\nThe SHA validation performs a HEAD request and compares the user-provided blob SHA against the response's ETag header:\n\n```go\nreq.Header.Set(\"If-None-Match\", fmt.Sprintf(`\"%s\"`, sha))\n// ...\ncase http.StatusOK:\n currentSHA := strings.Trim(resp.Header.Get(\"ETag\"), `\"`)\n return utils.NewToolResultError(fmt.Sprintf(\n \"SHA mismatch: provided SHA %s is stale...\", sha, currentSHA))\n```\n\n**The problem:** GitHub's Contents API returns a weak ETag (`W/\"...\"`) that is NOT the blob SHA. It's an opaque server-generated value. Comparing a blob SHA against an ETag is comparing two different things, causing the validation to reject perfectly valid updates where the SHA is actually current.\n\n### 2. `url.PathEscape` Breaks Multi-Segment Paths\n\n```go\ncontentURL := fmt.Sprintf(\"repos/%s/%s/contents/%s\", owner, repo, url.PathEscape(path))\n```\n\nFor paths like `sassymcp/modules/vision.py`, `PathEscape` encodes `/` as `%2F`, producing `sassymcp%2Fmodules%2Fvision.py`. The Contents API expects literal path separators. This causes the HEAD validation request to 404, which then falls through to the \"new file\" code path. The subsequent `CreateFile` call then fails with 409 Conflict because the file already exists but no SHA was provided.\n\nShould use `url.PathEscape` per-segment or just pass the raw path (the go-github client handles encoding).\n\n### 3. Blind Update ETag-as-SHA Injection\n\nWhen no SHA is provided and the file exists, the code extracts the ETag and uses it as the SHA for the update:\n\n```go\npreviousSHA = strings.Trim(resp.Header.Get(\"ETag\"), `\"`)\n// ...\nif previousSHA != \"\" {\n opts.SHA = github.Ptr(previousSHA)\n}\n```\n\nSince the ETag is not a blob SHA, this causes `client.Repositories.CreateFile` to fail with a 409 because GitHub's API rejects the invalid SHA value.\n\n### 4. Multiple Deferred Body Closes\n\nThe validation HEAD requests and the final CreateFile call all stack `defer resp.Body.Close()`. If response bodies aren't fully drained before the next request on the same HTTP/2 connection, this can cause connection reuse issues.\n\n## Recommended Fix\n\n**Option A: Split into two tools**\n- `create_file` — creates new files only, no SHA parameter needed\n- `update_file` — updates existing files, requires SHA parameter, validates using `get_file_contents` blob SHA (not ETag)\n\n**Option B: Fix the validation**\n1. Replace the HEAD+ETag approach with a GET to `/repos/{owner}/{repo}/contents/{path}?ref={branch}` and compare against the response's `.sha` field (the actual blob SHA)\n2. Fix `url.PathEscape` to not encode path separators\n3. Don't inject ETag values as SHA parameters\n\n## Workaround\n\nUse `push_files` instead of `create_or_update_file` for all update operations. `push_files` uses the Git Data API (create tree → create commit → update ref) which completely bypasses the Contents API and its SHA validation issues. It works reliably for both creates and updates, single or multi-file.\n\n## Environment\n\n- GitHub MCP Server (hosted by Anthropic as Claude.ai connector)\n- Reproduces on: `sassyconsultingllc/SassyMCP` repo, updating existing files on `main` branch\n- Failure rate: ~30-40% of update attempts via `create_or_update_file`","author":{"url":"https://github.com/sassyconsultingllc","@type":"Person","name":"sassyconsultingllc"},"datePublished":"2026-03-04T10:01:26Z","url":"https://github.com/github/github-mcp-server/issues/2133"}
| 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:086862ab-b6b1-c065-4acc-d6f7cff53ea4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9C00:1619FB:198D56B:22A860A:6B068F40 |
| html-safe-nonce | 8fd9cb49470834a85e214943a3f4d4db79cd60cb9663197705155db4f4bfb88a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QzAwOjE2MTlGQjoxOThENTZCOjIyQTg2MEE6NkIwNjhGNDAiLCJ2aXNpdG9yX2lkIjoiODEzNjYyNDMxOTIzODY3MjE5MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 81842a790e5e92ecce761649caa22596d98264e8e822075cd1efefdd9fa80801 |
| hovercard-subject-tag | issue:4021134925 |
| 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/2133/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e11eb065ea1e77957db7d395892e02f5d790b49bac51c9c898404c0fd8df3412/github/github-mcp-server/issues/2133 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e11eb065ea1e77957db7d395892e02f5d790b49bac51c9c898404c0fd8df3412/github/github-mcp-server/issues/2133 |
| og:image:alt | Summary create_or_update_file has multiple bugs in its SHA validation logic that cause it to fail on legitimate update operations. The tool should be split into separate create_file and update_file... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sassyconsultingllc |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4462ff7ebfd3d551f202659f2423dae617b6849d23b1df6465dc504ef497d14a |
| 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 | 6d3909414814ff86ce7da4c51a0f4918a13fb41b |
| 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