mcp: fix connectStandaloneSSE checking Content-Type header (#736)
Issue encountered: the MCP server request was unexpectedly redirected to an HTML page. Because the client didn’t validate the response Content-Type, it still entered handleSSE, which then kept treating the HTML as an SSE stream and repeatedly re-requesting the same page—creating an infinite request loop.
This commit is contained in:
parent
9c4d349ec0
commit
e66c23fae4
1 changed files with 19 additions and 8 deletions
|
|
@ -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"
|
||||
)
|
||||
|
|
@ -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 {
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue