modelcontextprotocol / modelcontextprotocol/java-sdk

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

Đang mở
#882 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

needs repro
Ngôn ngữ chính
Java
Star
3.7k
Fork
1.1k
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
9

Mô tả

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();
    }

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với ví dụ builder HttpClientStreamableHttpTransport được cung cấp và tái hiện lỗi bằng mcpSyncClient.initialize(). Đọc LifecycleInitializer.java quanh dòng 288 và đường dẫn khởi tạo dẫn đến timeout 20 giây, sau đó so sánh hành vi của streamable HTTP với trường hợp SSE được báo cáo là hoạt động. Công việc được hoàn tất khi Java SDK khởi tạo thành công cho streamable HTTP endpoint được cung cấp và có một regression test cho hành vi này.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java
Lĩnh vực
api, networking
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.