modelcontextprotocol / modelcontextprotocol/java-sdk

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

Abierto
#501 8 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

question
Lenguaje dominante
Java
Estrellas
3.7k
Forks
1.1k
Merge medio
1 d 15 h
PR fusionados (30 d)
9

Descripción

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!

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Reproduce el fallo con client.initialize().block() usando HTTPS y, a continuación, inspecciona HttpClientStreamableHttpTransport.java alrededor de la línea 512 y ResponseSubscribers.java alrededor de la línea 287. Compara la respuesta de inicialización HTTPS con la ruta SSE que funciona y con el comportamiento notificado de VS Code. Se considera terminado cuando la inicialización HTTPS de Java se completa correctamente sin el McpError.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
java
Área
api, backend, networking
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.