Files
agent/mcp/web_search/README.md
T

52 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# web_search
免费网页搜索 MCP server 的本地重构版(上游开源实现:[@sheep233_/dsh-web-search-free](https://github.com/sheep-programmer/dsh-web-search-free),MIT)。
零运行时依赖,只用 Node 内置 `fetch`(Node ≥ 18),**无需 npm install,直接 `node server.js` 启动**。
## 结构
| 文件 | 职责 |
| --- | --- |
| `core.js` | 搜索后端:Parallel(默认)/ Exa(备用)免费 MCP 端点封装 + 响应解析 |
| `mcp.js` | MCP 协议层:`web_search` 工具定义 + JSON-RPC 分发 |
| `server.js` | 入口:CLI 参数 + stdio / HTTP/SSE 双传输 |
## 本地启动
```bash
# HTTP/SSE 模式(默认 127.0.0.1:3100)
node server.js --http --port 3100
# stdio 模式(Claude Code / Codex 直接拉起时用)
node server.js
```
MCP 端点:
- `POST /` — Streamable HTTP(也接受 `Accept: text/event-stream`)
- `GET /sse` + `POST /messages` — 老式 SSE 传输
- `GET /health` — 健康检查
环境变量(均可选):
- `EXA_API_KEY` — 提升 Exa 匿名限额
- `SEARCH_TIMEOUT_MS` — 上游搜索超时,默认 30000
## Docker
`docker-compose.yml` 中的 `mcp_web_search` 服务直接构建本目录,Dockerfile 已改为拷贝源码启动(不再有 `npm install -g`)。
容器内监听 3000,**默认不占宿主端口**:agent 走 `agent-mcp-net` 按容器名访问
(`http://mcp_web_search:3000/`)。需要从宿主机 curl 调试时,把仓库根 `docker-compose.yml` 里
`mcp_web_search` 注释掉的 `ports` 两行打开(默认写的是 8081),调试完记得注释回去。
```bash
docker compose build mcp_web_search && docker compose up -d mcp_web_search
# 不占端口的健康检查
docker exec mcp_web_search node -e "fetch('http://localhost:3000/health').then(r=>r.text()).then(console.log)"
# {"name":"web_search","version":"...","transport":"http/sse","port":3000}
```
该服务**无服务端鉴权**(上游是免费端点),**永远不要**对外映射端口——会被白嫆搜索额度。