Skip to content

Conversation

@liushuangls
Copy link

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
Author

Choose a reason for hiding this comment

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

Done.

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