使用说明
web获取mcp
MCP服务器,将网页作为干净的、LLM就绪的markdown获取。用途 阅读器名称 对于大多数网站,以及具有隐身模式的无头浏览器,用于具有攻击性机器人检测的网站。
工具
| 工具 | 说明 |
|---|---|
fetch_page |
获取支持分页的单个URL |
fetch_pages |
同时获取最多10个URL |
先决条件
- 码头工人 --对于Docker安装方法(推荐,不需要其他依赖项)
- Node.js (v18+)——用于本地安装
- Chromium的系统库 --仅当您想使用木偶机和
STEALTH_HOSTS.
设置
选项1:Docker
添加到MCP客户端配置中:
{
"mcpServers": {
"web-fetch": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "STEALTH_HOSTS=example.com",
"-e", "DEBUG=1",
"parsam123/web-fetch-mcp"
]
}
}
}
选项2:克隆和构建
git clone https://github.com/parsam97/web-fetch-mcp.git
cd web-fetch-mcp
npm install
npm run build
然后添加到您的MCP客户端配置中:
{
"mcpServers": {
"web-fetch": {
"command": "node",
"args": ["/path/to/web-fetch-mcp/dist/index.js"],
"env": {
"STEALTH_HOSTS": "example.com",
"DEBUG": "1"
}
}
}
}
特性
- 阅读器名称 用于通过JS渲染快速获取
- Puppeteer+隐形插件 对于受bot保护的站点(通过配置
STEALTH_HOSTS任何人) - Mozilla可读性+关闭 用于清洁提取标记
- 内存缓存 (30分钟TTL)-重复获取是即时的
- 并发限制 --盖住Puppeter选项卡以防止OOM
- 使用指数回退重试 429/5xx/网络错误
- robots.txt合规性
- URL规范化 --删除跟踪参数,以便等效URL共享缓存
配置
| 变量 | 描述 |
|---|---|
STEALTH_HOSTS |
需要隐形无头浏览器的逗号分隔主机名 |
FETCH_PLUGINS |
逗号分隔的模块说明符(绝对路径或已安装的包名)作为自定义获取策略加载——请参阅 插件 |
DEBUG |
设置为 1 启用stderr的调试日志记录 |
当由于机器人检测导致获取失败时,错误消息将建议将主机名添加到 STEALTH_HOSTS.
请确保您指示您的代理人将此信息转达给您。如果您正在配置子代理以使用此mcp服务器,请指示 两者 子代理和您的主代理(例如 CLAUDE.md)将此信息转发给您。
子代理指令示例:
- **CRITICAL — Bot detection errors:** If ANY fetch returns an error mentioning
`STEALTH_HOSTS`, you must **start your entire response** with a clearly
separated, prominent block like this:
```
⚠️ ACTION REQUIRED: MCP Server Configuration Change Needed
[hostname] blocked the fetch due to bot detection.
To fix this permanently:
1. Open your MCP server config
2. Add "STEALTH_HOSTS": "[hostname]" to the "env" section of the web-fetch server
3. Restart the MCP server
Until this is fixed, documentation from [hostname] cannot be fetched.
```
This block MUST appear at the very top of your response — before any
documentation content. Do NOT bury it at the end, in a footnote, or as a
"Note" section. The parent agent summarizes your response and will drop
anything that looks like a minor aside. Making it the first thing ensures
it gets relayed to the user.
Do NOT silently skip the failed URL, retry it, or try workarounds.
代理说明示例:
# User-level instructions
## MCP STEALTH_HOSTS warnings
When any subagent response mentions `STEALTH_HOSTS` or bot detection blocking a fetch,
you MUST relay this to the user. This is a configuration issue that only the user can fix.
Include the blocked hostname and tell them to add it to `STEALTH_HOSTS` in their MCP server
config. Do not drop or summarize away this information.
插件
拾荒者与宿主无关。当一个特定的URL系列不能被一般性地提取时(例如,仅通过私有JSON API提供的内容),该知识属于 插件,不在这个代码库中。
插件是一个独立的、自包含的模块,它导出一系列获取策略处理程序:
export const handlers = [
{
name: "my-handler",
matches(url) {
return /* true if this handler claims the URL */;
},
async fetch(url) {
return { content: "...markdown..." };
},
},
];
点 FETCH_PLUGINS 在一个或多个模块上(逗号分隔的绝对路径或已安装的包名称):
"env": { "FETCH_PLUGINS": "/plugins/my-plugin.js" }
行为:
- 对于每个fetch,其第一个处理程序
matches(url)return true处理它;否则,通用的Jina/隐形路径将运行。处理程序优先于STEALTH_HOSTS. - 核心仍然拥有缓存、robots.txt、大小上限和分页——插件只提供内容。
- 如果处理程序
fetch抛出时,错误会传播(不会无声地掉入通用路径)。 - 无法加载或没有的插件
handlers导出记录到stderr并跳过;服务器仍在运行。
通过Docker运行?模块必须存在于容器内——挂载它(-v /host/plugins:/plugins -e FETCH_PLUGINS=/plugins/my-plugin.js).
示例插件
web fetch mcp salesforce开发人员文档插件 这是一个工作示例。它教导提取器阅读developer.salesforce.com文档:通过salesforce自己的文档JSON API呈现的传统Atlas页面(客户端呈现在同意外壳后面),以及通过本地文档呈现的现代文档页面 .md 变体。特定于主机的逻辑,保存在自己的仓库中,而不是核心中。
发展
npm run dev
npm test
npm run test:integration
DEBUG=1 npm run dev
