modelcontextprotocol / modelcontextprotocol/java-sdk

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

Aperta
#501 8 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

question
Lingua principale
Java
Stelle
3.7k
Fork
1.1k
Merge medio
1g 15h
PR unite (30g)
9

Descrizione

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!

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci il fallimento con client.initialize().block() usando HTTPS, quindi esamina HttpClientStreamableHttpTransport.java intorno alla riga 512 e ResponseSubscribers.java intorno alla riga 287. Confronta la risposta di inizializzazione HTTPS con il percorso SSE funzionante e con il comportamento segnalato di VS Code. Il lavoro è completato quando l’inizializzazione HTTPS Java termina correttamente senza McpError.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
api, backend, networking
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.