deepseek-web-search-mcp
# DeepSeek Web Search MCP
基于 Python(`uv` + `FastMCP`)实现的独立 **Model Context Protocol (MCP)** 服务,直接封装 DeepSeek 官方独立的[网页搜索(Search)与网页抓取(Fetch)工具 API](https://api-docs.deepseek.com/zh-cn/guides/search/)。
让你在 **Antigravity**、**Claude Desktop**、**Cursor**、**Cline**、**Claude Code** 等任意支持 MCP 的客户端中,复用已有的 DeepSeek API Key 获得低延迟、低成本的实时联网搜索与网页 Markdown 正文提取能力,**不消耗对话模型 Token**。
---
## 核心特性
- **双工具闭环**:
- `deepseek_search`:调用 `POST /v1/tools/search`,支持 `site:`、`-site:`、`lang:`、`after:`/`before:`、精确短语等搜索语法,支持 `summary`(600~800 字模型友好长摘要)/ `snippet` / `full` 三档返回粒度与 `min_score` 质量过滤。
- `deepseek_fetch`:调用 `POST /v1/tools/fetch`,抓取单个网页并转为干净的 Markdown 正文,带最大字符截断保护。
- **官方计费友好**:直接调用工具接口(官方标准定价 5 元 / 1,000 次成功请求,失败或空结果不计费;不走对话模型推理)。
- **健壮与安全**:
- 自动截断超过 128 字符的 `query` / `ori_question`,避免触发 HTTP 400。
- 严格校验 `deepseek_fetch` URL(仅允许 `http`/`https`、禁止携带 `userinfo`、限制最大 8192 字符)。
- 针对 `408`、`429`(支持 `Retry-After`)、`5xx` 及网络超时自动指数退避重试;`401`/`402`/`404` 快速失败并给出清晰提示,绝不泄露 API Key。
- 严格分离 `stdio` 协议输出与 `stderr` 日志,杜绝 JSON-RPC 解析损坏;在返回结果头部标注外部网页为不可信参考数据。
- **零克隆一键运行**:支持 `uvx --from git+https://github.com/LS-King/deepseek-web-search-mcp` 直接拉起。
---
## 前置准备
1. 已安装 [`uv`](https://docs.astral.sh/uv/)(包含 `uvx`)且系统具备 Python 3.11+。
2. 在 [DeepSeek 开放平台](https://platform.deepseek.com/api_keys) 申请一个 `DEEPSEEK_API_KEY`,并确保账户有可用余额。
---
## 快速配置(MCP 客户端)
### 方式 A:使用 `uvx` 直接从 GitHub 启动(推荐,无需手动克隆)
在任意支持标准 `mcpServers` 配置的客户端中填入以下配置:
```json
{
"mcpServers": {
"deepseek-web-search": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/LS-King/deepseek-web-search-mcp",
"deepseek-web-search-mcp"
],
"env": {
"DEEPSEEK_API_KEY": "sk-your-deepseek-api-key"
}
}
}
}
```
### 方式 B:本地克隆后通过 `uv run` 启动(适合本地二次开发)
```bash
git clone https://github.com/LS-King/deepseek-web-search-mcp.git
cd deepseek-web-search-mcp
uv sync
```
客户端配置示例(请将路径替换为你的实际克隆目录):
```json
{
"mcpServers": {
"deepseek-web-search": {
"command": "uv",
"args": [
"run",
"--directory",
"/path/to/deepseek-web-search-mcp",
"deepseek-web-search-mcp"
],
"env": {
"DEEPSEEK_API_KEY": "sk-your-deepseek-api-key"
}
}
}
}
```
### 常见客户端配置路径
| 客户端 | 配置文件位置 / 添加方式 |
| :--- | :--- |
| **Antigravity** | 全局 `~/.gemini/config/mcp_config.json` 或工作区 `.agents/mcp_config.json` |
| **Claude Desktop** | Windows: `%APPDATA%\Claude\claude_desktop_config.json`;macOS: `~/Library/Application Support/Claude/claude_desktop_config.json` |
| **Cursor** | Settings → MCP → Add New MCP Server |
| **Claude Code** | `claude mcp add deepseek-web-search -e DEEPSEEK_API_KEY=sk-... -- uvx --from git+https://github.com/LS-King/deepseek-web-search-mcp deepseek-web-search-mcp` |
---
## 工具说明
### 1. `deepseek_search`
调用 DeepSeek 独立 Search API 搜索互联网。
| 参数 | 类型 | 必填 | 默认值 | 说明 |
| :--- | :--- | :--- | :--- | :--- |
| `query` | `string` | 是 | — | 搜索词(1~128 Unicode 字符,超长会自动截断)。支持 `site:`、`-site:`、`-关键词`、`"精确短语"`、`lang:zh,en`、`after:`、`before:`。 |
| `count` | `integer` | 否 | `10` | 返回条数(1~50)。 |
| `detail_level` | `"summary" \| "snippet" \| "full"` | 否 | `"summary"` | `summary`(推荐,600~800 字长摘要)、`snippet`(100~200 字短摘要)、`full`(开启 `need_content` 并返回截断保护后的正文)。 |
| `min_score` | `number` | 否 | `0.0` | 最低 `rerank_score` 过滤阈值(0.0~3.0,官方认为 `>= 1.5` 为优质结果)。 |
| `ori_question` | `string \| null` | 否 | `null` | 触发搜索的用户原始问题(最多 128 字符),有助于理解意图。 |
| `localization` | `string` | 否 | `""` | 可选 IP 地址字符串,用于优先返回本地化搜索结果。 |
### 2. `deepseek_fetch`
调用 DeepSeek 独立 Fetch API 抓取单个网页并返回 Markdown 正文。
| 参数 | 类型 | 必填 | 默认值 | 说明 |
| :--- | :--- | :--- | :--- | :--- |
| `url` | `string` | 是 | — | 完整的 `http://` 或 `https://` 网址(≤8192 字符,不允许携带用户名/密码)。 |
| `max_chars` | `integer \| null` | 否 | `DEEPSEEK_FETCH_MAX_CHARS` (`12000`) | 返回 Markdown 的最大字符数(≥500),超出时自动截断并提示总长度。 |
---
## 环境变量与自检命令
| 环境变量 | 必填 | 默认值 | 说明 |
| :--- | :--- | :--- | :--- |
| `DEEPSEEK_API_KEY` | 是 | — | DeepSeek 开放平台 API Key(`sk-...`)。 |
| `DEEPSEEK_BASE_URL` | 否 | `https://api.deepseek.com` | 自定义 API 地址(用于企业网关或私有代理)。 |
| `DEEPSEEK_TIMEOUT_SECONDS` | 否 | `30` | 单次 HTTP 请求超时秒数。 |
| `DEEPSEEK_MAX_RETRIES` | 否 | `2` | 遇到 `408`/`429`/`5xx` 或网络超时时的最大重试次数(0~10)。 |
| `DEEPSEEK_FETCH_MAX_CHARS` | 否 | `12000` | `deepseek_fetch` 默认最大返回字符数(≥500)。 |
运行配置自检(不发网络请求、不扣费,并对 Key 自动脱敏):
```bash
DEEPSEEK_API_KEY=sk-your-key uv run deepseek-web-search-mcp --check
```
---
## 本地开发与测试
```bash
# 安装运行与开发依赖
uv sync --dev
# 代码风格与静态检查
uv run ruff check src tests
# 运行全部单元测试与 FastMCP 协议测试(全离线,无需真实 API Key)
uv run pytest -v
```
---
## License
[MIT License](LICENSE)
TDQS
Scored across 2 tools
deepseek_search and deepseek_fetch target clearly distinct actions: querying a search endpoint versus retrieving and cleaning a single known URL. There is no plausible scenario where an agent would confuse the two.
Both tools follow an identical namespace_verb snake_case pattern (deepseek_search, deepseek_fetch), matching the server name and each other perfectly. No mixed conventions.
Two tools is on the thin side, but for a search-and-fetch API wrapper they are exactly the two primitives needed, so each earns its place. The surface is minimal rather than padded.
Search plus fetch covers the standard discover-then-read workflow with no dead ends. Minor gaps exist (no batch fetch, crawling, or result-pagination control), but agents can work around them with repeated calls.