Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mcp/streamable.go
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,14 @@ func (c *streamableClientConn) connectStandaloneSSE() {
resp.Body.Close()
return
}
if resp.Header.Get("Content-Type") != "text/event-stream" {
// modelcontextprotocol/go-sdk#736: some servers return 200 OK or redirect with
// non-SSE content type instead of text/event-stream for the standalone
// SSE stream.
c.logger.Warn(fmt.Sprintf("got Content-Type %s instead of text/event-stream for standalone SSE stream", resp.Header.Get("Content-Type")))
resp.Body.Close()
return
}
if resp.StatusCode >= 400 && resp.StatusCode < 500 && !c.strict {
// modelcontextprotocol/go-sdk#393,#610: some servers return NotFound or
// other status codes instead of MethodNotAllowed for the standalone SSE
Expand Down
19 changes: 11 additions & 8 deletions mcp/streamable_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"time"

"github.com/google/go-cmp/cmp"

"github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2"
"github.com/modelcontextprotocol/go-sdk/jsonrpc"
)
Expand Down Expand Up @@ -258,14 +259,16 @@ func TestStreamableClientGETHandling(t *testing.T) {
tests := []struct {
status int
wantErrorContaining string
contentType string
}{
{http.StatusOK, ""},
{http.StatusMethodNotAllowed, ""},
// The client error status code is not treated as an error in non-strict
// mode.
{http.StatusNotFound, ""},
{http.StatusBadRequest, ""},
{http.StatusInternalServerError, "standalone SSE"},
{http.StatusOK, "", "text/event-stream"},
{http.StatusMethodNotAllowed, "", "text/event-stream"},
//// The client error status code is not treated as an error in non-strict
//// mode.
{http.StatusNotFound, "", "text/event-stream"},
{http.StatusBadRequest, "", "text/event-stream"},
{http.StatusInternalServerError, "standalone SSE", "text/event-stream"},
{http.StatusOK, "", "text/html; charset=utf-8"},
}

for _, test := range tests {
Expand All @@ -286,7 +289,7 @@ func TestStreamableClientGETHandling(t *testing.T) {
},
{"GET", "123", "", ""}: {
header: header{
"Content-Type": "text/event-stream",
"Content-Type": test.contentType,
},
status: test.status,
wantProtocolVersion: latestProtocolVersion,
Expand Down