Skip to main content
Glama
Perufitlife

multi-scraper-mcp

by Perufitlife

作为 Apify Actor 的 MCP 服务器 —— 一个可运行的参考实现

这是 renzomacar/multi-scraper-mcp 背后的源代码,它是一个以 Apify Actor 的 Standby 模式运行的 MCP 服务器,向 Claude、Cursor 和 Windsurf 等 AI 客户端提供 16 个线索生成和网页抓取工具。

它作为参考发布,因为有趣的部分不是工具列表,而是三个传输层 bug——它们让真实客户端无法连接,而每次运行却都报告 SUCCEEDED

此代码修复的三个故障

1. 过期的会话 ID 让客户端永远卡住

会话保存在内存中的 Map 里,但 Standby 运行并不是一个长期存活的进程——Apify 会回收它。客户端在周二带着周一的 Mcp-Session-Id 重新连接时,会碰到一个从未听说过该 ID 的进程。

服务器过去会返回 400规范 明确规定响应必须是 404

服务器可以随时终止会话,之后它必须对包含该会话 ID 的请求以 HTTP 404 Not Found 响应。

当客户端收到 HTTP 404 [...] 时,它必须通过发送一个不带会话 ID 的新 InitializeRequest 来开始新会话。

客户端的恢复路径与状态码绑定。400 会移除其自我修复的能力。参见 src/main.js 中的 sessionGone()

2. Accept 头在我们的任何代码运行之前就拒绝了客户端

规范要求客户端发送 Accept: application/json, text/event-stream。一些真实客户端只发送其中一个,或者什么都不发送,传输层会在请求到达处理器之前返回 406——因此日志中没有任何记录,控制台中也没有失败运行。

normalizeAccept() 无论如何都会接受它们。问题在于:传输层从 req.rawHeaders 读取该头,因此仅修改 req.headers 不会起任何作用。

3. 一个慢工具在工作进行中丢掉了连接

这些工具包装了需要一到三分钟的抓取器。如果线路上没有字节流动,Standby 网关就会断开连接。修复方法是每 10 秒流式发送一条 notifications/message,并在 finally 中清除定时器,这样提前的错误返回就不会泄漏定时器。

Related MCP server: ZapFetch MCP Server

诚实计费

Actor.charge 位于实际返回数据的路径上,在数据到手之后——而不是在请求处理器的开头。在数据到达时计费意味着为失败计费。

文件结构

文件

内容

src/main.js

Actor 初始化、Express 应用、Streamable HTTP + 旧版 SSE 传输、三个修复

src/tools.js

工具注册表:名称、描述、输入模式、目标 Actor

.actor/

Actor 定义、输入和输出模式

运行

npm install
npm start

然后将 MCP 客户端指向 http://localhost:4321/mcp。在 Apify 平台上,Standby URL 是 https://USERNAME--ACTOR-NAME.apify.actor/mcp——注意 USERNAME-- 前缀;发布不带此前缀的 URL 会让每次复制粘贴都失败。

一个值得运行的检查

六个请求,每一个都是一个已发布的 bug:

  1. 使用正确的 Accept 头进行握手 → 200

  2. 使用 Accept: application/json 进行握手 → 200(原为 406)

  3. 不带 Accept 头进行握手 → 200(原为 406)

  4. 使用未知会话 ID 调用 tools/list → 404(原为 400)

  5. 在仍持有过期 ID 时调用 initialize → 200(原为 400)

  6. 在活动会话上调用 tools/list → 200,返回完整工具列表

第 2 到第 5 项在生产环境中全部是坏的,而 Actor 却报告运行健康。

许可证

MIT

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    Not graded
    maintenance
    Exposes over 19,000 Apify Actors as MCP tools for web scraping, data extraction, and OSINT automation. It enables AI agents to dynamically discover and execute scrapers to collect structured data and crawl web content.
  • A
    license
    A
    quality
    C
    maintenance
    An APAC-native web scraping API for AI agents that provides tools for scraping, crawling, searching, and extracting structured data from websites, directly usable from MCP-compatible clients like Claude Desktop, Cursor, and Windsurf.
    7
    12
    MIT
  • F
    license
    Not graded
    quality
    C
    maintenance
    Provides 42+ MCP tools for browser automation, web scraping, and search, enabling AI agents like Claude and Cursor to browse, extract data, and run research agents on the live web.
    8

View all related MCP servers

Related MCP Connectors

  • Enable language models to perform advanced AI-powered web scraping with enterprise-grade reliabili…

  • Hosted MCP with 91 agent tools: X, domains, SEO, Maps, Trends, Search, YouTube, TikTok, and more.

  • 100+ MCP tools for AI agents: content metadata, trade intelligence, business-expertise analysis.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Perufitlife/apify-mcp-server-example'

If you have feedback or need assistance with the MCP directory API, please join our Discord server