[v2] requireBearerAuth: drop error="invalid_token" when no credentials were sent and resource_metadata is set (RFC 6750 §3.1)
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ó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- api, authentication
Hướng nghiên cứu
Trong packages/server, tìm requireBearerAuth và bearerAuthChallengeResponse dùng chung được adapter Express sử dụng; trước tiên, đọc cách chúng tạo challenge và các bài kiểm thử gần đó. Thêm hoặc cập nhật bài kiểm thử cho trường hợp thiếu thông tin xác thực có resource_metadata hoặc scope, thiếu thông tin xác thực không có tham số nào khác và token không hợp lệ. Công việc hoàn tất khi trường hợp đầu tiên bỏ qua invalid_token, trường hợp thứ hai giữ nguyên challenge hiện tại và phản hồi cho token không hợp lệ không thay đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What happened?
When a request has no Authorization header, requireBearerAuth answers:
WWW-Authenticate: Bearer error="invalid_token", error_description="Missing Authorization header", scope="a:read", resource_metadata="https://mcp.example/.well-known/oauth-protected-resource/mcp"
RFC 6750 §3.1 says that when a request has no authentication information, the server SHOULD NOT include an error code.
This was tried in #785 (v1) and closed. The blocker there was §3: a Bearer challenge MUST carry at least one auth-param, so removing the error code meant adding a realm, which didn't fit.
That's different for MCP servers now. resource_metadata (RFC 9728) is the param MCP clients need to start sign-in, and the SDK already adds it when resourceMetadataUrl is set (and scope when requiredScopes is set).
Why it matters: the first request from every MCP client has no token, so this is the challenge every client sees first. invalid_token says "your token went bad" to a client that hasn't signed in yet. We ran into this building the MCP server for Bachs (a payments API), and write the challenge ourselves for now.
Would you take a PR for this? It's a small change plus tests in packages/server (the Express adapter shares bearerAuthChallengeResponse, so it would follow), and a v1.x backport if you want one.
What did you expect?
Drop the error code only when another param remains:
- no credentials, resource_metadata or scope present → Bearer scope="a:read", resource_metadata="…"
- no credentials, no other params → unchanged, so the challenge is never a bare "Bearer"
- a token was sent but is bad → unchanged
Code to reproduce
import { requireBearerAuth } from '@modelcontextprotocol/server';
const gate = requireBearerAuth({
verifier: { verifyAccessToken: async () => { throw new Error('unused'); } },
requiredScopes: ['a:read'],
resourceMetadataUrl: 'https://mcp.example/.well-known/oauth-protected-resource/mcp',
});
const res = await gate(new Request('https://mcp.example/mcp', { method: 'POST' }));
console.log(res.status, res.headers.get('www-authenticate'));
SDK version
@modelcontextprotocol/server 2.4.0
Area
Auth
- Ngôn ngữ chính
- TypeScript
- Star
- 13.7k
- Fork
- 2.3k
- Merge trung bình
- 1 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 51
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không 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/typescript-sdk
-
The `maxToolInputElements` refusal lacks the `Input validation error:` prefix that the schema refusal carriesCó thể đã có người làm @barry166 đã nhận 3 ngày trước. Đang mởv1 v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
modelcontextprotocol/typescript-sdk#3111 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
server: registeredResource.update and registeredResourceTemplate.update desync title and metadata.title when updating metadata aloneCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởv1 v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
modelcontextprotocol/typescript-sdk#3103 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[v1.x] Protocol.request keeps its abort listener after the request resolved, so a later abort sends notifications/cancelled for an answered request (1.30.0)Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởv1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
modelcontextprotocol/typescript-sdk#3090 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[v2] e2e `protocol:timeout:max-total` is flaky over SSE: fake timers advance before the request reaches the serverCó thể đã có người làm @Singmin đã nhận 12 ngày trước. Đang mởv1 v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
modelcontextprotocol/typescript-sdk#3045 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[v1.x] Backport #2654: `notifications/cancelled` with `requestId: 0` is ignored, so the first server→client request cannot be cancelled (still in 1.32.1)Có thể đã có người làm @CloudCorpRecords đã nhận 13 ngày trước. Đang mởv1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
modelcontextprotocol/typescript-sdk#3043 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của modelcontextprotocol/typescript-sdk
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
components-web-app/docs#307 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
localstack/localstack-mcp-server#112 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:frontend kind:bug priority:p1 ready
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug ready-for-agent
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
PhyberApex/kuroshiro#1687 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Performance (Web Vitals) collector: LCP/FCP from background tabs are not discarded, inflating p75Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
umami-software/umami#4720 ·
Maintainer thường phản hồi trong vòng 3 ngày