Fetch MCP

by jae-jae
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Enables fetching and processing of dynamic web content that relies on JavaScript, executing client-side scripts to render full page content that traditional scrapers would miss.

  • Offers conversion of fetched web content to Markdown format, making it easy to integrate the retrieved information into markdown-based applications.

取指器 MCP

MCP 服务器使用 Playwright 无头浏览器获取网页内容。

优势

  • JavaScript 支持:与传统的网络抓取工具不同,Fetcher MCP 使用 Playwright 执行 JavaScript,使其能够处理动态网络内容和现代网络应用程序。
  • 智能内容提取:内置可读性算法自动从网页中提取主要内容,删除广告、导航和其他非必要元素。
  • 灵活的输出格式:支持HTML和Markdown输出格式,轻松与各种下游应用程序集成。
  • 并行处理fetch_urls工具可以并发获取多个URL,显著提高批量操作的效率。
  • 资源优化:自动阻止不必要的资源(图像、样式表、字体、媒体)以减少带宽使用并提高性能。
  • 强大的错误处理:全面的错误处理和日志记录确保即使在处理有问题的网页时也能可靠运行。
  • 可配置参数:对超时、内容提取和输出格式进行细粒度控制,以适应不同的用例。

快速入门

直接用npx运行:

npx -y fetcher-mcp

首次设置 - 通过在终端中运行以下命令来安装所需的浏览器:

npx playwright install chromium

调试模式

使用--debug选项运行以显示用于调试的浏览器窗口:

npx -y fetcher-mcp --debug

配置 MCP

在 Claude Desktop 中配置此 MCP 服务器:

在 MacOS 上: ~/Library/Application Support/Claude/claude_desktop_config.json

在 Windows 上: %APPDATA%/Claude/claude_desktop_config.json

{ "mcpServers": { "fetcher": { "command": "npx", "args": ["-y", "fetcher-mcp"] } } }

特征

  • fetch_url - 从指定的 URL 检索网页内容
    • 使用 Playwright 无头浏览器解析 JavaScript
    • 支持智能提取主要内容并转换为Markdown
    • 支持以下参数:
      • url :要获取的网页的 URL(必需参数)
      • timeout :页面加载超时时间(毫秒),默认为 30000(30 秒)
      • waitUntil :指定导航何时被视为完成,选项:'load'、'domcontentloaded'、'networkidle'、'commit',默认为'load'
      • extractContent :是否智能提取主要内容,默认为 true
      • maxLength :返回内容的最大长度(以字符为单位),默认无限制
      • returnHtml :是否返回 HTML 内容而不是 Markdown,默认为 false
      • waitForNavigation :是否在初始页面加载后等待额外的导航(对于具有反机器人验证的网站很有用),默认值为 false
      • navigationTimeout :等待额外导航的最长时间(以毫秒为单位),默认值为 10000(10 秒)
      • disableMedia :是否禁用媒体资源(图片、样式表、字体、媒体),默认为 true
      • debug :是否启用调试模式(显示浏览器窗口),如果指定,则覆盖 --debug 命令行标志
  • fetch_urls - 并行从多个 URL 批量检索网页内容
    • 使用多标签并行获取来提高性能
    • 返回网页之间有明显区分的组合结果
    • 支持以下参数:
      • urls :要获取的 URL 数组(必需参数)
      • 其他参数与fetch_url相同

尖端

处理特殊网站场景

应对反爬虫机制

  • 等待完成加载:对于使用 CAPTCHA、重定向或其他验证机制的网站,请在提示中包含:
    Please wait for the page to fully load
    这将使用waitForNavigation: true参数。
  • 增加超时时间:对于加载缓慢的网站:
    Please set the page loading timeout to 60 seconds
    这会相应地调整timeoutnavigationTimeout参数。

内容检索调整

  • 保留原始 HTML 结构:当内容提取可能失败时:
    Please preserve the original HTML content
    设置extractContent: falsereturnHtml: true
  • 获取完整的页面内容:当提取的内容太有限时:
    Please fetch the complete webpage content instead of just the main content
    设置extractContent: false
  • 以 HTML 格式返回内容:当需要 HTML 格式而不是默认的 Markdown 格式时:
    Please return the content in HTML format
    设置returnHtml: true

调试和身份验证

启用调试模式

  • 动态调试激活:在特定的获取操作期间显示浏览器窗口:
    Please enable debug mode for this fetch operation
    即使服务器启动时没有使用--debug标志,也会设置debug: true
  • 手动登录:使用您自己的凭据登录:
    Please run in debug mode so I can manually log in to the website
    设置debug: true或使用--debug标志,保持浏览器窗口打开以进行手动登录。
  • 与调试浏览器交互:启用调试模式后:
    1. 浏览器窗口保持打开状态
    2. 您可以使用您的凭证手动登录网站
    3. 登录完成后,将通过您的身份验证会话获取内容
  • 为特定请求启用调试:即使服务器已经在运行,您也可以为特定请求启用调试模式:
    Please enable debug mode for this authentication step
    仅为此特定请求设置debug: true ,打开浏览器窗口进行手动登录。

发展

安装依赖项

npm install

安装 Playwright 浏览器

安装 Playwright 所需的浏览器:

npm run install-browser

构建服务器

npm run build

调试

使用 MCP Inspector 进行调试:

npm run inspector

您还可以启用可见浏览器模式进行调试:

node build/index.js --debug

相关项目

  • g-search-mcp :一款强大的 Google 搜索 MCP 服务器,支持同时使用多个关键词进行并行搜索。非常适合批量搜索和数据收集。

执照

根据MIT 许可证授权

You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

使用 Playwright 无头浏览器检索网页内容的 MCP 服务器,能够提取主要内容并转换为 Markdown 格式。

  1. Advantages
    1. Quick Start
      1. Debug Mode
    2. Configuration MCP
      1. Features
        1. Tips
          1. Handling Special Website Scenarios
          2. Debugging and Authentication
        2. Development
          1. Install Dependencies
          2. Install Playwright Browser
          3. Build the Server
        3. Debugging
          1. Related Projects
            1. License
              ID: o6qc1j6a1z