-
Couldn't load subscription status.
- Fork 2.7k
Open
Labels
P2Moderate issues affecting some users, edge cases, potentially valuable featureModerate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingSomething isn't workingready for workEnough information for someone to start working onEnough information for someone to start working on
Description
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
When trying to connect to an MCP server using streamablehttp_client and ClientSession, the client prints Unexpected content type error if the server responds with anything other than the expected MCP JSON stream (e.g. error page, misconfigured endpoint, etc.).
This makes it difficult to handle cases where the server is not reachable or not serving MCP correctly, since no exception is raised.
Example Code
import asyncio
from mcp.client.streamable_http import streamablehttp_client
from mcp import ClientSession
async def main():
async with streamablehttp_client(
url="http://localhost:3001/mcp",
) as (read, write, _):
async with ClientSession(read, write) as session:
try:
await session.initialize()
except Exception as e:
print(f"Failed to initialize MCP session: {e}")
return
print("MCP session initialized")
if __name__ == "__main__":
asyncio.run(main())Output
Unexpected content type: text/html; charset=utf-8
Python & MCP Python SDK
python 3.13.5
mcp 1.14.1
acanadil and bystepiiacanadil and bystepii
Metadata
Metadata
Assignees
Labels
P2Moderate issues affecting some users, edge cases, potentially valuable featureModerate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingSomething isn't workingready for workEnough information for someone to start working onEnough information for someone to start working on