modelcontextprotocol / modelcontextprotocol/java-sdk

Disable standalone GET SSE Stream option for Streamable HTTP client transport

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

还没有人认领这个 Issue。

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

描述

Expected Behavior

The HttpClientStreamableHttpTransport.Builder should provide an option to completely disable the GET SSE stream, allowing the client to operate in pure request-response mode:

var transport = HttpClientStreamableHttpTransport.builder("https://example.com")
    .openSseStream(false) // Disable all GET SSE connections
    .build();

When openSseStream(false) is set:

  • No GET request is sent during connect() (regardless of openConnectionOnStartup)
  • No GET request is sent after session initialization in sendMessage()
  • The client operates in pure POST request / response mode
  • Server-initiated notifications and requests outside of POST response streams are not received

This aligns with the MCP specification, which uses MAY (RFC 2119) for the client GET across all spec versions (2025-03-26 and latest 2025-11-25):

The client MAY issue an HTTP GET to the MCP endpoint. This can be used to open an SSE stream, allowing the server to communicate to the client, without the client first sending data via HTTP POST.

Current Behavior

After the first successful POST response (typically InitializeResult), the transport unconditionally opens a GET SSE stream. The relevant code in HttpClientStreamableHttpTransport.sendMessage():

if (transportSession.markInitialized(
        responseEvent.responseInfo().headers().firstValue("mcp-session-id").orElseGet(() -> null))) {
    // Once we have a session, we try to open an async stream for
    // the server to send notifications and requests out-of-band.
    reconnect(null).contextWrite(deliveredSink.contextView()).subscribe();
}

The reconnect(null) call is unconditional — there is no builder flag, callback, or any mechanism to prevent it.

The existing openConnectionOnStartup(false) (which defaults to false) only prevents the eager GET during connect(). It does NOT prevent the GET triggered after the first POST response. There is no combination of existing builder options that achieves "never open a GET SSE stream."

Context

The MCP specification explicitly marks the GET SSE stream as optional — unchanged across both spec versions:

  • 2025-03-26: "The client MAY issue an HTTP GET to the MCP endpoint."
  • 2025-11-25: "The client MAY issue an HTTP GET to the MCP endpoint."

Despite this, the Java SDK provides no way to opt out. The GET stream is unconditionally opened after session initialization, and its lifecycle is difficult to manage:

Alternatives considered:

  • openConnectionOnStartup(false) — does not prevent the post-initialization GET
  • Intercepting at the HttpClient level to return a synthetic 405 Method Not Allowed for GET requests — this tricks the SDK into thinking the server doesn't support SSE streams, and the SDK stops trying. It works, but it's a hack: you have to wrap the HTTP client, intercept by method, and fabricate a response. This should be a first-class builder option, not something consumers need to reverse-engineer from the SDK's 405-handling behavior.

Precedent: The Go SDK already solved this exact problem via go-sdk#729 (merged Jan 11, 2026), adding a DisableStandaloneSSE field to StreamableClientTransport. The Java SDK should provide equivalent functionality.

Proposed fix: Add a builder option (e.g. disableStandaloneSSE(boolean) or openSseStream(boolean)) and guard both GET trigger points with it.

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 HttpClientStreamableHttpTransport.Builder 和 issue 中指定的 sendMessage() 入口点开始,然后从 connect() 和会话初始化处追踪 GET 路径。添加一个 builder 选项,以阻止两个独立的 GET SSE 触发器,并验证禁用模式只发送 POST 请求/响应流量,而不会打开 GET 流。

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

评估

技术栈
java
领域
api, networking
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
描述清楚
新手友好度
72/100

把新 issue 发到你的邮箱

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