modelcontextprotocol / modelcontextprotocol/java-sdk
[HTTP+SSE] Throw the Initialization Exception Immediately for Invalid SSE Endpoint Instead of After Timeout
还没有人认领这个 Issue。
- 主要语言
- Java
- 星标
- 3.7k
- 派生
- 1.1k
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 9
描述
Problem
Currently, when the SSE Endpoint is misconfigured, the client waits until the initialization timeout (e.g., 60s) before throwing an generic initialization exception. This causes unnecessary delays and makes debugging difficult.
Examples settings:
- If MCP Server SSE Endpoint is: http://localhost:8080/sse
- When MCP Client is configured:
- SSE Endpoint: http://localhost:8080/incorrect-sse
- Request timeout: 60s
- Initialization timeout: 60s
Behavior:
-
Calling Client.initialize() waits 60s before throwing an exception. The test code and exception are shown in the figure below:
-
Same issue occurs when:
-
The base URL points to a non-existent server. The test code and exception are shown in the figure below:
-
Access Token is misconfigured and the server requires authorization.
-
Expected Behavior
- Initialization exception should be thrown immediately when the server responds with an error (e.g., 404, 401, access denied), instead of waiting for the timeout.
- Exception should include status code and/or response body from the SSE endpoint to help diagnose configuration errors.
Technical Details
I checked the code, and the timeout issue occurs in the HttpClientSseClientTransport class when assigning the messageEndpointSink member variable. The initialization POST request keeps waiting for messageEndpointSink to be assigned. However, when the SSE Endpoint is incorrectly specified, the GET request never successfully returns the message endpoint, causing the initialization POST request to hang until the timeout occurs.
Affected Versions
- SDK 0.11.2
- SDK 0.12.1
- ...
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 HttpClientSseClientTransport 开始,跟踪初始化 POST 请求如何等待 messageEndpointSink,以及 SSE GET 请求如何处理无效 endpoint。复现错误 endpoint、不存在的服务器和授权错误这几种情况,然后验证初始化会立即报告服务器错误及其状态码或响应正文,而不是等待初始化超时。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- api, networking
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100