网页抓取服务器

Scrapidou是一个模块化的MCP服务器,用于网页抓取和URL内容获取,支持多种内容格式提取和问题检测。

  • by Shyzkanza
  • TypeScript
  • 混合部署
  • 1 星标
  • 更新于
在 GitHub 查看 Shyzkanza/mcp-fetch-url

使用说明

🕷️ Scrapidou-用于ChatGPT的Web抓取服务器

Scrapidou是一个干净的模块化MCP服务器,用于网络抓取和URL获取。


⚠️ 免责声明

这个项目是独立的、非官方的。

  • ❌ 无关联 提供任何刮擦服务
  • ✅ 教育和实用目的项目
  • ✅ 尊重robots.txt和速率限制
  • ⚠️ 负责任地使用 -遵守网站服务条款

🎯 这是怎么一回事?

此应用程序允许 ChatGPT 和其他MCP客户端使用 干净的模块化架构.

✨ 特性

  • 🌐 URL获取 -使用正确的标题和重定向处理从任何URL检索内容
  • 📄 灵活提取 -控制内容格式(text, html, markdown, both),尺寸(maxContentLength)、问题检测和链接提取独立进行
  • 📝 文本内容提取 -用于LLM消费的无HTML标签的干净文本提取
  • 📑 Markdown提取 -带有标题、链接、代码块和强调的结构化Markdown-针对LLM分析进行了优化
  • 🎨 HTML内容提取 -完整的HTML内容保存 full 模式(格式、图像、引用)
  • 🔍 问题检测 -自动检测付费墙、登录要求和部分内容
  • 🔗 相关链接 -在过滤广告和导航时提取相关链接(另请参阅相关文章)
  • 🧭 导航链接 -提取文档网站的侧边栏/菜单链接(可选)
  • 📊 元数据抽取 -摘录标题、描述、作者和出版日期
  • 🏗️ 模块化架构 -干净的关注点分离,可重复用于未来的项目
  • 🔌 双模式 -适用于ChatGPT(流式HTTP)和IDE(stdio)

💬 使用示例

在ChatGPT中,只需问:

“从以下位置获取内容https://example.com"

或者:

“从以下内容中提取主要内容https://blog.example.com/article限制为500个字符”

或者:

“从获取完整的HTML内容https://docs.example.com/page"

ChatGPT将使用MCP服务器根据所选参数获取、提取和返回内容:

  • 内容格式:从中选择 text (纯文本,默认), markdown (结构化Markdown), html (完整HTML),或 both (文本+HTML)
  • 内容大小控制:使用 maxContentLength 快速映射(500-1000个字符)或离开 undefined 用于完整分析
  • 问题检测:控制 detectIssues 参数(默认值: true)
  • 链接提取:配置 extractRelatedLinks 和 extractNavigationLinks 独立地

📖 用例和内容提取

提取了什么?

该工具提取三种类型的内容,您可以选择返回哪一种:

  1. contentText (文本内容)

    • 它是什么:从页面主要内容中提取清晰易读的文本
    • 如何提取:
      • 使用Mozilla可读性算法识别主要内容
      • 删除HTML标签、脚本、样式
      • 清理空白和格式
      • 保留带有标题标记的段落结构(#, ##等等)
    • 可用时间:: contentFormat: 'text' 或 contentFormat: 'both' (默认值: 'text')
    • 用例:非常适合LLM消费、总结、分析
    • 无尺寸限制:完整内容将在中返回 structuredContent.contentText
  2. contentMarkdown (Markdown内容)

    • 它是什么:带有标题、链接、代码块和强调的结构化Markdown
    • 如何提取:
      • 使用Mozilla可读性提取主要内容
      • 通过带有ATX标题、围栏代码块、内联链接的Turndown转换为Markdown
      • 保留代码块语言(例如。 ```python)
      • 删除图像(对LLM文本分析无效)
    • 可用时间:: contentFormat: 'markdown'
    • 用例:最适合LLM分析-保留结构、链接和代码格式
    • 无尺寸限制:完整内容将在中返回 structuredContent.contentMarkdown
  3. contentHTML (HTML内容)

    • 它是什么:主要内容区域的完整HTML(保留格式、结构)
    • 如何提取:
      • 使用Mozilla可读性提取主要内容HTML
      • 保留HTML结构、图像、链接和格式
      • 删除导航、页眉、页脚、广告
    • 可用时间:: contentFormat: 'html' 或 contentFormat: 'both'
    • 用例:技术分析、保留格式、高级处理
    • 尺寸控制:使用 maxContentLength 限制提取(默认:无限制-完整HTML)
    • 备注:何时 contentFormat 是 'html' 或 'both',该工具在内部自动提取HTML

响应结构

所有回复均遵循以下结构:

{
  // 1. Summary (markdown text visible to user and model)
  content: [{
    type: 'text',
    text: '📄 Content extracted from: https://example.com\n...'
  }],
  
  // 2. Structured data (accessible by ChatGPT)
  structuredContent: {
    type: 'webpage',
    url: 'https://example.com',
    contentFormat: 'text', // 'text' | 'markdown' | 'html' | 'both'
    maxContentLength: undefined, // Optional: limit content size (undefined = no limit)
    metadata: { title, description, author, publishedDate },
    contentText: '...', // Text content (truncated if maxContentLength specified)
    contentMarkdown: '...', // Markdown content (if contentFormat: 'markdown')
    contentHTML: '...', // HTML content (if contentFormat: 'html' or 'both')
    issues: [{ type: 'paywall', message: '...' }], // Empty array if detectIssues: false
    relatedLinks: [{ url, text, type }], // All links (no limit)
    navigationLinks: [{ url, text, level }], // All links (no limit)
    contentTextLength: 1234, // Original full length
    contentTextExtractedLength: 1234, // Actual extracted length
    contentTextTruncated: false, // true if truncated
    contentHTMLLength: 5678, // Original full length (if HTML present)
    contentHTMLExtractedLength: 5678, // Actual extracted length (if HTML present)
    contentHTMLTruncated: false // true if truncated (if HTML present)
  }
}

决策矩阵

使用案例 contentFormat maxContentLength detectIssues extractRelatedLinks extractNavigationLinks
快速映射/摘要 text 500-1000 false false false
文章/博客文章 text undefined (满) true (默认) true (默认) false
LLM深度分析 markdown undefined (满) true (默认) true (默认) false
维基百科页面 text undefined (满) true (默认) true (默认) false
文件网站 markdown undefined (满) true (默认) false true
需要HTML内容 html undefined (满) true (默认) true (默认) true (如果需要)
需要文本和HTML both undefined (满) true (默认) true (默认) true (如果需要)
技术分析 html undefined (满) true (默认) false true
预览/快速阅读 text 2000-5000 true (默认) true (默认) false

备注:

  • 'markdown' 是LLM分析的最佳格式,它保留了结构、链接和代码块。
  • 当 contentFormat 是 'html' 或 'both',该工具会自动在内部提取HTML。
  • 使用 maxContentLength 用于快速映射/摘要(500-1000个字符)或预览(2000-5000个字符)。离开 undefined 进行完整分析。
  • 集 detectIssues: false 当您知道内容可以自由访问时,可以更快地提取。

参数

contentFormat -内容类型

控制返回的内容类型:

  • contentFormat: 'text' (默认)

    • 退货 structuredContent.contentText 包含文本内容
    • 非常适合法学硕士分析、总结、一般理解
    • 在所有模式下都可用
  • contentFormat: 'markdown'

    • 退货 structuredContent.contentMarkdown 使用结构化Markdown
    • ATX标题(##),围栏代码块(```),内联链接([text](url))
    • 保留代码块语言、粗体、斜体、列表
    • 最适合LLM分析-结构最丰富,同时保持基于文本
  • contentFormat: 'html'

    • 退货 structuredContent.contentHTML 包含HTML内容
    • 在内部自动提取HTML
    • 保留格式、结构、图像和链接
    • 最适合技术分析,保留文档结构
  • contentFormat: 'both'

    • 返回两者 structuredContent.contentText 和 structuredContent.contentHTML
    • 在内部自动提取HTML
    • 当您需要两种格式用于不同目的时使用

maxContentLength -内容大小控制

控制要提取的最大字符数(适用于文本和HTML):

  • maxContentLength: undefined (默认-无限制)

    • 提取完整内容,不进行任何截断
    • 用于完整分析、深入理解或需要所有信息时
    • 最适合进行全面的内容分析
  • maxContentLength: 500-1000

    • 快速映射或简短摘要
    • 用于快速浏览内容
    • 适用于预览或只需要开始的时候
  • maxContentLength: 2000-5000

    • 详细预览或扩展摘要
    • 当您需要更多上下文而不是完整内容时使用
    • 完整性和令牌使用之间的良好平衡

重要:如果长度超过指定限制,则内容将被截断。答复包括:

  • contentTextTruncated / contentHTMLTruncated: true 如果内容被截断
  • contentTextLength / contentHTMLLength:原始全长
  • contentTextExtractedLength / contentHTMLExtractedLength:实际提取长度

detectIssues -问题检测

控制是否检测页面上的问题:

  • detectIssues: true (默认)

    • 分析页面以检测付费墙、登录要求或部分内容
    • 当您想知道是否存在访问问题时,用于一般用例
    • 增加少量处理开销
  • detectIssues: false

    • 跳过问题检测以加快提取速度
    • 当您知道内容可以自由访问时使用
    • 最适合快速映射或不需要问题信息时

内容提取详细信息

文本内容(contentText):

  • 使用Mozilla可读性算法提取
  • 删除HTML标签、脚本、样式、广告
  • 保留带有标题标记的段落结构(#, ##等等)
  • 清理空白和格式
  • 可用时间:: contentFormat: 'text' 或 'both'
  • 尺寸控制:使用 maxContentLength 限制提取(默认值:无限制-完整内容)

Markdown内容(contentMarkdown):

  • 使用Mozilla可读性+调低转换提取
  • ATX标题、带语言检测的围栏代码块、内联链接
  • 大胆(**text**),斜体(*text*),项目列表(- item)
  • 删除图像(对LLM文本分析无效)
  • 可用时间:: contentFormat: 'markdown'
  • 尺寸控制:使用 maxContentLength 限制提取(默认值:无限制)

HTML内容(contentHTML):

  • 使用Mozilla可读性算法提取
  • 保留HTML结构、图像、链接和格式
  • 删除导航、页眉、页脚、广告
  • 可用时间:: contentFormat: 'html' 或 'both'
  • 尺寸控制:使用 maxContentLength 限制提取(默认:无限制-完整HTML)
  • 自动模式:何时 contentFormat 是 'html' 或 'both',该工具使用 mode: 'full' 内部地

重要说明

  • 无小部件:此工具不使用小部件,因此所有内容都可以在中直接访问 structuredContent
  • 灵活的尺寸控制:使用 maxContentLength 快速映射(500-1000个字符)或离开 undefined 用于完整分析
  • 包含所有链接:相关链接和导航链接全部返回(无限制)
  • 不 _meta 复杂性:由于没有小部件,我们不需要复杂的 _meta 结构
  • 截断指示器:何时 maxContentLength 如果使用,响应包括 contentTextTruncated/contentHTMLTruncated 标志和长度信息

🏗️ 架构:MCP服务器

什么是MCP服务器?

MCP(模型上下文协议) 服务器允许您通过以下方式扩展ChatGPT和其他LLM:

  • 定制工具 (调用外部API)
  • 实时数据 (最新信息)

它是如何工作的?

┌─────────────┐         ┌──────────────┐         ┌──────────────┐
│   ChatGPT   │ ◄─────► │  MCP Server  │ ◄─────► │  Target URL  │
│             │  HTTP   │  (Node.js)   │  HTTP   │              │
└─────────────┘         └──────────────┘         └──────────────┘
  1. ChatGPT 通过以下方式连接 可流式传输的HTTP 到 /mcp (获取/发布)
  2. MCP服务器 从目标URL获取数据
  3. 结果 返回到ChatGPT

MCP协议

MCP(模型上下文协议)是Anthropic创建的一个开放标准,允许LLM安全地访问外部数据和工具。它由以下人员使用:

  • ChatGPT(通过MCP连接器)
  • 克劳德桌面版
  • 光标
  • 其他MCP客户端

🚀 快速开始

与光标/克劳德桌面/扭曲一起使用

你有 两种选择 要使用Scrapidou:

选项1:本地安装(建议用于开发)

安装本地运行的npm客户端:

{
  "mcpServers": {
    "mcp-scrapidou": {
      "command": "npx",
      "args": ["-y", "@shyzus/mcp-scrapidou"]
    }
  }
}

选项2:托管服务器(建议用于生产)

使用我们VPS上托管的生产服务器:

{
  "mcpServers": {
    "mcp-scrapidou": {
      "url": "https://scrapidou.rankorr.red/mcp"
    }
  }
}

配置文件位置:

  • 光标: ~/.cursor/mcp.json (macOS/Linux)或 %APPDATA%\Cursor\mcp.json (Windows)
  • 克劳德桌面版: ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
  • 扭曲:在扭曲AI设置中

选择哪个选项?

  • 本地(npx):更适合开发,始终使用最新版本,需要Node.js
  • 托管(URL):无需安装,始终可用,使用稳定的生产版本

与ChatGPT一起使用

生产服务器可用,随时可用!

服务器URL: https://scrapidou.rankorr.red/mcp

ChatGPT配置

  1. 拥有一个订阅的ChatGPT帐户 (ChatGPT Plus、团队或企业)
  2. 在浏览器中打开ChatGPT → Go to 设置 (⚙️)
  3. 转到“应用程序和连接器”
  4. 启用开发人员模式:
    • 在 “高级设置”,启用 开发者模式
    • 回去
  5. 创建新应用程序:
    • 这 “创建” 按钮现在出现在右上角
    • 点击它
    • 填写表格:
      • 名字:“Scrapidou”(或其他名称)
      • 图像:添加图标/图像(可选)
      • 服务器URL: https://scrapidou.rankorr.red/mcp
      • 备注:服务器使用 可流式传输的HTTP 运输(现代MCP标准)
      • 认证:选择 “无”
    • 点击 “创建”
  6. 应用程序现在可用 在ChatGPT中

对于开发人员-本地安装

# 1. Clone the project
git clone https://github.com/Shyzkanza/mcp-fetch-url.git
cd mcp-fetch-url

# 2. Install dependencies
npm install

# 3. Build
npm run build

# 4. Use locally
npx @modelcontextprotocol/inspector node dist/index.js

🧪 测试

# Run tests
npm test

# Watch mode
npm run test:watch

7个套件中的88个测试:

  • errors.test.ts --错误类别、格式化、网络检测(17项测试)
  • urlUtils.test.ts --URL规范化、链接文本提取(14项测试)
  • issueDetector.test.ts --付费墙、登录、部分内容检测(16次测试)
  • linkExtractor.test.ts --相关链接提取和过滤(13个测试)
  • navigationExtractor.test.ts --侧边栏/菜单导航链接(12个测试)
  • contentExtractor.test.ts --可读性提取+回退(9次测试)
  • markdownExtractor.test.ts --HTML到Markdown的转换(7个测试)

📂 项目结构

mcp-fetch-url/
├── src/
│   ├── config.ts              # Configuration centralisée
│   ├── types.ts               # Types TypeScript partagés
│   ├── client/
│   │   └── httpClient.ts      # HTTP client avec headers, redirections, timeout
│   ├── tools/
│   │   ├── fetchUrl.ts        # Tool MCP: fetch_url (logic)
│   │   └── fetchUrlSchema.ts  # Tool schema (shared between stdio/http)
│   ├── servers/
│   │   ├── stdio.ts           # Serveur stdio (IDEs)
│   │   └── http.ts            # Serveur Streamable HTTP (ChatGPT)
│   ├── utils/
│   │   ├── errors.ts          # Gestion erreurs centralisée
│   │   ├── urlUtils.ts        # URL normalization, link text extraction
│   │   ├── contentExtractor.ts # Extraction contenu (Readability + fallback)
│   │   ├── markdownExtractor.ts # Conversion HTML → Markdown (Turndown)
│   │   ├── issueDetector.ts   # Détection paywall, login, contenu partiel
│   │   ├── linkExtractor.ts   # Extraction liens pertinents (related links)
│   │   ├── navigationExtractor.ts # Extraction liens navigation (sidebar/menu)
│   │   └── __tests__/         # Unit tests (Vitest)
│   ├── index.ts               # Entry point stdio
│   ├── http-server.ts         # Entry point HTTP
│   └── http-client.ts         # Client npm
├── dist/                      # Compiled code (generated)
├── Dockerfile                 # Multi-stage Docker image
├── docker-compose.yml         # Docker Swarm stack with Traefik labels
├── .github/workflows/
│   ├── ci.yml                 # CI: tests + typecheck on push/PR
│   └── release.yml            # Release: test → Docker → deploy → npm
├── .nvmrc                     # Node version (20)
├── package.json               # Server dependencies
├── tsconfig.json              # TypeScript config
└── README.md                  # This file

🛠️ 可用命令

📖 全部文件: COMMANDS.md

快速参考

# 🌟 Recommended for ChatGPT development (2 terminals)
npm run tunnel           # Terminal 1: ngrok (keep running)
npm run dev              # Terminal 2: Dev server with hot-reload

# Alternative: All-in-one
npm run dev:tunnel       # Dev + ngrok in parallel

# Testing
npm test                 # Run unit tests
npm run test:watch       # Run tests in watch mode
npm run inspect          # Launch MCP Inspector
npm run health           # Health check

# Build & Production
npm run build            # Compile TypeScript
npm run rebuild          # Clean + Build
npm run build:start      # Build then start

# Utilities
npm run kill             # Kill process on port 3000
npm run kill:tunnel      # Kill ngrok

光标命令

可通过 Cmd+Shift+P:

  • dev-server -热重载开发(推荐)
  • tunnel-only -启动ngrok(继续运行)
  • mcp-inspector -启动MCP检查器
  • build / rebuild / clean
  • kill-server / kill-tunnel

看 COMMANDS.md 查看完整列表。


🔧 高级配置

环境变量

创建一个 .env 文件:

PORT=3000                          # HTTP server port
NODE_ENV=production                # Environment
CORS_ORIGIN=*                      # CORS origin (default: * in dev, https://chatgpt.com in prod)

🏗️ 建筑细部

该项目作为 模板/基础 对于未来具有干净、模块化架构的MCP服务器:

关注点分离

  • config.ts:环境变量、常量、验证
  • types.ts:共享TypeScript接口
  • client/httpClient.ts:HTTP客户端抽象(获取、标头、重定向、超时)
  • tools/fetchUrl.ts:业务逻辑(验证、提取编排)
  • tools/fetchUrlSchema.ts:stdio和HTTP服务器之间共享的工具架构
  • utils/urlUtils.ts:URL规范化、链接文本提取(共享实用程序)
  • utils/contentExtractor.ts:内容提取(可读性+回退)
  • utils/markdownExtractor.ts:HTML到Markdown转换(关闭)
  • utils/issueDetector.ts:问题检测(付费墙、登录、部分内容)
  • utils/linkExtractor.ts:相关链接提取和过滤
  • utils/navigationExtractor.ts:侧边栏/菜单导航链接提取
  • servers/:MCP实现(stdio/Streamable HTTP),重用工具
  • utils/errors.ts:自定义错误类、格式

看 内容.md 获取详细的架构文档。


📚 资源和文件

项目文件

正式文件

社区


🐛 调试与故障排除

服务器无法启动

# Check that Node.js is installed (requires Node 20+)
node --version  # Must be 20+

# If using nvm, switch to Node 20
nvm use 20  # or nvm install 20

# Check that dependencies are installed
npm install

# Full rebuild
npm run build

备注:由于依赖关系(jsdom、@mozilla/realready),此项目需要Node.js 20+。使用 .nvmrc 文件或 nvm use 以确保版本正确。

CORS错误

服务器允许开发中的所有源。在生产中,限制 src/servers/http.ts:

res.setHeader('Access-Control-Allow-Origin', 'https://chatgpt.com');

🚀 将此项目用作模板

这个项目是 完整模板 用于创建具有干净架构的自己的MCP服务器。

要创建自己的MCP服务器:

  1. 复制此项目
  2. 实施您的工具 在 src/tools/
  3. 自定义配置 在 src/config.ts
  4. 部署!

📝 许可证

麻省理工学院-免费用于您的个人或商业项目。


🙏 学分和归属


📞 支持

如有任何疑问:

  • 📖 检查 MCP文件
  • 💬 在GitHub上打开一个问题

享受MCP服务器的乐趣! 🕷️✨