Skip to content

Commit 6c06aa3

Browse files
committed
mcp: relax SSE connection response handling in non-strict mode
Signed-off-by: Xie Zhihao <[email protected]>
1 parent 32d84d8 commit 6c06aa3

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

mcp/streamable.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,13 +1377,14 @@ func (c *streamableClientConn) connectStandaloneSSE() {
13771377
resp.Body.Close()
13781378
return
13791379
}
1380-
if resp.StatusCode == http.StatusNotFound && !c.strict {
1381-
// modelcontextprotocol/gosdk#393: some servers return NotFound instead
1382-
// of MethodNotAllowed for the standalone SSE stream.
1380+
if resp.StatusCode >= 400 && resp.StatusCode < 500 && !c.strict {
1381+
// modelcontextprotocol/go-sdk#393,#610: some servers return NotFound or
1382+
// other status codes instead of MethodNotAllowed for the standalone SSE
1383+
// stream.
13831384
//
13841385
// Treat this like MethodNotAllowed in non-strict mode.
13851386
if c.logger != nil {
1386-
c.logger.Warn("got 404 instead of 405 for standalone SSE stream")
1387+
c.logger.Warn(fmt.Sprintf("got %d instead of 405 for standalone SSE stream", resp.StatusCode))
13871388
}
13881389
resp.Body.Close()
13891390
return

mcp/streamable_client_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ func TestStreamableClientStrictness(t *testing.T) {
305305
{"strict initialized", true, http.StatusOK, http.StatusMethodNotAllowed, true},
306306
{"unstrict initialized", false, http.StatusOK, http.StatusMethodNotAllowed, false},
307307
{"strict GET", true, http.StatusAccepted, http.StatusNotFound, true},
308-
{"unstrict GET", false, http.StatusOK, http.StatusNotFound, false},
308+
{"unstrict GET on StatusNotFound", false, http.StatusOK, http.StatusNotFound, false},
309+
{"unstrict GET on StatusBadRequest", false, http.StatusOK, http.StatusBadRequest, false},
309310
}
310311
for _, test := range tests {
311312
t.Run(test.label, func(t *testing.T) {

0 commit comments

Comments
 (0)