search-server
by: fengin
一个基于MCP协议的搜索服务实现,提供网络搜索和本地搜索功能,Cursor和Claude Desktop能与之无缝集成。
📌Overview
Purpose: To provide a search service based on the MCP protocol, integrating multiple search engines seamlessly with Cursor and Claude Desktop.
Overview: The Search MCP Server is developed in Python, designed to handle asynchronous processing and high concurrent requests. It currently supports three search engines: Brave Search, Metaso Search, and Bocha Search.
Key Features:
- Multi-Search Engine Support:
- Integration of three search engines, enabling various search capabilities including web search, academic search, and location-specific search.
- Seamless Integration:
- Works smoothly with Claude Desktop and Cursor, enhancing content retrieval capabilities within these tools.
- Modular Design:
- Each search engine is encapsulated in an independent module, allowing for flexible use and easy customization.
Search MCP Server
一个基于MCP协议的搜索服务实现,提供多种搜索引擎支持,Cursor和Claude Desktop能与之无缝集成。
使用Python开发,支持异步处理和高并发请求,目前支持三种搜索引擎选择:
- Brave Search: 国外一家专业提供搜索接口服务产品
- 秘塔(Metaso)搜索: 秘塔AI搜索的逆向实现接口,非官方接口
- 博查(bocha)搜索: 国内Search API市场占有率最高的搜索API产品
更多MCP知识,见AI全书一文看懂什么是MCP(大模型上下文)?用来干什么的?怎么用它?
作者: 凌封(微信fengin)
网址: AI全书
使用示例
功能特点
- 多搜索引擎支持:
- Brave Search: 网络搜索和位置搜索
- Metaso搜索: 网络搜索和学术搜索,支持简洁和深入两种模式
- 博查搜索: 网络搜索,支持时间范围过滤、详细摘要和图片搜索
- 适用场景: Claude Desktop或者Cursor无缝集成使用,大大扩展工具的内容获取能力
- 模块化设计: 每个搜索引擎都是独立的模块,可以单独拷贝使用
三种搜索的选择
运行时只能生效一种搜索引擎,以下是大致的对比:
搜索引擎 | 国内/外 | 需魔法 | 自带总结 | 质量 | 免费 | 官方 | 速度 | 注册门槛 |
---|---|---|---|---|---|---|---|---|
Brave | 国外 | 是 | 否 | 高 | 是(限量) | 是 | 中 | 很高 |
Metaso | 国内 | 否 | 是 | 中 | 是 | 否 | 慢 | 低 |
Bocha | 国内 | 否 | 否 | 高 | 否 | 是 | 极快 | 低 |
安装和使用
1. 环境要求
- Python 3.10+
- uv 0.24.0+
- node.js v20.15.0
- cursor >=0.45.10 (低于该版本mcp server配置老是连不上)
- 科学上网(仅使用Brave Search需要)
1.1 安装浏览器驱动(仅Metaso需要)
pip install playwright>=1.35.0
playwright install chromium
2.下载代码
git clone https://github.com/fengin/search-server.git
3. 启用搜索引擎
打开项目根目录,修改server.py
以下代码选择启用类型:
SEARCH_ENGINE = os.getenv("SEARCH_ENGINE", "bocha")
4. 配置对应的搜索模块
根据你的选择,修改以下目录对应的config.py
文件:
src/search/proxy/brave/config.py
src/search/proxy/metaso/config.py
src/search/proxy/bocha/config.py
4.1 Brave search配置
BRAVE_API_KEY = os.getenv("BRAVE_API_KEY")
if not BRAVE_API_KEY:
BRAVE_API_KEY = "你申请的 brave_api_key"
4.2 秘塔(metaso)配置
METASO_UID = os.getenv("METASO_UID")
METASO_SID = os.getenv("METASO_SID")
if not METASO_UID or not METASO_SID:
METASO_UID = "你获取的 metaso_uid"
METASO_SID = "你获取的 metaso_sid"
4.3 博查(bocha)配置
BOCHA_API_KEY = os.getenv("BOCHA_API_KEY", "")
if not BOCHA_API_KEY:
BOCHA_API_KEY = "你申请的 bocha_api_key"
5. AI工具配置
5.1 Cursor里配置
- name: search
- type: cmd
- command:
uv --directory D:\\code\\search-server run search
5.2 Claude Desktop配置
找到配置文件进行编辑:
{
"mcpServers": {
"search": {
"command": "uv",
"args": [
"--directory",
"D:\\code\\search-server",
"run",
"search"
],
"env": {
"BRAVE_API_KEY": "你申请的API KEY"
}
}
}
}
6. 使用
在你的Claude Desktop或Cursor中,正常工作时会自动调用搜索接口获取内容。配置好工具后,它的信息内会知道有这个工具,并根据需求自动调用搜索工具。
技术内幕
项目结构
search/
├── __init__.py
├── server.py # MCP服务器实现
└── proxy/ # 搜索引擎代理
├── brave/ # Brave搜索模块
├── metaso/ # Metaso搜索模块
└── bocha/ # 博查搜索模块
接口参数
Brave Search引擎
- search: 执行网络搜索,支持分页和过滤
- location_search: 搜索地理位置相关信息
Metaso搜索引擎
- search: 执行网络搜索,支持多种模式
- scholar_search: 执行学术搜索,专门用于查找学术资源
博查搜索引擎
- search: 执行网络搜索,支持时间范围过滤和详细摘要