# baidu-search-mcp

[![npm version](https://badge.fury.io/js/baidu-search-mcp.svg)](https://www.npmjs.com/package/baidu-search-mcp)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

基于 [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) 的百度搜索服务器，为 AI 智能体提供中文网络搜索能力。

## ✨ 特性

- 🔍 **百度搜索**: 直接使用百度搜索引擎，特别适合中文内容
- 🆓 **完全免费**: 无需 API Key，无调用次数限制
- ⚡ **快速响应**: 3-10 秒返回搜索结果
- 📄 **深度抓取**: 可选抓取搜索结果页面的详细内容
- 🎯 **灵活配置**: 支持自定义结果数量和内容长度
- 🔧 **即开即用**: 无需复杂配置，安装即可使用

## 📦 安装

### 全局安装（推荐）

```bash
npm install -g baidu-search-mcp
```

### 本地安装

```bash
npm install baidu-search-mcp
```

## 🚀 使用方法

### 在 Claude Desktop 中使用

编辑 Claude Desktop 配置文件：

**macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`  
**Windows**: `%APPDATA%\Claude\claude_desktop_config.json`

#### 方式 1: 基础配置（使用默认参数）

```json
{
  "mcpServers": {
    "baidu-search": {
      "command": "npx",
      "args": ["baidu-search-mcp"]
    }
  }
}
```

#### 方式 2: 自定义参数配置（推荐）

```json
{
  "mcpServers": {
    "baidu-search": {
      "command": "npx",
      "args": [
        "baidu-search-mcp",
        "--max-result=5",
        "--fetch-content-count=2",
        "--max-content-length=2000"
      ]
    }
  }
}
```

#### 方式 3: 全局安装后使用

```bash
# 先全局安装
npm install -g baidu-search-mcp
```

```json
{
  "mcpServers": {
    "baidu-search": {
      "command": "npx",
      "args": [
        "baidu-search-mcp",
        "--max-result=5",
        "--fetch-content-count=2",
        "--max-content-length=2000"
      ]
    }
  }
}
```

### 命令行参数说明

| 参数 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
| `--max-result` | number | 8 | 默认返回的搜索结果数量（1-50） |
| `--fetch-content-count` | number | 1 | 抓取详细内容的结果数量（1-10） |
| `--max-content-length` | number | 3000 | 默认每页最大抓取字符数（500-10000） |

**示例**:

```bash
# 快速搜索模式（仅摘要）
--max-result=5 --fetch-content-count=0

# 深度搜索模式（含详细内容）
--max-result=3 --fetch-content-count=3 --max-content-length=5000

# 大量快速搜索
--max-result=20 --fetch-content-count=0
```


### 在其他 MCP 客户端中使用

任何支持 MCP 协议的客户端都可以使用此服务器。通过 stdio 方式连接：

```bash
baidu-search-mcp
```

## 💡 使用建议

### 何时使用 `fetch_content: true`？

✅ **适合使用**:
- 需要深入分析文章内容
- 要对比多个来源的详细信息
- 提取特定段落或数据

❌ **不建议使用**:
- 只需要概览信息
- 对响应速度有严格要求
- 搜索结果数量较多（>5条）

### 搜索技巧

1. **使用关键词**: "React Hooks 教程" 优于 "如何学习 React Hooks"
2. **添加限定词**: "2024 人工智能趋势" 获取最新信息
3. **控制数量**: 一般 5-8 条结果足够，过多会影响性能

## 📊 性能对比

| 场景 | 参数设置 | 响应时间 | 适用情况 |
|------|----------|----------|----------|
| 快速概览 | `fetch_content: false` | 1-2秒 | 日常对话、快速查询 |
| 深度分析 | `fetch_content: true, count: 3` | 3-5秒 | 需要详细内容 |
| 全面研究 | `fetch_content: true, count: 8` | 8-10秒 | 深度研究、内容对比 |

## 🔧 开发

### 克隆仓库

```bash
git clone https://github.com/caiyili/baidu-search-mcp.git
cd baidu-search-mcp
```

### 安装依赖

```bash
npm install
```

### 本地测试

```bash
npm start
```

### 开发模式（支持热重载）

```bash
npm run dev
```

## 🐛 故障排除

### 搜索结果很少或为空

**原因**:
- 百度页面结构变化
- 网络问题
- 反爬限制

**解决方案**:
1. 稍后重试
2. 更换搜索关键词
3. 检查网络连接

### Claude Desktop 无法识别工具

**检查清单**:
- ✅ 配置文件路径正确
- ✅ JSON 格式正确（无多余逗号）
- ✅ 已重启 Claude Desktop
- ✅ 包已正确安装

### 抓取内容失败

部分网站可能有反爬机制，这是正常现象。建议：
- 使用 `fetch_content: false` 仅获取摘要
- 或使用 `fetch_url` 工具单独抓取特定 URL

## 🤝 贡献

欢迎提交 Issue 和 Pull Request！

### 开发指南

1. Fork 本仓库
2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
4. 推送到分支 (`git push origin feature/AmazingFeature`)
5. 开启 Pull Request

## 📝 更新日志

### v1.0.0 (2025-11-14)

- ✨ 初始版本发布
- 🔍 支持百度搜索
- 📄 支持页面内容抓取
- ⚙️ 可配置结果数量和内容长度

## 📄 许可证

[MIT License](LICENSE)

## 🔗 相关链接

- [Model Context Protocol](https://modelcontextprotocol.io/)
- [Claude Desktop](https://claude.ai/desktop)
- [npm 包地址](https://www.npmjs.com/package/baidu-search-mcp)


## ⭐ Star History

如果这个项目对你有帮助，请给它一个 Star！

---

**注意**: 本工具仅供学习和研究使用，请遵守百度搜索的使用条款和相关法律法规。
