Skip to content

SSE client doesn't raise exception if the MCP server responds with text/html #705

@codemug

Description

@codemug

Describe the bug

The SSE client will not raise any exception if MCP server responds with HTTP 200 and text/html content type at the time of connection:

async with sse_client(url) as (reader, writer)

The following event is logged.

{"event": "Error in sse_reader: Expected response header Content-Type to contain 'text/event-stream', got 'text/html'", "level": "error", "timestamp": "2025-05-13T13:22:19.309017Z"}

Since no exception is raised, there's no way to detect and rectify this issue in the control loop. I accidentally discovered this because I had mistakenly been running open-webui on port 8080, the same port my MCP server was supposed to run on.

To Reproduce
Steps to reproduce the behavior:

  1. Use an HTTP URL that returns 200 with an HTML document in the SSE client initialization
  2. Wrap the initialization in a try-except block, and check whether exception is raised

Expected behavior
Client should raise exception if the response is not correct.

Desktop (please complete the following information):

  • OS: macOS
  • Version: 15.4.1 (24E263)
  • MCP Package version: 1.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds reproneeds additional information to be able to reproduce bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions