modelcontextprotocol / modelcontextprotocol/java-sdk

[HELP NEEDED] io.modelcontextprotocol.spec.McpError: Client failed to initialize by explicit API call

未關閉
#501 8 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

question
主要語言
Java
星號
3.7k
分支
1.1k
平均合併
1 天 15 小時
30 天內合併 PR
9

描述

Hi everyone,

I'm working on a chat-based plugin using the MCP Java SDK (io.modelcontextprotocol.sdk:mcp:0.11.0) and getting the error io.modelcontextprotocol.spec.McpError: Client failed to initialize by explicit API call when using HTTPS transport.

Problem: Client initialization fails with the above error when using HTTPS transport. The same server works perfectly with VS Code (which also uses HTTPS) and with SSE transport from our Java client.

Context:

  • The MCP server is an internal implementation that works perfectly with VS Code via HTTPS
  • SSE transport connects successfully with the same server from our Java client
  • Only HTTPS transport is failing during the initialization phase in Java SDK
  • Server definitely supports MCP-over-HTTP since VS Code connects successfully

Code snippet:

if ("http".equalsIgnoreCase(transportType)) { // Note: actually using HTTPS URL
HttpClientStreamableHttpTransport.Builder builder = HttpClientStreamableHttpTransport.builder(mcpUrl)
.customizeRequest(requestBuilder -> {
System.out.println("Customizing request for HTTP MCP client: " + mcpUrl);
// Add authentication headers, if available
if (authHeader != null && !authHeader.isEmpty()) {
authHeader.forEach((key, value) -> {
requestBuilder.setHeader(key, value);
});
}
})
.endpoint(URI.create(mcpUrl).getRawPath());

client = McpClient.async(builder.build()).requestTimeout(Duration.ofSeconds(60)).build();

}

client.initialize().block();

Underlying Stack Trace:

java.lang.RuntimeException: Failed to send message: DummyEvent[responseInfo=jdk.internal.net.http.ResponseInfoImpl@fbe869d]
	at io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport.lambda$sendMessage$27(HttpClientStreamableHttpTransport.java:512)
	...
	at io.modelcontextprotocol.client.transport.ResponseSubscribers$BodilessResponseLineSubscriber.hookOnComplete(ResponseSubscribers.java:287)
 
 
Key observations:
1. Error occurs during client initialization with `client.initialize().block()`
2. Involves `BodilessResponseLineSubscriber.hookOnComplete` suggesting HTTP response processing issue
3. Same server works with VS Code via HTTPS - so server implementation should be correct
4. Same server works with SSE transport from Java - so authentication/connectivity is fine
 
Questions:
1. Has anyone encountered this specific `McpError` with HTTP transport initialization?
2. Are there differences in how the Java SDK's HTTP transport vs VS Code's HTTP client handle MCP initialization?
3. Could this be related to HTTP headers, request methods, or connection handling specific to the Java SDK?
4. Are there additional configuration options for `HttpClientStreamableHttpTransport` that might resolve this?
 
What works vs what doesn't:
- ✅ VS Code → Server via HTTPS  
- ✅ Java Client → Server via SSE
- ❌ Java Client → Server via HTTPS (fails with initialization error)
 
This suggests the issue is specifically with how the Java SDK's HTTP transport handles initialization compared to VS Code's implementation.
 
Any insights on resolving this initialization error with HTTP transport would be greatly appreciated!

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

使用 HTTPS 透過 client.initialize().block() 重現該失敗,然後檢查第 512 行附近的 HttpClientStreamableHttpTransport.java 和第 287 行附近的 ResponseSubscribers.java。將 HTTPS 初始化回應與正常運作的 SSE 路徑以及回報的 VS Code 行為進行比較。當 Java HTTPS 初始化在沒有 McpError 的情況下成功完成時,即視為完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
java
領域
api, backend, networking
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
需要釐清
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。