Zyte获取页面内容MCP服务器
一个模型上下文协议(MCP)服务器,使用 Zyte API非常适合需要阅读和理解网络内容的人工智能助手。
特性
- 🧹 清洁内容提取 -获取主页内容
- 🌐 浏览器渲染 -动态页面的完整JavaScript支持
- ⚡ 可配置提取 -在速度(HTTP)或质量(浏览器渲染)之间进行选择
- 🔒 安全 -API密钥存储在Docker机密中,以非root用户身份运行
- 🐳 基于Docker -通过Docker MCP工具包轻松部署
可用工具
服务器提供了三种工具,每种工具都使用不同的提取方法:
| 工具 | 说明 |
|---|---|
fetch_page_content_from_http_response_body |
从HTTP响应中提取(最快、最便宜) |
fetch_page_content_from_browser_html |
从浏览器中提取视觉特征(最佳质量,默认) |
fetch_page_content_from_browser_html_only |
仅从浏览器HTML中提取(更适合JS繁重的页面) |
提取方法详解
| 方法 | 速度 | 成本 | 用例 | 回报 |
|---|---|---|---|---|
| HTTP响应正文 | 最快 | 最便宜 | 简单的静态页面,快速预览 | pageContent 只有 |
| 浏览器HTML | 中等 | 中等 | 最佳质量,包括视觉特征 | pageContent + browserHtml |
| 仅浏览器HTML | 较慢 | 较高 | JavaScript繁重的页面,SPA | pageContent + browserHtml |
先决条件
- Docker桌面 启用MCP工具包
- Docker MCP CLI插件(
docker mcp命令) - Zyte API密钥 (免费版可用)
安装
步骤1:克隆存储库```bash
git clone https://github.com/YOUR_USERNAME/zyte-fetch-page-content-mcp-server.git
cd zyte-fetch-page-content-mcp-server
### 第二步:构建Docker镜像```bash
docker build -t zyte-fetch-page-content-mcp-server .
步骤3:设置Zyte API密钥```bash
docker mcp secret set ZYTE_API_KEY="your-zyte-api-key-here"
从获取API密钥 Zyte仪表板.
### 步骤4:导入目录```bash
# Create catalogs directory if it doesn't exist
mkdir -p ~/.docker/mcp/catalogs
# Copy catalog file
cp custom.yaml ~/.docker/mcp/catalogs/custom.yaml
# Import the catalog
docker mcp catalog import ~/.docker/mcp/catalogs/custom.yaml
步骤5:添加服务器```bash
docker mcp server add zyte-fetch-page-content
### 步骤6:验证安装```bash
# Check server is listed
docker mcp server ls
# Should show:
# zyte-fetch-page-content - ✓ done - Fetches page content...
# Check tools are available
docker mcp tools ls | grep fetch
步骤7:配置LLM客户端(例如,Claude Desktop)
编辑您的Claude Desktop配置文件:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - 视窗:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
确保它包含:```json
{
"mcpServers": {
"MCP_DOCKER": {
"command": "docker",
"args": ["mcp", "gateway", "run"]
}
}
}
### 步骤8:重新启动克劳德桌面
完全退出克劳德桌面(Cmd+Q/Ctrl+Q)并重新打开。
## 用法
安装后,您可以要求Claude使用这些工具:
### 基本用法(最佳质量)```
Use fetch_page_content_from_browser_html to get content from https://example.com
快速提取(静态页面)```
Use fetch_page_content_from_http_response_body to quickly get content from https://example.com
### JavaScript重度页面```
Use fetch_page_content_from_browser_html_only to extract content from https://example.com
刀具参数
所有三个工具都接受一个参数:
url(必填):从中获取内容的URL
例子:```python
fetch_page_content_from_browser_html(url="https://example.com")
## 响应格式
所有工具都从Zyte API返回原始JSON文本。
### HTTP响应正文响应```json
{
"url": "https://example.com",
"statusCode": 200,
"pageContent": {
"itemMain": "Main article content as clean text...",
"itemSecondary": "Sidebar and navigation content..."
}
}
浏览器HTML响应(带视觉功能)```json
{
"url": "https://example.com",
"statusCode": 200,
"browserHtml": "...",
"pageContent": {
"itemMain": "Main article content as clean text...",
"itemSecondary": "Sidebar and navigation content..."
}
}
### 仅浏览器HTML响应```json
{
"url": "https://example.com",
"statusCode": 200,
"browserHtml": "...",
"pageContent": {
"itemMain": "Main article content as clean text...",
"itemSecondary": "Sidebar and navigation content..."
}
}
测试
直接测试Docker镜像```bash
Test that the server starts
echo '{"jsonrpc":"2.0","method":"tools/list","id":1}' | docker run --rm -i -e ZYTE_API_KEY="your-key" zyte-fetch-page-content-mcp-server
### 通过Docker MCP进行测试```bash
# Test HTTP response body extraction
docker mcp tools call fetch_page_content_from_http_response_body url="https://example.com"
# Test browser HTML extraction (best quality)
docker mcp tools call fetch_page_content_from_browser_html url="https://example.com"
# Test browser HTML only extraction
docker mcp tools call fetch_page_content_from_browser_html_only url="https://example.com"
故障排除
在目录中找不到服务器```bash
Reimport the catalog
docker mcp catalog rm custom
docker mcp catalog import ~/.docker/mcp/catalogs/custom.yaml
docker mcp server add zyte-fetch-page-content
或者将其添加到~/.docker/mcp/register.yaml```
registry:
zyte-fetch-page-content:
ref: ""
工具未出现在Claude中
- 验证服务器是否已启用:
docker mcp server ls - 检查工具是否存在:
docker mcp tools ls | grep fetch - 完全重新启动克劳德桌面
API关键问题```bash
Verify secret is set
docker mcp secret ls | grep ZYTE
Reset the secret
docker mcp secret set ZYTE_API_KEY="your-key"
### 配置错误响应
如果您看到此响应:```json
{"error": "ZYTE_API_KEY not configured", "type": "config_error"}
API密钥设置不正确。运行:```bash
docker mcp secret set ZYTE_API_KEY="your-actual-key"
### 超时错误
默认超时为120秒。如果您遇到超时:
- 使用 `fetch_page_content_from_http_response_body` 在简单页面上获得更快的结果
- 考虑到具有大量JavaScript的复杂页面可能需要更长的时间来呈现
## 运作原理
### 请求流```
Claude Desktop
↓
MCP Gateway (Docker)
↓
Zyte MCP Server (this project)
↓
Zyte API (api.zyte.com)
↓
Returns JSON with pageContent
实现细节
每个工具都会向以下对象发出HTTPS POST请求 https://api.zyte.com/v1/extract 与:
- 认证:使用Zyte API密钥进行HTTP基本验证
- 超时:120秒
- 标头:
Content-Type: application/json,Accept-Encoding: gzip - 有效载荷:URL和提取选项
这些工具的不同之处仅在于 pageContentOptions.extractFrom 价值和是否 browserHtml: true 包括在内。
发展
本地开发```bash
Install dependencies
pip install mcp[cli] httpx
Set API key
export ZYTE_API_KEY="your-key"
Run server
python zyte_fetch_page_content_server.py
### 本地测试MCP协议```bash
# List available tools
echo '{"jsonrpc":"2.0","method":"tools/list","id":1}' | python zyte_fetch_page_content_server.py
更改后重建```bash
docker build -t zyte-fetch-page-content-mcp-server .
docker mcp server rm zyte-fetch-page-content
docker mcp server add zyte-fetch-page-content
Restart Claude Desktop
```
安全
- API密钥存储在Docker Desktop机密中(从不存储在代码中)
- 容器以非root用户身份运行
- 未记录敏感数据
- 所有网络请求都使用HTTPS
- 用于API身份验证的HTTP基本身份验证
性能提示
- 用于静态HTML页面:使用
fetch_page_content_from_http_response_body(最快) - 为了获得最佳的提取质量:使用
fetch_page_content_from_browser_html(包括视觉特征) - 对于JavaScript密集的SPA:使用
fetch_page_content_from_browser_html_only - 成本优化:HTTP响应体提取是最便宜的选择
实用链接
- Zyte API文件
- Zyte API定价
- 模型上下文协议
- Docker MCP工具包
