mcp-server-fetch: missing Content-Type header forces non-HTML payloads into readability extraction, failing with error
Which server?
fetch (mcp-server-fetch)
Server version
2026.10.10 (PyPI / commit bbb701e)
How did you run the server?
uvx (Python package)
Transport
stdio
Protocol era
Current (2024-11-05 spec or newer)
MCP client and version
Direct reproduction script / Claude Desktop 0.8.0
Operating system and runtime
Linux 5.15 / Python 3.11
Server configuration
Standard mcp-server-fetch execution.
Steps to reproduce
In src/fetch/src/mcp_server_fetch/server.py lines 335–341:
content_type = response.headers.get("content-type", "")
is_page_html = (
"<html" in page_raw[:100] or "text/html" in content_type or not content_type
)
if is_page_html and not force_raw:
return extract_content_from_html(page_raw), ""
Notice the clause or not content_type.
When fetching an HTTP endpoint that does not include an explicit Content-Type header (common with static files, raw S3/CDN buckets, embedded/IoT servers, or internal microservices returning plain text or raw JSON):
response.headers.get("content-type", "")returns"".not content_typeevaluates toTrue.is_page_htmlbecomesTrueregardless of what the payload actually contains.extract_content_from_html(page_raw)is invoked on non-HTML content (e.g. JSON{"status": 200}, plain text, CSV, or Markdown).readabilipy.simple_json.simple_json_from_html_string()cannot extract readability content from non-HTML text.- The tool returns
<error>Page failed to be simplified from HTML</error>instead of returning the raw payload.
Contrast this with the exact same payload returned with Content-Type: text/plain:
- With
Content-Type: text/plain:is_page_htmlisFalse-> returnspage_rawsuccessfully. - Without
Content-Typeheader:is_page_htmlisTrue-> fails with<error>Page failed to be simplified from HTML</error>.
Minimal reproduction:
def classify_page(page_raw: str, content_type: str):
is_page_html = (
"<html" in page_raw[:100] or "text/html" in content_type or not content_type
)
return is_page_html
# text/plain with header: False -> raw content returned
assert classify_page("hello world", "text/plain") is False
# plain text without header: True -> wrongly forced into HTML extractor!
assert classify_page("hello world", "") is True
# JSON without header: True -> wrongly forced into HTML extractor!
assert classify_page('{"status": "ok"}', "") is True
Expected behavior
Responses lacking a Content-Type header should NOT automatically be assumed to be HTML. Unless the payload contains unambiguous HTML markup (e.g. starting with <!DOCTYPE html or <html), it should be treated as non-HTML and fall back to returning page_raw.
Actual behavior
Any non-HTML endpoint without a Content-Type header is coerced into HTML simplification and fails with:
<error>Page failed to be simplified from HTML</error>
Logs or error output
<error>Page failed to be simplified from HTML</error>
From src/fetch/src/mcp_server_fetch/server.py:158-160:
ret = readabilipy.simple_json.simple_json_from_html_string(html, use_readability=True)
if not ret["content"]:
return "<error>Page failed to be simplified from HTML</error>"
Already prototyped a fix?
In src/fetch/src/mcp_server_fetch/server.py, remove or not content_type and check for HTML markers properly:
content_type_lower = content_type.lower()
page_start = page_raw.lstrip()[:100].lower()
is_page_html = (
"text/html" in content_type_lower
or "application/xhtml+xml" in content_type_lower
or page_start.startswith(("<html", "<!doctype html"))
)
This ensures:
- Valid HTML documents (with or without headers) are still simplified.
- Payloads without a
Content-Typeheader that are NOT HTML fall through to the raw content return block instead of returning an error string.
Before you submit
- [x] I searched existing issues and this is not a duplicate.
- [x] This is not a security vulnerability report (those go through the private advisory form).
I investigated this and prepared a verified fix with tests on branch bradleyjoejoseph/servers@fix/fetch-missing-content-type.
Root Cause
In src/fetch/src/mcp_server_fetch/server.py:
is_page_html = (
"<html" in page_raw[:100] or "text/html" in content_type or not content_type
)
Evaluating not content_type as True forces any non-HTML endpoint without an explicit Content-Type header (JSON, CSV, plain text, raw S3/CDN endpoints) into readabilipy's HTML parser, raising <error>Page failed to be simplified from HTML</error>.
Fix
- Sniff for HTML markers in content or headers rather than treating all missing headers as HTML:
content_type = response.headers.get("content-type", "")
content_type_lower = content_type.lower()
page_start = page_raw.lstrip()[:100].lower()
is_page_html = (
"text/html" in content_type_lower
or "application/xhtml+xml" in content_type_lower
or page_start.startswith(("<html", "<!doctype html", "<!doctype"))
or "<html" in page_start
)
- Handle the fallback prefix cleanly when
Content-Typeis empty. - Added unit tests in
src/fetch/tests/test_protocol.py:test_non_html_without_content_type_is_returned_raw(JSON payload without Content-Type header).test_plain_text_without_content_type_is_returned_raw(plain text payload without Content-Type header).
Verification
uv run pytest-> 124 passed in 3.66s.uv run ruff check .anduv run ruff format --check .-> all clean.
Branch with full commit and diff is ready on the fork if maintainers want to pull it into the workflow.
Triage: Priority Medium (total 6)
- Severity 3: A response with no Content-Type header is still treated as HTML, so plain text, JSON or Markdown is pushed through readability and markdownify and comes back altered (escaped underscores and asterisks, newlines collapsed without Node) or, for an empty body, as a simplification error, instead of being returned raw.
- Urgency 2: wanted eventually
- Bonuses: +1
buglabel
Still present on v2 (checked by a local reproduction against the current code).
Board: Servers V2 (#43), Status Incoming, awaiting maintainer review (no milestone yet). Part of the backlog triage in #4875.
Thanks for the triage @cliffhall!
Just a heads up that the fix and regression test suite (covering raw JSON/text payloads and preventing the markdownify/readability corruption when headers are omitted) are already verified and packaged on bradleyjoejoseph/servers@fix/fetch-missing-content-type whenever you or the team are ready to pull it into the V2 board.
Happy to rebase or adjust anything needed for the V2 milestone review!
Fixed by #5300, merged into v2/main; it ships with the v2.2.0 release.