internal/mcp: implement 2026-07-28 error code allocation policy (sa-70) - #2513
Merged
Merged
Conversation
The MCP 2026-07-28 revision partitions the JSON-RPC server-error range: -32000..-32019 stays implementation-defined (grandfathered), while -32020..-32099 is reserved for the MCP specification. The draft codes were renumbered (HeaderMismatch -32001 -> -32020, MissingRequiredClientCapability -32003 -> -32021, UnsupportedProtocolVersion -32004 -> -32022) and resource not found changed from -32002 to -32602 (Invalid Params). ggcode's MCP client previously had no awareness of the reserved range or the renumbering: a server answering -32020/-32021/-32022 surfaced as an opaque "JSON-RPC error -32020: ..." with no spec context, the initialize path did not recognize UnsupportedProtocolVersionError, and resources/read failures did not normalize the legacy/new not-found reporting. - new internal/mcp/errorcodes.go: reserved-range constants (plus grandfathered legacy aliases), classification helpers (isMCPReservedErrorCode / isUnsupportedProtocolVersionCode / isResourceNotFoundCode), decorateSpecError wrapping known spec codes with name+hint while keeping *Error reachable via errors.As, and annotateResourceReadError normalizing -32002 / -32602 not-found reporting for the agent. - client.go: sendRequest decorates spec-defined errors; Initialize renders an actionable UnsupportedProtocolVersion diagnostic listing supported versions (both -32022 and legacy -32004); ReadResource annotates not-found failures. Tests: unit coverage of the range/classification helpers plus end-to-end httptest pins for the decorated HeaderMismatch, the version-rejection diagnostic, and resource-not-found normalization. Full internal/mcp suite passes (goolm); darwin/arm64, linux/amd64, linux/arm64 build. Co-Authored-By: ggcode <noreply@ggcode.dev>
topcheer
commented
Sep 17, 2026
topcheer
left a comment
Owner
Author
There was a problem hiding this comment.
复审通过 ✅(三重点核销)
① 区段边界:保留域 -32020..-32099(isMCPReservedErrorCode 严格界检查)+grandfathered 区 -32000..-32019(实现定义)+重编号映射(HeaderMismatch -32001→-32020/MissingRequiredClientCapability -32003→-32021/UnsupportedProtocolVersion -32004→-32022)——与 #2498(-32001 旧值识别)和 #2510(-32022 typed)的既有常量双号并认(legacy+新号同语义)零冲突。
② 透传 vs 拦截边界——hint-only 正确:未知码(保留域内未定义/实现域全部)原样透传+附 specErrorCodeHint 上下文注释——客户端不吞不改码(server 语义权威),只加可操作性解释;isResourceNotFoundCode 的 -32602 歧义显式声明(method 上下文消歧)。
③ 与 #2490 cancelled 码域:cancelled 是 notification 非 error 码(JSON-RPC notification 无 error 面)——无码域交集;#2498 的 HeaderMismatch 处理链升级为双号识别(旧 -32001 刷新重试语义保留)。
常量集中化后消除散落魔数。CI 9/9 绿。可合并。
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.
sa-70 / MCP 2026-07-28: error code allocation policy
Implements the 2026-07-28 revision's error-code allocation policy in
internal/mcp(changelog).Spec background
Gap closed
ggcode's MCP client previously had zero awareness of the reserved range or renumbering: servers answering -32020/-32021/-32022 surfaced as opaque
JSON-RPC error -32020: ...with no spec context, the initialize path didn't recognizeUnsupportedProtocolVersionError, and resources/read failures didn't normalize legacy/new not-found reporting.Changes
internal/mcp/errorcodes.go: reserved-range constants + grandfathered legacy aliases; classification helpers (isMCPReservedErrorCode,isUnsupportedProtocolVersionCode,isResourceNotFoundCode);decorateSpecErrorwraps known spec codes with name + actionable hint while keeping the original*Errorreachable viaerrors.As(idempotent, so breaker semantics are untouched);annotateResourceReadErrornormalizes -32002 / -32602 not-found reporting for the agent.client.go:sendRequestdecorates spec-defined errors;Initializerenders an actionable version-rejection diagnostic listing supported versions (recognizes both -32022 and legacy -32004);ReadResourceannotates not-found failures.Verification
internal/mcpsuite passes (-tags goolm); builds on darwin/arm64, linux/amd64, linux/arm64.Co-Authored-By: ggcode noreply@ggcode.dev