使用说明
🌐 Web Search MCP (Rust)
🔍 多引擎 AI 联网搜索 MCP 服务 — 一站式接入,随心切换
功能特性 • 快速开始 • 搜索引擎 • 配置参数 • API 接口 • 部署
✨ 功能特性
| 特性 | 说明 |
|---|---|
| 🔌 多引擎支持 | Kimi · 智谱 · 火山引擎 · 腾讯云 · 阿里云,一个服务全搞定 |
| 🎯 动态工具发现 | 按需传参,只暴露你配置了的搜索引擎 |
| 🔀 默认搜索别名 | default-search=kimi 即可生成通用 web-search 工具 |
| 📡 MCP 协议 | 完整实现 Model Context Protocol (2026-07-28) |
| 🚀 轻量高效 | Rust 原生编写,静态编译无运行时依赖,启动快、内存占用低 |
| 🐳 Docker 支持 | 开箱即用的 Dockerfile,极简容器化部署 |
| 🧩 易于扩展 | 实现 SearchProvider trait + 注册一行代码 = 新增搜索引擎 |
🔍 搜索引擎
| Provider | Tool 名称 | 必需参数 | 说明 |
|---|---|---|---|
| 🌙 Kimi | kimi-search |
kimi-apiKey |
月之暗面 Moonshot AI 联网搜索 |
| 🧠 智谱 (Zai) | zai-search |
zai-apiKey |
智谱 BigModel 搜索 API,支持多搜索引擎 |
| 🌋 火山引擎 (Volces) | volces-search |
volces-apiKey |
豆包大模型联网搜索,支持抖音/头条等源 |
| ☁️ 腾讯云 (Tencentmaas) | tencentmaas-search |
tencentmaas-apiKey |
混元大模型联网搜索 |
| 🟠 阿里云 (Aliyuncs) | aliyuncs-search |
aliyuncs-apiKey + aliyuncs-baseUrl |
通义千问联网搜索(需提供业务空间 URL) |
[!TIP] 阿里云需要同时提供
aliyuncs-apiKey和aliyuncs-baseUrl(如https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com)才会在tools/list中显示。
🚀 快速开始
📋 环境要求
- Rust >= 1.75
- 至少一个搜索引擎的 API Key
🏃 开发运行
cargo run
指定端口运行:
cargo run -- -p 8080
# 或
cargo run -- --port 8080
服务启动后即可使用:
🚀 MCP Server running at http://0.0.0.0:3000
🔑 Example: POST http://localhost:3000/mcp?kimi-apiKey=YOUR_KEY
📚 Supported providers: kimi, zai, volces, tencentmaas, aliyuncs
🔨 构建发布版本
cargo build --release
编译后的可执行文件位于 target/release/web-search-mcp (Windows 下为 web-search-mcp.exe)。
⚙️ 配置参数
所有参数均通过 URL Query String 传递,格式为 {provider}-{param}。
🌙 Kimi
| 参数 | 必填 | 默认值 | 说明 |
|---|---|---|---|
kimi-apiKey |
✅ | — | Moonshot API Key |
kimi-model |
— | moonshot-v1-32k |
模型名称 |
🧠 智谱 (Zai)
| 参数 | 必填 | 默认值 | 说明 |
|---|---|---|---|
zai-apiKey |
✅ | — | 智谱 API Key |
zai-search_engine |
— | search_std |
搜索引擎 (search_std / search_pro / search_pro_sogou / search_pro_quark) |
zai-count |
— | 10 |
返回结果数 (1-50) |
zai-search_recency_filter |
— | noLimit |
时间过滤 (oneDay / oneWeek / oneMonth / oneYear / noLimit) |
zai-content_size |
— | medium |
内容长度 (medium / high) |
🌋 火山引擎 (Volces)
| 参数 | 必填 | 默认值 | 说明 |
|---|---|---|---|
volces-apiKey |
✅ | — | 火山引擎 API Key |
volces-model |
— | doubao-seed-2-0-mini-260428 |
模型名称 |
volces-max_keyword |
— | 2 |
最大关键词数 (1-50) |
volces-limit |
— | 10 |
最大返回结果数 (1-50) |
volces-sources |
— | — | 附加搜索源,逗号分隔 (douyin,moji,toutiao) |
☁️ 腾讯云 (Tencentmaas)
| 参数 | 必填 | 默认值 | 说明 |
|---|---|---|---|
tencentmaas-apiKey |
✅ | — | 腾讯云 API Key |
tencentmaas-model |
— | hy3 |
模型名称 |
tencentmaas-search_source |
— | standard |
搜索版本 (lite / standard) |
🟠 阿里云 (Aliyuncs)
| 参数 | 必填 | 默认值 | 说明 |
|---|---|---|---|
aliyuncs-apiKey |
✅ | — | 阿里云 API Key |
aliyuncs-baseUrl |
✅ | — | 业务空间 URL(如 https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com) |
aliyuncs-model |
— | qwen3.7-flash |
模型名称 |
🔀 默认搜索
| 参数 | 说明 |
|---|---|
default-search |
设为 Provider 名称(如 kimi),会额外暴露一个 web-search 通用工具,调用时委托给指定 Provider |
📡 API 接口
端点
POST http://localhost:3000/mcp?{参数}
💡 使用示例
🔹 只用 Kimi 搜索
POST /mcp?kimi-apiKey=sk-xxxxxxxx
tools/list 返回:kimi-search
🔹 多引擎 + 默认搜索
POST /mcp?kimi-apiKey=sk-xxx&zai-apiKey=zzz&default-search=kimi
tools/list 返回:kimi-search、zai-search、web-search
调用
web-search等同于调用kimi-search
🔹 火山引擎自定义参数
POST /mcp?volces-apiKey=sk-xxx&volces-max_keyword=5&volces-sources=douyin,toutiao
tools/list 返回:volces-search
🔹 阿里云(需要 baseUrl)
POST /mcp?aliyuncs-apiKey=sk-xxx&aliyuncs-baseUrl=https://workspace.cn-beijing.maas.aliyuncs.com
tools/list 返回:aliyuncs-search
🔹 全部引擎拉满
POST /mcp?kimi-apiKey=sk-a&zai-apiKey=sk-b&volces-apiKey=sk-c&tencentmaas-apiKey=sk-d&aliyuncs-apiKey=sk-e&aliyuncs-baseUrl=https://ws.maas.aliyuncs.com&default-search=zai
tools/list 返回:kimi-search、zai-search、volces-search、tencentmaas-search、aliyuncs-search、web-search
📨 请求 & 响应示例
获取工具列表:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list"
}
调用搜索工具:
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "kimi-search",
"arguments": {
"query": "今天北京天气怎么样"
}
}
}
响应:
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"content": [
{
"type": "text",
"text": "搜索结果..."
}
]
}
}
🖥️ 在客户端中使用
Claude Desktop
在 Claude Desktop 配置文件中添加:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"web-search": {
"url": "http://localhost:3000/mcp?kimi-apiKey=YOUR_API_KEY&default-search=kimi"
}
}
}
Cursor
在 .cursor/mcp.json 中添加:
{
"mcpServers": {
"web-search": {
"url": "http://localhost:3000/mcp?kimi-apiKey=YOUR_API_KEY&default-search=kimi"
}
}
}
🐳 部署
Docker 构建
docker build -t web-search-mcp .
Docker 运行
docker run -d -p 3000:3000 web-search-mcp
Docker Compose
version: '3'
services:
web-search-mcp:
build: .
ports:
- "3000:3000"
📁 项目结构
web-search-mcp-rs/
├── src/
│ ├── main.rs # 🚪 入口文件与 MCP HTTP 服务器(动态路由)
│ └── provider/ # 🔌 搜索引擎 Provider 模块
│ ├── mod.rs # ├─ Trait 定义、公共类型与注册表
│ ├── kimi.rs # ├─ 🌙 Kimi (Moonshot)
│ ├── zai.rs # ├─ 🧠 智谱 (BigModel)
│ ├── volces.rs # ├─ 🌋 火山引擎 (豆包)
│ ├── tencentmaas.rs # ├─ ☁️ 腾讯云 (混元)
│ └── aliyuncs.rs # └─ 🟠 阿里云 (通义千问)
├── Cargo.toml # ⚙️ Rust 包与依赖配置
├── Dockerfile # 🐳 Docker 构建文件
└── .github/ # 🚀 CI/CD 自动化构建与发布
🧩 扩展新引擎
只需 3 步 即可新增一个搜索引擎:
① 创建 Provider 文件 src/provider/my_engine.rs
use super::{SearchProvider, WebSearchResult};
use std::collections::HashMap;
pub struct MyEngineProvider;
#[async_trait::async_trait]
impl SearchProvider for MyEngineProvider {
fn name(&self) -> &str { "myengine" }
fn tool_name(&self) -> &str { "myengine-search" }
fn description(&self) -> &str { "我的自定义搜索引擎" }
fn required_params(&self) -> &[&str] { &["myengine-apiKey"] }
async fn search(
&self,
query: &str,
params: &HashMap<String, String>,
client: &reqwest::Client,
) -> Result<WebSearchResult, String> {
let api_key = params.get("myengine-apiKey").unwrap();
// ... 调用搜索 API ...
Ok(WebSearchResult::text("搜索结果"))
}
}
② 在注册表中注册 src/provider/mod.rs
pub mod my_engine;
pub use my_engine::MyEngineProvider;
// 在 build_registry 中添加:
registry.register(Box::new(MyEngineProvider));
③ 完成! 传入 myengine-apiKey=xxx 即可使用 ✅
🛠️ 技术栈
| 技术 | 用途 |
|---|---|
| Rust | ⚡ 极致性能与内存安全 |
| Axum | 🌐 高性能异步 Web 框架 |
| Tokio | ⏳ 异步运行时 |
| Reqwest | 📡 静态编译友好 HTTP 客户端 (rustls) |
| MCP Protocol | 📡 Model Context Protocol (2026-07-28) |
📄 许可证
Made with ❤️ using Rust — 🌐 搜索无界,引擎随心