Return HTTP 401 for credential/authorization failures instead of `isError: true`, so OAuth clients can refresh
維護者通常 2 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 48/100
- Issue 類型
- 功能
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- go
研究方向
Start by tracing how GitHub API errors reach the MCP tool response and where HTTP status codes and response headers are set. Check the existing error-handling tests, especially cases for 401 and ordinary tool failures. Done means API 401 responses produce HTTP 401, while other tool failures remain HTTP 200 with isError: true; the issue also asks maintainers to decide whether to preserve error content and include WWW-Authenticate.
由索引模型根據 Issue 內容生成。
描述
Summary
When the GitHub API rejects a request with 401 Unauthorized (expired or invalid credential), the server currently returns it as a tool execution error: HTTP 200, isError: true, with the failure in the text content (e.g. failed to get user: GET .../user: 401 Bad credentials []).
For ordinary tool failures (validation errors, business-logic errors, 404s, 409s) this is correct and should stay — an LLM needs to see them and self-correct.
But an authorization failure is categorically different: it is not something the model can fix by adjusting arguments. It means the credential is no longer valid and the client must re-authenticate or refresh its token. We propose the server return HTTP 401 for credential/authorization failures, while keeping isError: true for all other tool errors.
Why auth failures belong at the transport layer
The MCP spec has two distinct error-handling sections, for two distinct layers:
-
Tool error handling — for failures the model can act on. These are
isError: truein a 200. Correct for validation, business logic, "not found", etc. -
Authorization error handling — for credential validity. This section is unambiguous:
Invalid or expired tokens MUST receive a HTTP 401 response.
An expired token is precisely "invalid or expired token." The spec says that MUST be a 401. The only reason it currently isn't is an implementation detail: the credential happens to be validated downstream (at the GitHub API) rather than at the MCP server's own boundary. But from the client's perspective the meaning is identical — the token it presented is no longer good — and the spec's prescribed signal for that is HTTP 401, not a tool-result flag.
Routing auth failures through the tool-result path effectively hides a transport-layer condition inside an application-layer channel. The client's token-refresh logic lives at the transport layer (as the spec directs), so it never sees the signal.
Relationship to #420
We're aware of #420, which moved failed API calls from Go errors to isError: true. That change was correct for the general case and we're not asking to revert it. We're asking to carve out one specific sub-case — HTTP 401 from the GitHub API — and map it to the corresponding HTTP status, because the authorization spec explicitly governs that sub-case and overrides the general tool-error guidance for it.
Concretely:
| GitHub API result | Proposed MCP response |
|---|---|
| 401 (token invalid/expired) | HTTP 401 (with WWW-Authenticate if available) |
| 404, 409, 422, validation, business logic | HTTP 200, isError: true (unchanged) |
| rate limited | HTTP 200, isError: true (unchanged — model/client may legitimately retry) |
Why this matters — our deployment
We host the GitHub MCP server for GitHub Enterprise Server. GHES lacks the OAuth extensions MCP needs, so we front it with a Proxy that presents a compliant Authorization Server.
- Tokens are GitHub App user-to-server tokens issued by GHES — short-lived, with refresh tokens. Mid-session expiry is the normal case.
- The Proxy is an Authorization Server only — not in the request path — so it cannot observe tool calls or emit the 401. The MCP server is the only component positioned to surface the auth failure to the client.
When the token expires, the only symptom today is a tool call returning 401 Bad credentials inside an isError: true result. Clients that follow the spec and watch for transport-level 401 never refresh.
Affected clients
OAuth-authenticating MCP clients are affected, including Joule Work and OpenCode. They implement the spec-mandated behavior of refreshing their token on a transport-level HTTP 401, but because this failure mode never produces a transport-level 401 — it arrives as isError: true in an HTTP 200 — the refresh is never triggered. The expired token keeps being replayed and every GitHub call fails, while the connection appears healthy.
Returning HTTP 401 means these clients work with no client-side changes, because they already implement the spec-mandated 401→refresh path.
The ask
Map GitHub API 401 → MCP HTTP 401, ideally with a WWW-Authenticate header, while leaving all other tool failures as isError: true. This aligns with the authorization spec's MUST, fixes OAuth token refresh for any spec-compliant client without client-side changes, and preserves #420's behavior for the error classes it was actually about.
Questions for maintainers:
- Would you accept auth (401) being treated as a transport/authorization-layer condition rather than a tool-execution error, given the authorization spec's explicit MUST?
- If full HTTP-status mapping is undesirable, would a hybrid be acceptable — HTTP 401 plus retain
isError: truecontent for the LLM — so both layers get their signal?
- 主要語言
- Go
- 星號
- 34.2k
- 分支
- 5.3k
- 平均合併
- 5 天 18 小時
- 30 天內合併 PR
- 13
環境準備
- 提供 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
github/github-mcp-server 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 69/100
github/github-mcp-server#3760 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
github/github-mcp-server#3758 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 69/100
github/github-mcp-server#3729 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
github/github-mcp-server#3722 ·
維護者通常 2 天內回覆
-
Insiders Feedback: PR created UI doesn't link to the PR可能已有人在做 @genius-0963 於 5 天前認領。 未關閉bug insiders user-experience
難度 2/5 1-3 小時 新手友好度 65/100
github/github-mcp-server#3658 ·
維護者通常 2 天內回覆
查看 github/github-mcp-server 的全部 Issue
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 72/100
open-feature/flagd-schemas#237 ·
-
enhancement
難度 2/5 1-3 小時 新手友好度 72/100
superplanehq/superplane#9234 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
betterleaks/betterleaks#469 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
prime-radiant-inc/evener#5901 ·
維護者通常 1 天內回覆