HttpServletStreamableServerTransportProvider: GET stream sends no status or headers until the first event
維護者通常 3 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
從 HttpServletStreamableServerTransportProvider#doGet 開始,並針對 servlet transport 執行提供的 StreamableGetStreamHeadersTest.java 重現案例。在傳送任何 event 或 keep-alive ping 之前,GET 請求以狀態 200 和 text/event-stream Content-Type 完成,即表示完成。
由索引模型根據 Issue 內容生成。
描述
Bug description
After initialize, a GET to the MCP endpoint with Accept: text/event-stream gets no status line and no headers. doGet sets the SSE headers and starts async but doesn't flush, so nothing is sent until the server writes its first event to the stream. If the server has nothing to send, the client never gets a response.
Clients that wait for headers time out. Node's fetch (undici) gives up after its default headersTimeout of 300 s with UND_ERR_HEADERS_TIMEOUT. mcp-remote then retries twice and stops ("Maximum reconnection attempts (2) exceeded"). After that the server has no stream to the client, and server-initiated requests fail with Stream unavailable for session ... (see also #1061).
With keepAliveInterval set, the first ping sends the headers, but only after one interval.
The spec says the server must either return Content-Type: text/event-stream for this GET or return 405 (Streamable HTTP, 2025-11-25).
Environment
- Where it was seen: mcp-core 1.1.1, Spring Boot 4.0.5 (embedded Tomcat), Java 25.0.3, macOS 27.0.1. Client: Claude Desktop through mcp-remote 0.14.3, protocol 2025-11-25.
- Reproduced with the test below: mcp-core 1.1.1 and 2.0.1, tomcat-embed-core 11.0.22, JDK 26.0.1, macOS 14.7.4. The
doGetcode is the same onmain(1cf7903). - No keep-alive configured.
Steps to reproduce
- POST
initializeand note theMcp-Session-Id. - POST
notifications/initialized. You get 202. - GET the endpoint with
Accept: text/event-streamand the session ID.
curl -sN --max-time 20 -D - http://127.0.0.1:8080/mcp -H 'Accept: text/event-stream' -H "Mcp-Session-Id: $SID"
Actual: 0 bytes received in 20 s.
Expected behavior
200 with Content-Type: text/event-stream sent as soon as the GET stream opens, before any event is ready.
Minimal Complete Reproducible example
Dependencies: io.modelcontextprotocol.sdk:mcp, org.apache.tomcat.embed:tomcat-embed-core:11.0.22, org.junit.jupiter:junit-jupiter. The test fails with java.util.concurrent.TimeoutException on 1.1.1 and 2.0.1. If .keepAliveInterval(Duration.ofSeconds(1)) is added to the builder, it passes: the headers arrive with the first ping.
StreamableGetStreamHeadersTest.java
package repro;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.InputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.util.concurrent.TimeUnit;
import org.apache.catalina.Context;
import org.apache.catalina.startup.Tomcat;
import org.junit.jupiter.api.Test;
import io.modelcontextprotocol.server.McpAsyncServer;
import io.modelcontextprotocol.server.McpServer;
import io.modelcontextprotocol.server.transport.HttpServletStreamableServerTransportProvider;
class StreamableGetStreamHeadersTest {
@Test
void getStreamSendsHeadersBeforeFirstEvent() throws Exception {
HttpServletStreamableServerTransportProvider transport = HttpServletStreamableServerTransportProvider.builder()
.build();
McpAsyncServer server = McpServer.async(transport).serverInfo("repro", "1").build();
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir(Files.createTempDirectory("tomcat").toString());
tomcat.setPort(0);
Context context = tomcat.addContext("", null);
Tomcat.addServlet(context, "mcp", transport).setAsyncSupported(true);
context.addServletMappingDecoded("/*", "mcp");
tomcat.start();
try {
URI endpoint = URI.create("http://127.0.0.1:" + tomcat.getConnector().getLocalPort() + "/mcp");
HttpClient client = HttpClient.newHttpClient();
String sessionId = client.send(post(endpoint, null, """
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25",\
"capabilities":{},"clientInfo":{"name":"repro","version":"1"}}}"""),
HttpResponse.BodyHandlers.discarding())
.headers()
.firstValue("Mcp-Session-Id")
.orElseThrow();
assertEquals(202, client.send(post(endpoint, sessionId, """
{"jsonrpc":"2.0","method":"notifications/initialized"}"""),
HttpResponse.BodyHandlers.discarding())
.statusCode());
HttpRequest get = HttpRequest.newBuilder(endpoint)
.header("Accept", "text/event-stream")
.header("Mcp-Session-Id", sessionId)
.GET()
.build();
// Completes once the status line and headers arrive. Fails with TimeoutException.
HttpResponse<InputStream> response = client.sendAsync(get, HttpResponse.BodyHandlers.ofInputStream())
.get(5, TimeUnit.SECONDS);
assertEquals(200, response.statusCode());
assertTrue(response.headers().firstValue("Content-Type").orElse("").startsWith("text/event-stream"));
response.body().close();
}
finally {
server.closeGracefully().block();
tomcat.stop();
tomcat.destroy();
}
}
private static HttpRequest post(URI endpoint, String sessionId, String body) {
HttpRequest.Builder builder = HttpRequest.newBuilder(endpoint)
.header("Accept", "application/json, text/event-stream")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body));
if (sessionId != null) {
builder.header("Mcp-Session-Id", sessionId);
}
return builder.build();
}
}
- 主要語言
- Java
- 星號
- 3.7k
- 分支
- 1.1k
- 平均合併
- 2 天 5 小時
- 30 天內合併 PR
- 4
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/java-sdk 的其他 Issue
-
area/client bug P2
難度 2/5 1-3 小時 新手友好度 84/100
modelcontextprotocol/java-sdk#1124 · 5 則留言 ·
維護者通常 3 天內回覆
-
ServerCapabilities.logging is added unconditionally, overriding the caller's explicit capabilities未關閉bug P2 ready for work
難度 2/5 1-3 小時 新手友好度 68/100
modelcontextprotocol/java-sdk#1086 · 1 則留言 ·
維護者通常 3 天內回覆
-
enhancement good first issue P3
難度 2/5 1-3 小時 新手友好度 82/100
modelcontextprotocol/java-sdk#1067 · 1 則留言 ·
維護者通常 3 天內回覆
-
bug P2 ready for work
難度 2/5 1-3 小時 新手友好度 74/100
modelcontextprotocol/java-sdk#898 · 1 則留言 ·
維護者通常 3 天內回覆
-
documentation P2
難度 2/5 1-3 小時 新手友好度 65/100
modelcontextprotocol/java-sdk#798 · 1 則留言 ·
維護者通常 3 天內回覆
查看 modelcontextprotocol/java-sdk 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 65/100
aoqia194/leaf-loader#19 ·
-
難度 2/5 1-3 小時 新手友好度 84/100
apache/streampark#4521 ·
-
0 - Backlog 1 - Ready documentation good first issue help wanted
難度 2/5 1-3 小時 新手友好度 78/100
-
cbor
難度 2/5 1-3 小時 新手友好度 84/100
FasterXML/jackson-dataformats-binary#844 ·
維護者通常 1 天內回覆
-
Issue: Bug
難度 2/5 1-3 小時 新手友好度 82/100
OpenAPITools/openapi-generator#25107 ·
維護者通常 1 天內回覆