一个生产就绪的 Model Context Protocol (MCP) 服务器,提供与 ScrapeGraph AI API 的无缝集成。此服务器使语言模型能够利用先进的AI驱动的网络爬取功能,并具有企业级可靠性。
.agent/文件夹中在 ScrapeGraph仪表板 注册并获取您的API密钥
npx -y @smithery/cli install @ScrapeGraphAI/scrapegraph-mcp --client claude
询问Claude或Cursor:
就这样!服务器现在可供您的AI助手使用。
该服务器提供了8个企业级工具用于AI驱动的网络爬取:
markdownify将任何网页转换为干净、结构化的Markdown格式。
markdownify(website_url: str)
smartscraper利用AI从任何网页中提取结构化数据,支持无限滚动。
smartscraper(
user_prompt: str,
website_url: str,
number_of_scrolls: int = None,
markdown_only: bool = None
)
searchscraper执行AI驱动的网络搜索,具有结构化、可操作的结果。
searchscraper(
user_prompt: str,
num_results: int = None,
number_of_scrolls: int = None
)
scrape基本爬取端点,用于获取页面内容,可选支持重载JavaScript。
scrape(website_url: str, render_heavy_js: bool = None)
sitemap提取任何网站的站点地图URL和结构。
sitemap(website_url: str)
smartcrawler_initiate启动智能多页网络爬取(异步操作)。
smartcrawler_initiate(
url: str,
prompt: str = None,
extraction_mode: str = "ai",
depth: int = None,
max_pages: int = None,
same_domain_only: bool = None
)
request_id用于轮询smartcrawler_fetch_results从异步爬取操作中检索结果。
smartcrawler_fetch_results(request_id: str)
agentic_scrapper运行高级代理爬取工作流程,具有可定制步骤和结构化输出模式。
agentic_scrapper(
url: str,
user_prompt: str = None,
output_schema: dict = None,
steps: list = None,
ai_extraction: bool = None,
persistent_session: bool = None,
timeout_seconds: float = None
)
要使用此服务器,您需要一个ScrapeGraph API密钥。按照以下步骤获得一个:
使用Smithery进行ScrapeGraph API集成服务器的自动化安装:
npx -y @smithery/cli install @ScrapeGraphAI/scrapegraph-mcp --client claude
更新您的Claude Desktop配置文件(位于Cursor页面右上角),如下所示(记得添加您的API密钥):
{
"mcpServers": {
"@ScrapeGraphAI-scrapegraph-mcp": {
"command": "npx",
"args": [
"-y",
"@smithery/cli@latest",
"run",
"@ScrapeGraphAI/scrapegraph-mcp",
"--config",
"\"{\\\"scrapegraphApiKey\\\":\\\"YOUR-SGAI-API-KEY\\\"}\""
]
}
}
}
配置文件的位置:
在设置中添加ScrapeGraphAI MCP服务器:

要在开发或测试环境中运行MCP服务器,请遵循以下步骤:
git clone https://github.com/ScrapeGraphAI/scrapegraph-mcp
cd scrapegraph-mcp
# 使用pip
pip install -e .
# 或使用uv(更快)
uv pip install -e .
# macOS/Linux
export SGAI_API_KEY=your-api-key-here
# Windows (PowerShell)
$env:SGAI_API_KEY="your-api-key-here"
# Windows (CMD)
set SGAI_API_KEY=your-api-key-here
您可以直接运行服务器:
# 使用已安装命令
scrapegraph-mcp
# 或使用Python模块
python -m scrapegraph_mcp.server
服务器将启动并通过标准输入输出(stdio)通信,这是标准的MCP传输方法。
使用MCP Inspector工具测试您的本地服务器:
npx @modelcontextprotocol/inspector python -m scrapegraph_mcp.server
这将提供一个Web界面来交互式地测试所有可用工具。
要使用本地运行的服务器与Claude Desktop,更新您的配置文件:
macOS/Linux(~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"scrapegraph-mcp-local": {
"command": "python",
"args": [
"-m",
"scrapegraph_mcp.server"
],
"env": {
"SGAI_API_KEY": "your-api-key-here"
}
}
}
}
Windows(%APPDATA%\Claude\claude_desktop_config.json):
{
"mcpServers": {
"scrapegraph-mcp-local": {
"command": "python",
"args": [
"-m",
"scrapegraph_mcp.server"
],
"env": {
"SGAI_API_KEY": "your-api-key-here"
}
}
}
}
注意:确保Python在您的PATH中。您可以通过运行python --version在终端中验证。
在Cursor的MCP设置中,添加一个新的服务器:
python["-m", "scrapegraph_mcp.server"]{"SGAI_API_KEY": "your-api-key-here"}服务器无法启动:
python --versionpip list | grep scrapegraph-mcpecho $SGAI_API_KEY(macOS/Linux)或echo %SGAI_API_KEY%(Windows)工具未显示:
导入错误:
pip install -e . --force-reinstallpip install -r requirements.txt(如果可用)ScrapeGraph MCP服务器可以与Google ADK(代理开发工具包)集成,创建具有网络爬取能力的AI代理。
pip install google-adk
export SGAI_API_KEY=your-api-key-here
创建一个代理文件(例如,agent.py),包含以下配置:
import os
from google.adk.agents import LlmAgent
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
from mcp import StdioServerParameters
# ScrapeGraph MCP服务器目录路径
SCRAPEGRAPH_MCP_PATH = "/path/to/scrapegraph-mcp"
# 服务器.py文件路径
SERVER_SCRIPT_PATH = os.path.join(
SCRAPEGRAPH_MCP_PATH,
"src",
"scrapegraph_mcp",
"server.py"
)
root_agent = LlmAgent(
model='gemini-2.0-flash',
name='scrapegraph_assistant_agent',
instruction='使用ScrapeGraph AI帮助用户进行网络爬取和数据提取。'
'您可以将网页转换为Markdown,使用AI提取结构化数据,'
'执行网络搜索,爬取多个页面,并自动化复杂的爬取工作流程。',
tools=[
MCPToolset(
connection_params=StdioConnectionParams(
server_params=StdioServerParameters(
command='python3',
args=[
SERVER_SCRIPT_PATH,
],
env={
'SGAI_API_KEY': os.getenv('SGAI_API_KEY'),
},
),
timeout=300.0,)
),
# 可选:过滤MCP服务器暴露的哪些工具
# tool_filter=['markdownify', 'smartscraper', 'searchscraper']
)
],
)
超时设置:
timeout=300.0工具过滤:
tool_filter限制可用的工具:
tool_filter=['markdownify', 'smartscraper', 'searchscraper']
API密钥配置:
export SGAI_API_KEY=your-keyenv字典:'SGAI_API_KEY': 'your-key-here'配置完成后,您的代理可以使用自然语言与网络爬取工具交互:
# 代理现在可以处理如下查询:
# - "将https://example.com转换为Markdown"
# - "从这个电子商务页面提取所有产品价格"
# - "搜索最近关于AI驱动的网络爬取的研究并总结"
# - "爬取这个文档站点并提取所有API端点"
有关Google ADK的更多信息,请访问官方文档。
服务器支持各种爬取场景中的复杂查询:
服务器实现了强大的错误处理机制,提供详细且可操作的错误消息,包括:
在Windows系统上运行时,您可能需要使用以下命令连接到MCP服务器:
C:\Windows\System32\cmd.exe /c npx -y @smithery/cli@latest run @ScrapeGraphAI/scrapegraph-mcp --config "{\"scrapegraphApiKey\":\"YOUR-SGAI-API-KEY\"}"
这确保了在Windows环境下的正确执行。
“ScrapeGraph客户端未初始化”
SGAI_API_KEY环境变量或通过--config提供“错误401:未授权”
“错误402:支付所需”
SmartCrawler未返回结果
smartcrawler_fetch_results()直到状态为“已完成”工具未出现在Claude Desktop中
~/Library/Logs/Claude/(macOS)或%APPDATA%\Claude\Logs\(Windows)有关详细的故障排除,请参阅[.agent文档](.agent