Files
agent/mcp/web_search/README.md
T
kicer 8f693d0753 部署:video_gen 双监听(全量 3000 内网 / 只读 3001 公网供中转),mcp 默认不占宿主机端口
- video_gen: UPLOAD_BASE_URL(AI 上传,内网)与 PUBLIC_BASE_URL(智谱下载,公网)拆开配置;
  新增 PUBLIC_PORT 公网只读监听,只挂 GET /uploads/*(无 /mcp、无 POST /upload)
- video_gen: 上传目录落到宿主 ./uploads(重启不让已发出的 URL 失效),Dockerfile EXPOSE 3000 3001
- docker-compose: 三个服务默认都不映射宿主机端口(调试用的 ports 注释保留);
  video_gen 配 UPLOAD_BASE_URL/PUBLIC_BASE_URL/PUBLIC_PORT/UPLOAD_DIR + ./uploads 挂载
- .gitignore(新): node_modules/ 与 uploads/
- 文档: 根 README 说明「只开 agent 端口」与图片到智谱的完整链路;三个子 README 同步端口与调试方式
2026-09-15 19:40:53 +08:00

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 走 `my-app-network` 按容器名访问
(`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}
```
该服务**无服务端鉴权**(上游是免费端点),**永远不要**对外映射端口——会被白嫆搜索额度。