modelcontextprotocol / modelcontextprotocol/python-sdk
Server ClientAuthenticator requires client_id in token body, rejecting valid client_secret_basic requests (RFC 6749 §2.3.1)
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 24.3k
- 派生
- 4k
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 31
描述
Summary
The server-side ClientAuthenticator reads client_id only from the token request form body and raises invalid_client: "Missing client_id" when it is absent — even when the client authenticated correctly via HTTP Basic (Authorization: Basic base64(client_id:client_secret)). Per RFC 6749 §2.3.1, a client using client_secret_basic sends its client_id and client_secret in the Authorization header and MAY omit them from the body. Servers advertising client_secret_basic in token_endpoint_auth_methods_supported therefore reject spec-compliant clients (e.g. clients that use Basic and do not duplicate client_id into the body).
Location
src/mcp/server/auth/middleware/client_auth.py, authenticate_request:
form_data = await request.form()
client_id = form_data.get("client_id")
if not client_id:
raise AuthenticationError("Missing client_id")
...
if client.token_endpoint_auth_method == "client_secret_basic":
...
basic_client_id, request_client_secret = decoded.split(":", 1)
basic_client_id = unquote(basic_client_id)
if basic_client_id != client_id: # only cross-checks; never used as fallback
raise AuthenticationError("Client ID mismatch in Basic auth")
client_id from the Basic header is only used to cross-check a body-supplied value; it is never used as a fallback source. So a request with credentials solely in the Basic header fails before the client is even looked up.
Steps to reproduce
- Register a client with
token_endpoint_auth_method=client_secret_basic. POST /tokenwithgrant_type=authorization_code,Authorization: Basic base64(client_id:client_secret), and noclient_id/client_secretin the form body.- Response:
401 {"error":"invalid_client","error_description":"Missing client_id"}.
Sending the same credentials via client_secret_post (in the body) works.
Expected
When Authorization: Basic is present, the authenticator should derive client_id from the header if it is absent from the body (RFC 6749 §2.3.1), then verify the secret as it does today.
Notes
This is the mirror image of client-side PR #3536 (which stops MCP clients from putting client_id in the body under client_secret_basic). With that client-side change, compliant clients will send client_id only in the Basic header — which this server-side code rejects. The two need to agree.
Observed on mcp 1.27.0.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 src/mcp/server/auth/middleware/client_auth.py 中的 authenticate_request 开始,跟踪表单字段和 HTTP Basic 凭据的解析方式。仅在 Authorization 标头中携带凭据来重现令牌请求,然后验证 client_secret_basic 身份验证成功,同时不匹配的凭据仍会产生文档中所述的身份验证错误。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- api, authentication
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 活跃
- 描述清晰度
- 描述清楚
- 新手友好度
- 76/100