Back to MCP directory
publicPublicdnsLocal runtime

mcp-node-fetch

基于Node.js undici库的网页内容获取MCP服务

article

README

🚀 MCP 节点抓取

MCP 节点抓取是一个基于 Node.js 的 MCP 服务器,借助 undici 库实现网络内容抓取。它能使用多种 HTTP 方法从任意 URL 获取内容,支持请求头和请求正文,可返回多种格式的内容,还能灵活处理错误情况,具有可配置超时时间和重定向行为等优势。

✨ 主要特性

  • 使用各种 HTTP 方法从任何 URL 获取内容。
  • 支持请求头和请求正文。
  • 返回多种格式的内容(文本、JSON、二进制、HTML 片段)。
  • 灵活处理错误情况。
  • 可配置超时时间和重定向行为。

📦 安装指南

文档未提供安装步骤,暂不展示。

💻 使用示例

基础用法

fetch-url

// 从指定的 URL 抓取内容并返回结果
const { fetchUrl } = require('./path/to/mcp-server');

const result = await fetchUrl({
  url: 'https://example.com',
  method: 'GET',
  headers: { 'Content-Type': 'application/json' },
  timeout: 5000,
  responseType: 'text'
});
console.log(result);

extract-html-fragment

// 使用 CSS 选择器从网页中提取特定的 HTML 内容
const { extractHtmlFragment } = require('./path/to/mcp-server');

const fragment = await extractHtmlFragment({
  url: 'https://example.com',
  selector: 'div.content',
  anchorId: 'section-1',
  method: 'GET',
  timeout: 5000
});
console.log(fragment);

check-status

// 检查指定 URL 是否可达
const { checkStatus } = require('./path/to/mcp-server');

const isReachable = await checkStatus({
  url: 'https://example.com',
  timeout: 5000
});
console.log(isReachable);

高级用法

文档未提供高级用法示例,暂不展示。

📚 详细文档

MCP 工具集

此服务器提供了以下 MCP 工具:

fetch-url

从指定的 URL 抓取内容并返回结果。

| 参数 | 详情 | |------|------| | url | 字符串,必填,要抓取的 URL 地址 | | method | 字符串,可选,HTTP 方法,默认为 "GET" | | headers | 对象,可选,请求头信息 | | body | 字符串,可选,POST/PUT 请求的正文内容 | | timeout | 数字,可选,请求超时时间(单位:毫秒) | | responseType | 字符串,可选,指定响应内容的解析方式 ("text", "json", "binary", "html-fragment") | | fragmentSelector | 字符串,可选,当 responseType 为 "html-fragment" 时,用于提取特定 HTML 片段的 CSS 选择器 | | followRedirects | 布尔值,可选,是否自动跳转重定向,默认为 true |

extract-html-fragment

使用 CSS 选择器从网页中提取特定的 HTML 内容,并可根据需要定位到具体的锚点。

| 参数 | 详情 | |------|------| | url | 字符串,必填,要抓取的 URL 地址 | | selector | 字符串,必填,用于提取 HTML 片段的 CSS 选择器 | | anchorId | 字符串,可选,可选的锚点 ID,用于定位特定内容 | | method | 字符串,可选,HTTP 方法,默认为 "GET" | | headers | 对象,可选,请求头信息 | | body | 字符串,可选,POST 请求的正文内容 | | timeout | 数字,可选,请求超时时间(单位:毫秒) | | followRedirects | 布尔值,可选,是否自动跳转重定向,默认为 true |

check-status

检查指定 URL 是否可达,而不必下载完整内容。

| 参数 | 详情 | |------|------| | url | 字符串,必填,要检查的 URL 地址 | | timeout | 数字,可选,请求超时时间(单位:毫秒) |

与桌面版 Claude 配置

要在桌面版 Claude 中使用,请在 claude_desktop_config.json 文件中添加以下内容:

{
  "mcpServers": {
    "node-fetch": {
      "command": "node",
      "args": ["dist/index.js"]
    }
  }
}

🔧 技术细节

文档未提供技术实现细节,暂不展示。

📄 许可证

本项目采用 MIT 许可证。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client