Open
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
Hello,
When I tried to create a simple HTTP MCP server I ran into this bug.
New StreamableHttp connection request
Query parameters: {"url":"http://localhost:6274/sse","transportType":"streamable-http"}
Created StreamableHttp server transport
Created StreamableHttp client transport
Client <-> Proxy sessionId: e4e153f5-ae33-4061-8adc-c4a2985e5fae
Error from MCP server: StreamableHTTPError: Streamable HTTP error: Unexpected content type: text/html; charset=utf-8
at StreamableHTTPClientTransport.send (file:///home/aj/.npm/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js:318:27)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
code: -1
}
Example Code
import httpx
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("poke")
POKEAPI_BASE = "https://pokeapi.co/api/v2"
# --- Helper to fetch Pokémon data ---
async def fetch_pokemon_data(name: str) -> dict:
async with httpx.AsyncClient() as client:
try:
response = await client.get(f"{POKEAPI_BASE}/pokemon/{name.lower()}")
if response.status_code == 200:
return response.json()
except httpx.HTTPError:
pass
return {}
# --- Tool: Get info about a Pokémon ---
@mcp.tool()
async def get_pokemon_info(name: str) -> str:
"""Get detailed info about a Pokémon by name."""
data = await fetch_pokemon_data(name)
if not data:
return f"No data found for Pokémon: {name}"
stats = {stat['stat']['name']: stat['base_stat'] for stat in data['stats']}
types_ = [t['type']['name'] for t in data['types']]
abilities = [a['ability']['name'] for a in data['abilities']]
return f"""
Name: {data['name'].capitalize()}
Types: {', '.join(types_)}
Abilities: {', '.join(abilities)}
Stats: {', '.join(f"{k}: {v}" for k, v in stats.items())}
"""
# --- Tool: Create a tournament squad ---
@mcp.tool()
async def create_tournament_squad() -> str:
"""Create a powerful squad of Pokémon for a tournament."""
top_pokemon = ["charizard", "garchomp", "lucario", "dragonite", "metagross", "gardevoir"]
squad = []
for name in top_pokemon:
data = await fetch_pokemon_data(name)
if data:
squad.append(data["name"].capitalize())
return "Tournament Squad:\n" + "\n".join(squad)
# --- Tool: List popular Pokémon ---
@mcp.tool()
async def list_popular_pokemon() -> str:
"""List popular tournament-ready Pokémon."""
return "\n".join([
"Charizard", "Garchomp", "Lucario",
"Dragonite", "Metagross", "Gardevoir"
])
# --- Entry point ---
if __name__ == "__main__":
mcp.run(transport="streamable-http")
Python & MCP Python SDK
python 3.11
mcp-1.10.1
Metadata
Metadata
Assignees
Labels
No labels