WebSearch网络搜索工具
构建为一个模型上下文协议(MCP)服务器,通过使用Firecrawl API提供高级网络搜索、内容提取、网络爬取和抓取功能。
可用工具 (4 个)
该服务在 MCP 协议中暴露的工具,AI 可按需调用
search 1 个参数 需填 1 项
Performs web searches and retrieves up-to-date information from the internet. Args: - prompt: Specific query or topic to search for on the internet - limit: Maximum number of results to return (between 1 and 20) Returns: - Search results with relevant information about the requested topic
必填参数:query
crawl 3 个参数 需填 3 项
Crawls a website starting from the specified URL and extracts content from multiple pages. Args: - url: The complete URL of the web page to start crawling from - maxDepth: The maximum depth level for crawling linked pages - limit: The maximum number of pages to crawl Returns: - Content extracted from the crawled pages in markdown and HTML format
必填参数:url、maxDepth、limit
extract 4 个参数 需填 4 项
Extracts specific information from a web page based on a prompt. Args: - url: The complete URL of the web page to extract information from - prompt: Instructions specifying what information to extract from the page - enabaleWebSearch: Whether to allow web searches to supplement the extraction - showSources: Whether to include source references in the response Returns: - Extracted information from the web page based on the prompt
必填参数:url、prompt、enabaleWebSearch、showSources
scrape 1 个参数 需填 1 项
必填参数:url
服务介绍
WebSearch - 高级网络搜索和内容提取工具
这是一个强大的网络搜索和内容提取工具,使用 Python 构建,并利用 Firecrawl API 提供高级的网页抓取、搜索和内容分析功能。
🚀 功能
- 高级网络搜索:执行带有可自定义参数的智能网络搜索
- 内容提取:使用自然语言提示从网页中提取特定信息
- 网站爬取:以可配置的深度和限制爬取网站
- 网页抓取:支持多种输出格式的网页抓取
- MCP 集成:作为 Model Context Protocol (MCP) 服务器构建,以便无缝集成
📋 先决条件
- Python 3.8 或更高版本
- uv 包管理器
- Firecrawl API 密钥
- OpenAI API 密钥(可选,用于增强功能)
- Tavily API 密钥(可选,用于额外的搜索能力)
🛠️ 安装
- 安装 uv:
# On Windows (using pip)
pip install uv
# On Unix/MacOS
curl -LsSf https://astral.sh/uv/install.sh | sh
# Add uv to PATH (Unix/MacOS)
export PATH="$HOME/.local/bin:$PATH"
# Add uv to PATH (Windows - add to Environment Variables)
# Add: %USERPROFILE%\.local\bin
- 克隆仓库:
git clone https://github.com/yourusername/websearch.git
cd websearch
- 使用 uv 创建并激活虚拟环境:
# Create virtual environment
uv venv
# Activate on Windows
.\.venv\Scripts\activate.ps1
# Activate on Unix/MacOS
source .venv/bin/activate
- 使用 uv 安装依赖项:
# Install from requirements.txt
uv sync
- 设置环境变量:
# Create .env file
touch .env
# Add your API keys
FIRECRAWL_API_KEY=your_firecrawl_api_key
OPENAI_API_KEY=your_openai_api_key
🎯 使用方法
与 Claude for Desktop 配合使用
你可以配置 Claude for Desktop 来访问 WebSearch 工具,而无需直接运行服务器:
-
找到或创建你的 Claude for Desktop 配置文件:
- Windows:
%env:AppData%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
-
在
mcpServers部分添加 WebSearch 服务器配置:
{
"mcpServers": {
"websearch": {
"command": "uv",
"args": [
"--directory",
"D:\\ABSOLUTE\\PATH\\TO\\WebSearch",
"run",
"main.py"
]
}
}
}
-
确保将目录路径替换为你的 WebSearch 项目文件夹的绝对路径。
-
保存配置文件并重启 Claude for Desktop。
-
配置完成后,WebSearch 工具将在 Claude for Desktop 的工具菜单(锤子图标)中出现。
可用工具
-
搜索
-
提取信息
-
爬取网站
-
抓取内容
📚 API 参考
搜索
query(str): 搜索查询- 返回值: JSON 格式的搜索结果
提取
urls(List[str]): 要从中提取信息的 URL 列表prompt(str): 提取指令enableWebSearch(bool): 启用补充网络搜索showSources(bool): 包含来源引用- 返回值: 以指定格式提取的信息
爬取
url(str): 起始 URLmaxDepth(int): 最大爬取深度limit(int): 最大爬取页数- 返回值: 以 markdown/HTML 格式返回的爬取内容
抓取
url(str): 目标 URL- 返回值: 带有可选截图的抓取内容
🔧 配置
环境变量
该工具需要某些 API 密钥才能运行。我们提供了一个 .env.example 文件,您可以将其用作模板:
- 复制示例文件:
# On Unix/MacOS
cp .env.example .env
# On Windows
copy .env.example .env
- 使用您的 API 密钥编辑
.env文件:
# OpenAI API key - Required for AI-powered features
OPENAI_API_KEY=your_openai_api_key_here
# Firecrawl API key - Required for web scraping and searching
FIRECRAWL_API_KEY=your_firecrawl_api_key_here
获取 API 密钥
-
OpenAI API 密钥:
- 访问 OpenAI 平台
- 注册或登录
- 转到 API 密钥部分
- 创建一个新的密钥
-
Firecrawl API 密钥:
- 访问 Firecrawl 网站
- 创建一个账户
- 转到您的仪表板
- 生成一个新的 API 密钥
如果一切配置正确,您应该会收到包含搜索结果的 JSON 响应。
故障排除
如果您遇到错误:
- 确保所有必需的 API 密钥都已设置在您的
.env文件中 - 验证 API 密钥有效且未过期
- 检查
.env文件是否位于项目的根目录中 - 确保环境变量被正确加载
🤝 贡献
- 分叉仓库
- 创建你的功能分支 (
git checkout -b feature/AmazingFeature) - 提交你的更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 打开一个 Pull Request
📝 许可证
该项目根据 MIT 许可证许可 - 查看 LICENSE 文件以获取详细信息。
🙏 致谢
📬 联系方式
José Martín Rodriguez Mortaloni - @m4s1t425 - jmrodriguezm13@gmail.com
使用 Python 和 Firecrawl 以 ❤️ 制作