Skip to content

Commit 9b6e320

Browse files
cliffhallclaude
andcommitted
fix(fetch): report an empty page without Node as a simplification failure
Without Node, readabilipy's pure-Python extractor returns "<div></div>" for an empty page, which markdownify turns into an empty string. That empty string reached the pagination check, so start_index 0 read as "No more content available". extract_content_from_html now treats an empty conversion as the same simplification failure the Node path reports. The pinning test is renamed to describe the correct behavior and its KNOWN BUG modelcontextprotocol#4989 marker is removed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 142bb84 commit 9b6e320

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

‎src/mcp_server_fetch/server.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,19 @@ def extract_content_from_html(html: str) -> str:
3636
ret = readabilipy.simple_json.simple_json_from_html_string(
3737
html, use_readability=True
3838
)
39+
failed = "<error>Page failed to be simplified from HTML</error>"
3940
if not ret["content"]:
40-
return "<error>Page failed to be simplified from HTML</error>"
41+
return failed
4142
content = markdownify.markdownify(
4243
ret["content"],
4344
heading_style=markdownify.ATX,
4445
)
46+
# Without Node, readabilipy's pure-Python extractor never returns empty
47+
# content: an empty page comes back as "<div></div>", which converts to an
48+
# empty string. Report that as the same simplification failure the Node
49+
# path reports, rather than letting it reach pagination as an exhausted page.
50+
if not content.strip():
51+
return failed
4552
return content
4653

4754

‎tests/test_protocol.py‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -451,18 +451,23 @@ async def test_html_without_node_falls_back_to_pure_python(web: FakeWeb) -> None
451451
assert "https://example.com/x" not in text
452452

453453

454-
# 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.
455454
@pytest.mark.usefixtures("python_readability")
456-
async def test_empty_html_without_node_reads_as_no_more_content(web: FakeWeb) -> None:
457-
# The pure-Python extractor never returns empty content, so the
458-
# "failed to be simplified" message is not reached; the page converts to
459-
# an empty string and the pagination check reports it as exhausted.
455+
async def test_empty_html_without_node_cannot_be_simplified(web: FakeWeb) -> None:
456+
# The pure-Python extractor returns "<div></div>" for an empty page, which
457+
# converts to an empty string. It reports the same simplification failure
458+
# as the Node path, not "No more content available" at start_index 0.
460459
web.add(PAGE, html("<html><body></body></html>"))
461460
async with connect(ignore_robots_txt=True) as (session, _):
462461
result = await call(session, {"url": PAGE})
463-
assert text_of(result) == (
464-
f"Contents of {PAGE}:\n<error>No more content available.</error>"
465-
)
462+
assert wire(result) == {
463+
"content": [
464+
{
465+
"type": "text",
466+
"text": f"Contents of {PAGE}:\n<error>Page failed to be simplified from HTML</error>",
467+
}
468+
],
469+
"isError": False,
470+
}
466471

467472

468473
async def test_raw_returns_html_unsimplified(web: FakeWeb) -> None:

0 commit comments

Comments
 (0)