proposal: auth: support SEP-2350 request-time scope challenges
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- go
- Lĩnh vực
- authentication, backend-api-design
Hướng nghiên cứu
Bắt đầu bằng việc đọc auth.go, đặc biệt là RequireBearerToken và RequireBearerTokenOptions, sau đó xem lại các yêu cầu của SEP-2350 và RFC 6750 được mô tả ở đây. Kiểm tra conformance#481 và conformance/baseline.yml để hiểu các kịch bản dự kiến ở phía máy chủ; công việc được hoàn tất khi có thiết kế scope tại thời điểm request đã được thống nhất và có coverage của conformance mà không có một loại trừ baseline không chính đáng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Is your feature request related to a problem? Please describe.
auth.RequireBearerToken can't produce a SEP-2350 conformant insufficient-scope challenge, for two separate reasons.
- Smaller/Possible Bug: On the 403 path the middleware builds a
WWW-Authenticateheader fromresource_metadataandscope, but never addserror="insufficient_scope". RFC 6750 §3.1 requires theerrorparam, and a client that switches on it sees an unlabelled challenge and can't tell a scope problem from anything else. - Larger/Structural:
RequireBearerTokenOptions.Scopesis fixed when the middleware is constructed, so a server has exactly one required scope set for every request. SEP-2350 is about advertising the scope a particular operation needs, so a low-privilege client can step up for the one tool that requires more. With a construction-time set there's no way to express "readfor most tools,admin-writefor this one", and thescope=the challenge advertises is the server-wide set rather than what the operation actually needed.
SEP-2350 is merged and labelled final (modelcontextprotocol/modelcontextprotocol#2350), so this might no longer be a tracking a draft?
Describe the solution you'd like
Two changes, separable, and would be happy to land only the first if the second needs more discussion.
-
Add
error="insufficient_scope"to the challenge on the 403 branch. Non-breaking in any way that matters, and imo it is a bug fix rather than a proposal. -
Let the required scopes vary per request. The smallest thing that could work is a callback on the options struct, leaving
Scopesas the static fallback:
type RequireBearerTokenOptions struct {
// ...
// ScopesForRequest returns the scopes required for this particular
// request. When nil, Scopes applies to every request.
ScopesForRequest func(*http.Request) []string
}
The middleware would use its result both for the containment check and for the scope= it advertises, so the challenge names what the operation needed rather than what the server requires in general.
One thing we want to deep dive a bit more is that RequireBearerToken is a generic net/http middleware and runs before the JSON-RPC body is dispatched, so a ScopesForRequest callback cannot see which tool is being called without the implementer parsing the body themselves. While this may be (coz it keeps the auth package free of MCP concepts and puts the choice in the caller's hands) if the preference is for the scope requirement to live next to the tool it guards then this is a different and larger design touching the mcp package. Would prefer to hear yall's thoughts on which which direction to take.
Describe alternatives you've considered
- A typed error from the handler. Let a tool handler return something like
auth.ErrInsufficientScope{Scopes: []string{"admin-write"}}that the HTTP layer maps to a 403 plus challenge. This puts the requirement next to the tool, which reads better, but it means the check happens after dispatch rather than in middleware, and it couplesmcptoauth. - Leave it to implementers. Callers can write their own middleware today. It works, but every implementer re-derives the RFC 6750 challenge format, and the SDK already owns that formatting for the 401 case, so the knowledge is half here already.
- Do nothing until the TypeScript SDK settles. Genuinely possible, see below.
Additional context
The main question I have before writing any code is whether we want to wait for the TypeScript SDK?modelcontextprotocol/typescript-sdk#1624 is the reference implementation for this, open since March, currently with changes requested. auth.go notes that RequireBearerToken is based on that SDK's bearerAuth.ts, so if you'd rather track their final API shape than diverge, that's a fair call. Id love to know now than send a PR prematurely.
Also from a conformance angle modelcontextprotocol/conformance#481 adds a server-side scope-challenge scenario covering tools/call, static and templated resources/read, and prompts/get. When it merges, the Go SDK will either fail it or need a new exclusion line in conformance/baseline.yml alongside the DPoP and WIF ones. IMO doing this now keeps it ready then.
Some prior-art - I've implemented the equivalent in another Go MCP library (panyam/mcpkit#1353, request-time challenges across all primitives) and it passes that scenario 17/17 with no warnings. So I have a design that's been through the conformance suite and I'm happy to write the PR here. Just want to make sure the extension point/design first with yall.
- Ngôn ngữ chính
- Go
- Star
- 5.4k
- Fork
- 623
- Merge trung bình
- 22 giờ 10 phút
- Pull request đã merge (30 ngày)
- 30
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/go-sdk
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
modelcontextprotocol/go-sdk#1557 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Streamable HTTP (2026-07-28): tools/call with an out-of-range number in arguments fails because extractName decodes Arguments into anyCó thể làm lại được @beiryu đã nhận 10 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
modelcontextprotocol/go-sdk#1534 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensionsCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởneeds investigation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
modelcontextprotocol/go-sdk#745 · 13 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 18/100
modelcontextprotocol/go-sdk#1555 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: 2026-07-28 client runs elicitation and sampling handlers for standalone server requestsCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
modelcontextprotocol/go-sdk#1552 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của modelcontextprotocol/go-sdk
Issue tương tự
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
compiler-explorer/compiler-explorer#9738 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
evilmartians/lefthook#1674 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày