Skip to content

Comments

fix: connectStandaloneSSE checking Content-Type header#736

Merged
findleyr merged 3 commits intomodelcontextprotocol:mainfrom
liushuangls:fix-connectStandaloneSSE
Jan 4, 2026
Merged

fix: connectStandaloneSSE checking Content-Type header#736
findleyr merged 3 commits intomodelcontextprotocol:mainfrom
liushuangls:fix-connectStandaloneSSE

Conversation

@liushuangls
Copy link
Contributor

mcp/streamable: checking Content-Type header

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.

@findleyr
Copy link
Contributor

Thanks for this CL. We're on break now, but I'll review next week.

Copy link
Contributor

@findleyr findleyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the test! One more minor comment.

//
// [§2.2.3]: https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#listening-for-messages-from-the-server
if resp.StatusCode == http.StatusMethodNotAllowed {
if resp.StatusCode == http.StatusMethodNotAllowed || resp.Header.Get("Content-Type") != "text/event-stream" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not catching this before: I think this is a non-conformant server implementation, so we should at the very least log.

Let's pull this out into a separate if block, and similar to the block on line 1558 below, we should log a warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@findleyr findleyr merged commit e66c23f into modelcontextprotocol:main Jan 4, 2026
5 checks passed
@liushuangls liushuangls deleted the fix-connectStandaloneSSE branch January 5, 2026 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants