modelcontextprotocol / modelcontextprotocol/java-sdk

JAVA SDK connectto streamablehttptransport raise "Client failed to initialize by explicit API call"

未关闭
#882 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

needs repro
主要语言
Java
星标
3.7k
派生
1.1k
平均合并
1 天 15 小时
30 天内合并 PR
9

描述

JAVA SDK connectto streamablehttptransport raise "Client failed to initialize by explicit API call".
sse is fine.
I searched on issuses, Some similar issues were found, but they were all marked as resolved.

Bug description
JAVA SDK connectto streamablehttptransport raise "Client failed to initialize by explicit API call"

Environment
Please provide as many details as possible: Spring MCP version, Java version, which vector store you use if any, etc
java 17 , main brunch 2026-03-25; v1.1.0

Steps to reproduce

    public static void testmcphttp() {
        String mcpUrl = "http://192.168.190.51:31603/api/mcp/mcpserver/mcp";
        String tk = "gtk849416ca3e3b44a28b9956046895fafe";
        mcpUrl = "http://127.0.0.1:8702/api/mcp/mcpserver/mcp";
        tk = "gtkba06f61af36f4cf597624c73cc23abbc";
        HttpClientStreamableHttpTransport transport = HttpClientStreamableHttpTransport
                .builder("http://127.0.0.1:8702")
                .endpoint("/api/mcp/mcpserver/mcp?tk=" + tk)
                .build();
        McpSyncClient mcpSyncClient = McpClient
                .sync(transport)
                .clientInfo(new McpSchema.Implementation("Sample client", "0.0.0"))
                .build();

        mcpSyncClient.initialize();
    }

Expected behavior


Exception in thread "main" java.lang.RuntimeException: Client failed to initialize by explicit API call
	at io.modelcontextprotocol.client.LifecycleInitializer.lambda$withInitialization$2(LifecycleInitializer.java:288)
	at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:94)
	at reactor.core.publisher.SerializedSubscriber.onError(SerializedSubscriber.java:124)
	at reactor.core.publisher.FluxTimeout$TimeoutMainSubscriber.handleTimeout(FluxTimeout.java:296)
	at reactor.core.publisher.FluxTimeout$TimeoutMainSubscriber.doTimeout(FluxTimeout.java:281)
	at reactor.core.publisher.FluxTimeout$TimeoutTimeoutSubscriber.onNext(FluxTimeout.java:420)
	at reactor.core.publisher.FluxOnErrorReturn$ReturnSubscriber.onNext(FluxOnErrorReturn.java:162)
	at reactor.core.publisher.MonoDelay$MonoDelayRunnable.propagateDelay(MonoDelay.java:270)
	at reactor.core.publisher.MonoDelay$MonoDelayRunnable.run(MonoDelay.java:285)
	at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68)
	at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28)
	at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)
	Suppressed: java.lang.Exception: #block terminated with an error
		at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:104)
		at reactor.core.publisher.Mono.block(Mono.java:1779)
		at io.modelcontextprotocol.client.McpSyncClient.initialize(McpSyncClient.java:189)
		at io.modelcontextprotocol.TLCMCP.testmcphttp(TLCMCP.java:33)
		at io.modelcontextprotocol.TLCMCP.main(TLCMCP.java:57)
Caused by: java.util.concurrent.TimeoutException: Did not observe any item or terminal signal within 20000ms in 'map' (and no fallback has been configured)
	... 14 more

Minimal Complete Reproducible example

    public static void testmcphttp() {
        String mcpUrl = "http://192.168.190.51:31603/api/mcp/mcpserver/mcp";
        String tk = "gtk849416ca3e3b44a28b9956046895fafe";
        mcpUrl = "http://127.0.0.1:8702/api/mcp/mcpserver/mcp";
        tk = "gtkba06f61af36f4cf597624c73cc23abbc";
        HttpClientStreamableHttpTransport transport = HttpClientStreamableHttpTransport
                .builder("http://127.0.0.1:8702")
                .endpoint("/api/mcp/mcpserver/mcp?tk=" + tk)
                .build();
        McpSyncClient mcpSyncClient = McpClient
                .sync(transport)
                .clientInfo(new McpSchema.Implementation("Sample client", "0.0.0"))
                .build();

        mcpSyncClient.initialize();
    }

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从提供的 HttpClientStreamableHttpTransport builder 示例开始,并使用 mcpSyncClient.initialize() 重现失败。阅读 LifecycleInitializer.java 第 288 行附近的内容以及导致 20 秒超时的初始化路径,然后将 streamable HTTP 的行为与报告中可正常工作的 SSE 情况进行比较。完成的标准是 Java SDK 能够针对提供的 streamable HTTP endpoint 成功初始化,并且有一个覆盖该行为的回归测试。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
api, networking
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。