Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

mcp-server-fetch: missing Content-Type header forces non-HTML payloads into readability extraction, failing with error

未关闭 适合新手
#5,134 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

从 src/fetch/src/mcp_server_fetch/server.py 第335–341行附近的内容类型检查开始,并将其与原始内容返回路径进行比较。检查当前如何识别没有内容类型的 HTML 响应,然后运行或添加针对缺少 header 的 HTML 和非 HTML 响应的测试。完成标准是:非 HTML 负载以原始形式返回,同时 HTML 仍会被简化。

由索引模型根据 Issue 内容生成。

描述

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):

  1. response.headers.get("content-type", "") returns "".
  2. not content_type evaluates to True.
  3. is_page_html becomes True regardless of what the payload actually contains.
  4. extract_content_from_html(page_raw) is invoked on non-HTML content (e.g. JSON {"status": 200}, plain text, CSV, or Markdown).
  5. readabilipy.simple_json.simple_json_from_html_string() cannot extract readability content from non-HTML text.
  6. 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_html is False -> returns page_raw successfully.
  • Without Content-Type header: is_page_html is True -> 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:

  1. Valid HTML documents (with or without headers) are still simplified.
  2. Payloads without a Content-Type header that are NOT HTML fall through to the raw content return block instead of returning an error string.
Before you submit
  • I searched existing issues and this is not a duplicate.
  • This is not a security vulnerability report (those go through the private advisory form).
主要语言
JavaScript
星标
91.2k
派生
11.8k
平均合并
6 小时 20 分钟
30 天内合并 PR
117

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelcontextprotocol/servers 的其他 Issue

查看 modelcontextprotocol/servers 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。