MCP 节点抓取是一个基于 Node.js 的 MCP 服务器,借助 undici 库实现网络内容抓取。它能使用多种 HTTP 方法从任意 URL 获取内容,支持请求头和请求正文,可返回多种格式的内容,还能灵活处理错误情况,具有可配置超时时间和重定向行为等优势。
文档未提供安装步骤,暂不展示。
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 工具:
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_desktop_config.json 文件中添加以下内容:
{
"mcpServers": {
"node-fetch": {
"command": "node",
"args": ["dist/index.js"]
}
}
}
文档未提供技术实现细节,暂不展示。
本项目采用 MIT 许可证。