diff --git a/src/fetch/src/mcp_server_fetch/server.py b/src/fetch/src/mcp_server_fetch/server.py
index 9bdbb1ef47..bb628235fb 100644
--- a/src/fetch/src/mcp_server_fetch/server.py
+++ b/src/fetch/src/mcp_server_fetch/server.py
@@ -36,12 +36,19 @@ def extract_content_from_html(html: str) -> str:
ret = readabilipy.simple_json.simple_json_from_html_string(
html, use_readability=True
)
+ failed = "Page failed to be simplified from HTML"
if not ret["content"]:
- return "Page failed to be simplified from HTML"
+ return failed
content = markdownify.markdownify(
ret["content"],
heading_style=markdownify.ATX,
)
+ # Without Node, readabilipy's pure-Python extractor never returns empty
+ # content: an empty page comes back as "
", which converts to an
+ # empty string. Report that as the same simplification failure the Node
+ # path reports, rather than letting it reach pagination as an exhausted page.
+ if not content.strip():
+ return failed
return content
diff --git a/src/fetch/tests/test_protocol.py b/src/fetch/tests/test_protocol.py
index d13a2fb2a2..f6672662fd 100644
--- a/src/fetch/tests/test_protocol.py
+++ b/src/fetch/tests/test_protocol.py
@@ -451,18 +451,23 @@ async def test_html_without_node_falls_back_to_pure_python(web: FakeWeb) -> None
assert "https://example.com/x" not in text
-# KNOWN BUG #4989: an empty page without Node reports "No more content available" at start_index 0 instead of a simplification failure; the fix changes this assertion.
@pytest.mark.usefixtures("python_readability")
-async def test_empty_html_without_node_reads_as_no_more_content(web: FakeWeb) -> None:
- # The pure-Python extractor never returns empty content, so the
- # "failed to be simplified" message is not reached; the page converts to
- # an empty string and the pagination check reports it as exhausted.
+async def test_empty_html_without_node_cannot_be_simplified(web: FakeWeb) -> None:
+ # The pure-Python extractor returns "" for an empty page, which
+ # converts to an empty string. It reports the same simplification failure
+ # as the Node path, not "No more content available" at start_index 0.
web.add(PAGE, html(""))
async with connect(ignore_robots_txt=True) as (session, _):
result = await call(session, {"url": PAGE})
- assert text_of(result) == (
- f"Contents of {PAGE}:\nNo more content available."
- )
+ assert wire(result) == {
+ "content": [
+ {
+ "type": "text",
+ "text": f"Contents of {PAGE}:\nPage failed to be simplified from HTML",
+ }
+ ],
+ "isError": False,
+ }
async def test_raw_returns_html_unsimplified(web: FakeWeb) -> None: