all scenarios

Leading garbage before JSON

bom-garbage · Transport & framing

Endpoint (Streamable HTTP)
https://chaos-mcp.thomascdnns.com/s/bom-garbage/mcp
On the wire — recorded from a real request
your clientchaos-mcp01initializePOST /s/bom-garbage/mcp200 OK · application/json · 5 ms·[debug] starting handler...{"jsonrpc": "2.0", "id": 1, "result": {"protocolVersion": "2024-11-05", "capabilities": {"tools": {}}, "serverInfo": {"name": "chaos-mcp/bom-garbage", "version": "1.0.0"}, "instructions": "chaos-mcpscenario: bom-garbage \u2014 Leading garbage before JSON"}}! body does not parse as JSON — unexpected utf-8 bom (decode using utf-8-sig)! no Content-Length — body delimited by connection close02tools/listPOST /s/bom-garbage/mcp200 OK · application/json · 5 ms·[debug] starting handler...{"jsonrpc": "2.0", "id": 2, "result": {"tools": [{"name": "echo", "description": "Echo back the provided message.", "inputSchema": {"type": "object", "properties": {"message": {"type": "string", "description": "Text to echo"}}, "required": ["message"]}}, {"name": "add", "description": "Add two numbers and return the sum.", "inputSchema": {"type": "object", "properties": {"a": {"type": "number"}, "b": {"type": "number"}}, "required": ["a", "b"]}}, {"name": "current_time", "description": "Return the current server time in RFC3339.", "inputSchema": {"type": "object", "properties": {"timezone": {"type": "string", "description": "IANA timezone, default UTC"}}}}]}}! body does not parse as JSON — unexpected utf-8 bom (decode using utf-8-sig)! no Content-Length — body delimited by connection close

Symptom

what you'll observe

Some parsers fail; others silently skip the first tool. Intermittent and confusing.

Cause

what this reproduces

A stray log/print writes to stdout (the stdio transport) or before the HTTP body — debug output leaks into the stream.

Fix

how you'd resolve it

Never write to the transport stream except protocol messages; route logs to stderr/files.

Try it with curl
bash
curl -sS -X POST \
  https://chaos-mcp.thomascdnns.com/s/bom-garbage/mcp \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '
"jsonrpc""2.0"
"id"1
"method""initialize"
"params"
"protocolVersion""2024-11-05"
"capabilities"
"clientInfo""name""curl""version""1"

'