使用说明
网络搜索mcp
一种MCP(Model Context Protocol)服务器,提供使用DuckDuckGo的Web搜索功能。在Rust中实现,不需要API密钥就可以使用。
机能一覧
本服务器提供以下两个MCP工具。
工具名称|说明|数据源|
|---|---|---|
| web_search 执行基于关键字的Web检索,返回检索结果一览表html.duckduckgo.com),模板名称将采用不同的格式
| instant_answer 返回对查询的即时回答(定义、摘要、相关主题等)api.duckduckgo.com) |
技术栈
|类别|粘土/技术| |---|---| |MCP-SDK| rmcp (公式 Rust SDK) | HTTP客户端 reqwest | HTML解析器 爬虫 | 异步运行时 东京 | 串行化 序列化与反序列化 / Serde JSON | | JSON Schema 生成 | 阴谋家 | 错误处理 这个错误 | 日志 追踪 / 追踪订户 |
前提条件
- Rust toolchain (1.75 以上推奨)
- 网络连接(需要访问DuckDuckGo)
安装
快速安装(Linux/macOS)
curl -fsSL https://raw.githubusercontent.com/mizunomi32/websearch-mcp/main/install.sh | sh
要更改安装位置:
INSTALL_DIR=~/.local/bin curl -fsSL https://raw.githubusercontent.com/mizunomi32/websearch-mcp/main/install.sh | sh
自制(macOS)
brew tap mizunomi32/websearch-mcp https://github.com/mizunomi32/websearch-mcp.git
brew install websearch-mcp
APT(Debian/Ubuntu)
# GPG 鍵を追加
curl -fsSL https://mizunomi32.github.io/websearch-mcp/websearch-mcp-keyring.gpg \
| sudo tee /usr/share/keyrings/websearch-mcp-keyring.gpg > /dev/null
# リポジトリを追加
echo "deb [signed-by=/usr/share/keyrings/websearch-mcp-keyring.gpg] https://mizunomi32.github.io/websearch-mcp stable main" \
| sudo tee /etc/apt/sources.list.d/websearch-mcp.list > /dev/null
# インストール
sudo apt update
sudo apt install websearch-mcp
YUM/DNF(Fedora/RHEL/CentOS)
# GPG 鍵をインポート
sudo rpm --import https://mizunomi32.github.io/websearch-mcp/rpm/RPM-GPG-KEY-websearch-mcp
# リポジトリを追加
sudo tee /etc/yum.repos.d/websearch-mcp.repo << 'EOF'
[websearch-mcp]
name=websearch-mcp
baseurl=https://mizunomi32.github.io/websearch-mcp/rpm/$basearch
enabled=1
gpgcheck=1
gpgkey=https://mizunomi32.github.io/websearch-mcp/rpm/RPM-GPG-KEY-websearch-mcp
EOF
# インストール
sudo dnf install websearch-mcp
从源构建
# リポジトリをクローン
git clone https://github.com/mizunomi32/websearch-mcp.git
cd websearch-mcp
# リリースビルド
cargo build --release
# バイナリは target/release/websearch-mcp に生成されます
用法
在Claude Desktop中设置
claude_desktop_config.json 将条目添加到文档注册表。
{
"mcpServers": {
"websearch": {
"command": "/path/to/websearch-mcp"
}
}
}
在Claude Code中设置
.mcp.json 将条目添加到文档注册表。
{
"mcpServers": {
"websearch": {
"command": "/path/to/websearch-mcp"
}
}
}
服务器通过stdio传输进行MCP通信。
设定
您可以使用环境变量自定义行为。
|环境变量|说明|默认值|
|---|---|---|
| WEBSEARCH_MAX_RESULTS | web_search 的默认最大搜索结果数 10 |
| WEBSEARCH_TIMEOUT_SECS |HTTP请求超时(秒)| 10 |
| WEBSEARCH_USER_AGENT 用于HTTP请求的User-Agent字符串 websearch-mcp/0.1 |
| WEBSEARCH_CACHE_TTL_SECS 响应高速缓存的TTL(秒) 300 |
| WEBSEARCH_RATE_LIMIT_MS 请求之间的最小间隔(毫秒) 1000 |
| WEBSEARCH_MAX_RETRIES 429/5xx/超时时的最大重试次数 3 |
开発
测试运行
cargo test -- --test-threads=1
注: 某些测试共享全局状态(例如环境变量)
--test-threads=1中所述修改相应参数的值。
行格式
# フォーマットチェック
cargo fmt --all --check
# Lint チェック
cargo clippy --all-targets -- -D warnings
持续集成
GitHub Actions在push和Pull Request期间自动执行测试行格式检查。
项目结构
src/
├── main.rs # エントリーポイント
├── lib.rs # モジュール再エクスポート
├── server.rs # MCP サーバー定義
├── config.rs # 環境変数読み込み
├── error.rs # エラー型定義
├── http_client.rs # HTTP クライアント構築
├── cache.rs # TTL 付きインメモリキャッシュ
├── rate_limiter.rs # リクエスト間隔制御
├── retry.rs # Exponential Backoff リトライ
├── tools/
│ ├── web_search.rs # Web 検索(HTML パース)
│ └── instant_answer.rs # Instant Answer(API 連携)
└── models/
├── search.rs # SearchResult 構造体
└── instant_answer.rs # API レスポンスモデル
许可证
MIT许可证