修正文件夹目录
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
services:
|
services:
|
||||||
mcp-web-search-free:
|
mcp_web_search:
|
||||||
build: ./web-search-free
|
build: ./web_search
|
||||||
container_name: mcp-web-search-free
|
container_name: mcp_web_search
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
expose:
|
expose:
|
||||||
- "3000"
|
- "3000"
|
||||||
@@ -12,9 +12,9 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- my-app-network
|
- my-app-network
|
||||||
|
|
||||||
mcp-image-gen:
|
mcp_image_gen:
|
||||||
build: ./image-gen
|
build: ./image_gen
|
||||||
container_name: mcp-image-gen
|
container_name: mcp_image_gen
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
expose:
|
expose:
|
||||||
- "3000"
|
- "3000"
|
||||||
@@ -25,9 +25,9 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- my-app-network
|
- my-app-network
|
||||||
|
|
||||||
mcp-video-gen:
|
mcp_video_gen:
|
||||||
build: ./video-gen
|
build: ./video_gen
|
||||||
container_name: mcp-video-gen
|
container_name: mcp_video_gen
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
expose:
|
expose:
|
||||||
- "3000"
|
- "3000"
|
||||||
|
|||||||
@@ -18,18 +18,18 @@
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /root/workspace/tools/mcp
|
cd /root/workspace/tools/mcp
|
||||||
docker compose up -d --build mcp-image-gen
|
docker compose up -d --build mcp_image_gen
|
||||||
```
|
```
|
||||||
|
|
||||||
服务容器名 `mcp-image-gen`,通过反代暴露为 `https://image-gen.ai.foresh.com/mcp`。
|
服务容器名 `mcp_image_gen`,通过反代暴露为 `https://image-gen.ai.foresh.com/mcp`。
|
||||||
|
|
||||||
直接连容器调试:
|
直接连容器调试:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker exec -it mcp-image-gen sh
|
docker exec -it mcp_image_gen sh
|
||||||
# 或本机
|
# 或本机
|
||||||
curl http://localhost:3000/health
|
curl http://localhost:3000/health
|
||||||
# {"status":"ok","service":"image-gen","sessions":0}
|
# {"status":"ok","service":"image_gen","sessions":0}
|
||||||
```
|
```
|
||||||
|
|
||||||
### MCP 客户端配置
|
### MCP 客户端配置
|
||||||
@@ -41,7 +41,7 @@ curl http://localhost:3000/health
|
|||||||
// Cursor: ~/.cursor/mcp.json
|
// Cursor: ~/.cursor/mcp.json
|
||||||
{
|
{
|
||||||
"mcpServers": {
|
"mcpServers": {
|
||||||
"image-gen": {
|
"image_gen": {
|
||||||
"url": "https://image-gen.ai.foresh.com/mcp",
|
"url": "https://image-gen.ai.foresh.com/mcp",
|
||||||
"headers": {
|
"headers": {
|
||||||
"Authorization": "Bearer <your-zhipu-api-key>"
|
"Authorization": "Bearer <your-zhipu-api-key>"
|
||||||
@@ -59,7 +59,7 @@ curl http://localhost:3000/health
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 工具:generate_image
|
## 工具:image_gen
|
||||||
|
|
||||||
调用智谱图片生成接口,返回图片 URL。
|
调用智谱图片生成接口,返回图片 URL。
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ curl -s -X POST http://localhost:3000/mcp \
|
|||||||
-H "Mcp-Session-Id: $SESSION" \
|
-H "Mcp-Session-Id: $SESSION" \
|
||||||
-d '{"jsonrpc": "2.0", "id": 2, "method": "tools/list"}'
|
-d '{"jsonrpc": "2.0", "id": 2, "method": "tools/list"}'
|
||||||
|
|
||||||
# 4. 调 generate_image
|
# 4. 调 image_gen
|
||||||
curl -s -X POST http://localhost:3000/mcp \
|
curl -s -X POST http://localhost:3000/mcp \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "Accept: application/json, text/event-stream" \
|
-H "Accept: application/json, text/event-stream" \
|
||||||
@@ -180,7 +180,7 @@ curl -s -X POST http://localhost:3000/mcp \
|
|||||||
"id": 3,
|
"id": 3,
|
||||||
"method": "tools/call",
|
"method": "tools/call",
|
||||||
"params": {
|
"params": {
|
||||||
"name": "generate_image",
|
"name": "image_gen",
|
||||||
"arguments": {
|
"arguments": {
|
||||||
"prompt": "一只可爱的小猫咪,坐在阳光明媚的窗台上,背景是蓝天白云",
|
"prompt": "一只可爱的小猫咪,坐在阳光明媚的窗台上,背景是蓝天白云",
|
||||||
"size": "1280x1280"
|
"size": "1280x1280"
|
||||||
@@ -196,7 +196,7 @@ curl -s -X POST http://localhost:3000/mcp \
|
|||||||
## 架构与文件
|
## 架构与文件
|
||||||
|
|
||||||
```
|
```
|
||||||
image-gen/
|
image_gen/
|
||||||
├── Dockerfile # node:22-slim,安装依赖后启动 MCP HTTP server
|
├── Dockerfile # node:22-slim,安装依赖后启动 MCP HTTP server
|
||||||
├── .dockerignore # 排除 node_modules
|
├── .dockerignore # 排除 node_modules
|
||||||
├── package.json # @modelcontextprotocol/sdk + express + zod
|
├── package.json # @modelcontextprotocol/sdk + express + zod
|
||||||
@@ -219,7 +219,7 @@ image-gen/
|
|||||||
const DEFAULT_MODEL = "CogView-3-Flash";
|
const DEFAULT_MODEL = "CogView-3-Flash";
|
||||||
```
|
```
|
||||||
|
|
||||||
修改后 `docker compose up -d --build mcp-image-gen` 即可生效。
|
修改后 `docker compose up -d --build mcp_image_gen` 即可生效。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -244,4 +244,4 @@ A: 漏发了 `Mcp-Session-Id` header,或调 `tools/call` 前没先 `initialize
|
|||||||
A: 智谱签发 URL 默认 24h 左右,详见响应里的 `Expires` 参数。需要长期使用请自行转存到 OSS/S3。
|
A: 智谱签发 URL 默认 24h 左右,详见响应里的 `Expires` 参数。需要长期使用请自行转存到 OSS/S3。
|
||||||
|
|
||||||
**Q: 能否限制 `size` 白名单?**
|
**Q: 能否限制 `size` 白名单?**
|
||||||
A: 当前透传给智谱 API,不做强制校验。如需加白名单,修改 `src/mcp-server.js` 中 `generate_image` 的 `size` schema 即可。
|
A: 当前透传给智谱 API,不做强制校验。如需加白名单,修改 `src/mcp-server.js` 中 `image_gen` 的 `size` schema 即可。
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "mcp-image-gen",
|
"name": "mcp_image_gen",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "MCP server for image generation via Zhipu BigModel CogView-3-Flash",
|
"description": "MCP server for image generation via Zhipu BigModel CogView-3-Flash",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -100,7 +100,7 @@ function extractUrls(data) {
|
|||||||
function buildServer() {
|
function buildServer() {
|
||||||
const server = new McpServer(
|
const server = new McpServer(
|
||||||
{
|
{
|
||||||
name: "image-gen",
|
name: "image_gen",
|
||||||
version: "1.0.0",
|
version: "1.0.0",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -111,7 +111,7 @@ function buildServer() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
server.tool(
|
server.tool(
|
||||||
"image-gen",
|
"image_gen",
|
||||||
"Generate an image from a prompt and return the image URL. Optionally specify size.",
|
"Generate an image from a prompt and return the image URL. Optionally specify size.",
|
||||||
{
|
{
|
||||||
prompt: z
|
prompt: z
|
||||||
@@ -207,7 +207,7 @@ async function startHttp({ port, host }) {
|
|||||||
const sessions = new Map();
|
const sessions = new Map();
|
||||||
|
|
||||||
app.get("/health", (_req, res) => {
|
app.get("/health", (_req, res) => {
|
||||||
res.json({ status: "ok", service: "image-gen", sessions: sessions.size });
|
res.json({ status: "ok", service: "image_gen", sessions: sessions.size });
|
||||||
});
|
});
|
||||||
|
|
||||||
async function handleSessionRequest(req, res) {
|
async function handleSessionRequest(req, res) {
|
||||||
@@ -270,7 +270,7 @@ async function startHttp({ port, host }) {
|
|||||||
|
|
||||||
app.listen(port, host, () => {
|
app.listen(port, host, () => {
|
||||||
console.log(
|
console.log(
|
||||||
`[image-gen] MCP HTTP server listening on http://${host}:${port}/mcp`
|
`[image_gen] MCP HTTP server listening on http://${host}:${port}/mcp`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -283,18 +283,18 @@ async function startStdio() {
|
|||||||
);
|
);
|
||||||
const transport = new StdioServerTransport();
|
const transport = new StdioServerTransport();
|
||||||
await server.connect(transport);
|
await server.connect(transport);
|
||||||
console.error("[image-gen] MCP stdio server started");
|
console.error("[image_gen] MCP stdio server started");
|
||||||
}
|
}
|
||||||
|
|
||||||
const args = parseArgs(process.argv.slice(2));
|
const args = parseArgs(process.argv.slice(2));
|
||||||
if (args.http) {
|
if (args.http) {
|
||||||
startHttp({ port: args.port, host: args.host }).catch((e) => {
|
startHttp({ port: args.port, host: args.host }).catch((e) => {
|
||||||
console.error("[image-gen] failed to start http server:", e);
|
console.error("[image_gen] failed to start http server:", e);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
startStdio().catch((e) => {
|
startStdio().catch((e) => {
|
||||||
console.error("[image-gen] failed to start stdio server:", e);
|
console.error("[image_gen] failed to start stdio server:", e);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -19,18 +19,18 @@
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /root/workspace/tools/mcp
|
cd /root/workspace/tools/mcp
|
||||||
docker compose up -d --build mcp-video-gen
|
docker compose up -d --build mcp_video_gen
|
||||||
```
|
```
|
||||||
|
|
||||||
服务容器名 `mcp-video-gen`,通过反代暴露为 `https://video-gen.ai.foresh.com/mcp`。
|
服务容器名 `mcp_video_gen`,通过反代暴露为 `https://video-gen.ai.foresh.com/mcp`。
|
||||||
|
|
||||||
直接连容器调试:
|
直接连容器调试:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker exec -it mcp-video-gen sh
|
docker exec -it mcp_video_gen sh
|
||||||
# 或本机
|
# 或本机
|
||||||
curl http://localhost:3000/health
|
curl http://localhost:3000/health
|
||||||
# {"status":"ok","service":"video-gen","sessions":0}
|
# {"status":"ok","service":"video_gen","sessions":0}
|
||||||
```
|
```
|
||||||
|
|
||||||
### MCP 客户端配置
|
### MCP 客户端配置
|
||||||
@@ -42,7 +42,7 @@ curl http://localhost:3000/health
|
|||||||
// Cursor: ~/.cursor/mcp.json
|
// Cursor: ~/.cursor/mcp.json
|
||||||
{
|
{
|
||||||
"mcpServers": {
|
"mcpServers": {
|
||||||
"video-gen": {
|
"video_gen": {
|
||||||
"url": "https://video-gen.ai.foresh.com/mcp",
|
"url": "https://video-gen.ai.foresh.com/mcp",
|
||||||
"headers": {
|
"headers": {
|
||||||
"Authorization": "Bearer <your-zhipu-api-key>"
|
"Authorization": "Bearer <your-zhipu-api-key>"
|
||||||
@@ -60,14 +60,14 @@ curl http://localhost:3000/health
|
|||||||
|
|
||||||
| 工具 | 作用 | 同步/异步 |
|
| 工具 | 作用 | 同步/异步 |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `generate_video` | 提交一个视频生成任务,立刻返回 `task_id` | 同步(仅提交) |
|
| `video_gen` | 提交一个视频生成任务,立刻返回 `task_id` | 同步(仅提交) |
|
||||||
| `query_video` | 用 `task_id` 拉一次当前结果 | 同步(单次查询,不轮询) |
|
| `query_video` | 用 `task_id` 拉一次当前结果 | 同步(单次查询,不轮询) |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 上传图片:POST /upload
|
## 上传图片:POST /upload
|
||||||
|
|
||||||
供 AI 临时上传本地图片、拿到 URL 后喂给 `generate_video.image_url`。**不走 MCP、不走鉴权**,仅依赖内网隔离(`my-app-network`)+ 反代层控制访问。
|
供 AI 临时上传本地图片、拿到 URL 后喂给 `video_gen.image_url`。**不走 MCP、不走鉴权**,仅依赖内网隔离(`my-app-network`)+ 反代层控制访问。
|
||||||
|
|
||||||
### 配置
|
### 配置
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ environment:
|
|||||||
| 变量 | 默认 | 说明 |
|
| 变量 | 默认 | 说明 |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `PUBLIC_BASE_URL` | `http://localhost:3000` | 返回 `url` 字段里拼接的对外 base URL |
|
| `PUBLIC_BASE_URL` | `http://localhost:3000` | 返回 `url` 字段里拼接的对外 base URL |
|
||||||
| `UPLOAD_DIR` | `/tmp/video-gen-uploads` | 磁盘存储目录(容器内临时) |
|
| `UPLOAD_DIR` | `/tmp/video_gen_uploads` | 磁盘存储目录(容器内临时) |
|
||||||
| `UPLOAD_TTL_HOURS` | `24` | 超过该小时数的文件会在启动时和每小时被自动删除 |
|
| `UPLOAD_TTL_HOURS` | `24` | 超过该小时数的文件会在启动时和每小时被自动删除 |
|
||||||
|
|
||||||
### 接口
|
### 接口
|
||||||
@@ -104,7 +104,7 @@ file: <二进制图片文件>
|
|||||||
|---|---|
|
|---|---|
|
||||||
| 最大体积 | 8MB(智谱 `image_url` 上限5MB,留余量) |
|
| 最大体积 | 8MB(智谱 `image_url` 上限5MB,留余量) |
|
||||||
| 白名单 content-type | `image/png`、`image/jpeg`、`image/jpg` |
|
| 白名单 content-type | `image/png`、`image/jpeg`、`image/jpg` |
|
||||||
| 存储位置 | 容器内 `/tmp/video-gen-uploads/`(`UPLOAD_DIR` 可覆盖) |
|
| 存储位置 | 容器内 `/tmp/video_gen_uploads/`(`UPLOAD_DIR` 可覆盖) |
|
||||||
| 持久化 | **不持久化**。容器重启即丢,请尽快消费 URL |
|
| 持久化 | **不持久化**。容器重启即丢,请尽快消费 URL |
|
||||||
| 过期清理 | 启动时 + 每小时一次删除 `>UPLOAD_TTL_HOURS` 的文件,默认 24h |
|
| 过期清理 | 启动时 + 每小时一次删除 `>UPLOAD_TTL_HOURS` 的文件,默认 24h |
|
||||||
| 鉴权 | 无 |
|
| 鉴权 | 无 |
|
||||||
@@ -121,11 +121,11 @@ file: <二进制图片文件>
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
返回的 `url` 可直接作为 `generate_video.image_url` 使用。
|
返回的 `url` 可直接作为 `video_gen.image_url` 使用。
|
||||||
|
|
||||||
### 反代路由
|
### 反代路由
|
||||||
|
|
||||||
反代需要额外暴露两条路由到 `mcp-video-gen:3000`:
|
反代需要额外暴露两条路由到 `mcp_video_gen:3000`:
|
||||||
|
|
||||||
- `POST /upload` → `/upload`
|
- `POST /upload` → `/upload`
|
||||||
- `GET /uploads/*` → `/uploads/*`
|
- `GET /uploads/*` → `/uploads/*`
|
||||||
@@ -137,13 +137,13 @@ curl -F "file=@/tmp/cat.png" https://video-gen.ai.foresh.com/upload
|
|||||||
# {"url":"https://video-gen.ai.foresh.com/uploads/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.png", ...}
|
# {"url":"https://video-gen.ai.foresh.com/uploads/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.png", ...}
|
||||||
|
|
||||||
# 然后把 url 喂给 MCP:
|
# 然后把 url 喂给 MCP:
|
||||||
# tool: generate_video
|
# tool: video_gen
|
||||||
# args: { image_url: "https://video-gen.ai.foresh.com/uploads/xxx.png", prompt: "..." }
|
# args: { image_url: "https://video-gen.ai.foresh.com/uploads/xxx.png", prompt: "..." }
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 工具:generate_video
|
## 工具:video_gen
|
||||||
|
|
||||||
提交一个视频生成任务,支持**文生视频**和**图生视频**。`prompt` 为**必填**;图生视频另传 `image_url`(两者都传也行,此时 prompt 会附加为运动/动作描述)。
|
提交一个视频生成任务,支持**文生视频**和**图生视频**。`prompt` 为**必填**;图生视频另传 `image_url`(两者都传也行,此时 prompt 会附加为运动/动作描述)。
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ curl -F "file=@/tmp/cat.png" https://video-gen.ai.foresh.com/upload
|
|||||||
|
|
||||||
| 名称 | 类型 | 必填 | 说明 |
|
| 名称 | 类型 | 必填 | 说明 |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| `task_id` | string | ✅ | `generate_video` 返回的 `id` |
|
| `task_id` | string | ✅ | `video_gen` 返回的 `id` |
|
||||||
|
|
||||||
### 返回
|
### 返回
|
||||||
|
|
||||||
@@ -235,7 +235,7 @@ Token 仅在每次 tool call 时从 header 读取,不写入任何存储、不
|
|||||||
|
|
||||||
```
|
```
|
||||||
1. 如果手头是【本地文件】:先调 POST {PUBLIC_BASE_URL}/upload 拿到 url,再进第 2 步
|
1. 如果手头是【本地文件】:先调 POST {PUBLIC_BASE_URL}/upload 拿到 url,再进第 2 步
|
||||||
2. 调用 generate_video({ prompt, image_url?, size?, with_audio? })
|
2. 调用 video_gen({ prompt, image_url?, size?, with_audio? })
|
||||||
3. 拿到 task_id → 等待若干秒(建议 2~5 秒)
|
3. 拿到 task_id → 等待若干秒(建议 2~5 秒)
|
||||||
4. 调用 query_video({ task_id })
|
4. 调用 query_video({ task_id })
|
||||||
- 若 PROCESSING → 等一会再调
|
- 若 PROCESSING → 等一会再调
|
||||||
@@ -243,7 +243,7 @@ Token 仅在每次 tool call 时从 header 读取,不写入任何存储、不
|
|||||||
- 若 FAIL → 展示错误信息,结束
|
- 若 FAIL → 展示错误信息,结束
|
||||||
```
|
```
|
||||||
|
|
||||||
> `generate_video` 的 tool description 里已经嵌入了完整 curl 上传命令,AI 一看就知道怎么传本地图片。
|
> `video_gen` 的 tool description 里已经嵌入了完整 curl 上传命令,AI 一看就知道怎么传本地图片。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -300,7 +300,7 @@ curl -s -X POST http://localhost:3000/mcp \
|
|||||||
"id": 3,
|
"id": 3,
|
||||||
"method": "tools/call",
|
"method": "tools/call",
|
||||||
"params": {
|
"params": {
|
||||||
"name": "generate_video",
|
"name": "video_gen",
|
||||||
"arguments": {
|
"arguments": {
|
||||||
"prompt": "A cat is playing with a ball.",
|
"prompt": "A cat is playing with a ball.",
|
||||||
"size": "1920x1080",
|
"size": "1920x1080",
|
||||||
@@ -344,7 +344,7 @@ curl -o cat.png https://video-gen.ai.foresh.com/uploads/xxx.png
|
|||||||
## 架构与文件
|
## 架构与文件
|
||||||
|
|
||||||
```
|
```
|
||||||
video-gen/
|
video_gen/
|
||||||
├── Dockerfile # node:22-slim,安装依赖后启动 MCP HTTP server
|
├── Dockerfile # node:22-slim,安装依赖后启动 MCP HTTP server
|
||||||
├── .dockerignore # 排除 node_modules
|
├── .dockerignore # 排除 node_modules
|
||||||
package.json # @modelcontextprotocol/sdk + express + multer
|
package.json # @modelcontextprotocol/sdk + express + multer
|
||||||
@@ -360,7 +360,7 @@ package.json # @modelcontextprotocol/sdk + express + multer
|
|||||||
- **AI 可见 vs AI 不可见**:
|
- **AI 可见 vs AI 不可见**:
|
||||||
- AI 只看到 `prompt / image_url / size / with_audio`
|
- AI 只看到 `prompt / image_url / size / with_audio`
|
||||||
- `model / quality / fps / watermark_enabled` 全部由 HTTP header 注入,避免 AI 误传或被诱导调高价档
|
- `model / quality / fps / watermark_enabled` 全部由 HTTP header 注入,避免 AI 误传或被诱导调高价档
|
||||||
- **异步语义暴露给 AI**:服务端不做轮询,`generate_video` 只提交、`query_video` 只查一次。AI 自主决定节奏
|
- **异步语义暴露给 AI**:服务端不做轮询,`video_gen` 只提交、`query_video` 只查一次。AI 自主决定节奏
|
||||||
- **服务端自动 `request_id`**:每次提交服务端生成一个 UUID 作为智谱 `request_id`,便于日志关联,但不暴露给 AI
|
- **服务端自动 `request_id`**:每次提交服务端生成一个 UUID 作为智谱 `request_id`,便于日志关联,但不暴露给 AI
|
||||||
- **上传接口与 MCP 走同一进程**:额外 `POST /upload` + `GET /uploads/*` 不走 MCP、不鉴权,靠内网隔离;`PUBLIC_BASE_URL` 环境变量控制返回 URL 的拼接 host,AI 看到的 tool description 启动时拼接进真实地址,避免 AI 自由发挥
|
- **上传接口与 MCP 走同一进程**:额外 `POST /upload` + `GET /uploads/*` 不走 MCP、不鉴权,靠内网隔离;`PUBLIC_BASE_URL` 环境变量控制返回 URL 的拼接 host,AI 看到的 tool description 启动时拼接进真实地址,避免 AI 自由发挥
|
||||||
- **上传过期清理**:启动时 + 每小时一次删除 `mtime > UPLOAD_TTL_HOURS` 的文件,避免磁盘被不消费的上传堆满;清理 timer 用 `unref()` 不阻塞进程退出
|
- **上传过期清理**:启动时 + 每小时一次删除 `mtime > UPLOAD_TTL_HOURS` 的文件,避免磁盘被不消费的上传堆满;清理 timer 用 `unref()` 不阻塞进程退出
|
||||||
@@ -372,7 +372,7 @@ package.json # @modelcontextprotocol/sdk + express + multer
|
|||||||
const DEFAULT_MODEL = "cogvideox-flash";
|
const DEFAULT_MODEL = "cogvideox-flash";
|
||||||
```
|
```
|
||||||
|
|
||||||
修改后 `docker compose up -d --build mcp-video-gen` 即可生效。
|
修改后 `docker compose up -d --build mcp_video_gen` 即可生效。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -388,7 +388,7 @@ A: 智谱签发 URL 默认 24h 左右。需要在收到后及时转存到自己
|
|||||||
A: 这些是技术档位,与成本/单价挂钩。让 AI 自主挑 `quality=quality + fps=60` 会爆账号预算。改成 header 由部署方注入更可控。
|
A: 这些是技术档位,与成本/单价挂钩。让 AI 自主挑 `quality=quality + fps=60` 会爆账号预算。改成 header 由部署方注入更可控。
|
||||||
|
|
||||||
**Q: 能否限制 `size` 白名单?**
|
**Q: 能否限制 `size` 白名单?**
|
||||||
A: 当前透传给智谱 API,不做强制校验。如需加白名单,修改 `src/mcp-server.js` 中 `generate_video` 的 `size` schema 即可。
|
A: 当前透传给智谱 API,不做强制校验。如需加白名单,修改 `src/mcp-server.js` 中 `video_gen` 的 `size` schema 即可。
|
||||||
|
|
||||||
**Q: 报错 `Missing valid Mcp-Session-Id`?**
|
**Q: 报错 `Missing valid Mcp-Session-Id`?**
|
||||||
A: 漏发了 `Mcp-Session-Id` header,或调 `tools/call` 前没先 `initialize`。
|
A: 漏发了 `Mcp-Session-Id` header,或调 `tools/call` 前没先 `initialize`。
|
||||||
@@ -400,7 +400,7 @@ A: 可以。`/async-result/{id}` 是幂等的读接口,并发无副作用。
|
|||||||
A: 不需要。Model header 在每次 `tools/call` 都从当前请求读取。
|
A: 不需要。Model header 在每次 `tools/call` 都从当前请求读取。
|
||||||
|
|
||||||
**Q: 上传的图片多久过期?**
|
**Q: 上传的图片多久过期?**
|
||||||
A: 容器重启即丢(本服务不持久化)。请在上传后立刻把返回的 `url` 喂给 `generate_video.image_url`。URL 本身只有可访问性,不受单独 TTL 限制;但容器一旦重启,该文件物理消失,URL 变 404。
|
A: 容器重启即丢(本服务不持久化)。请在上传后立刻把返回的 `url` 喂给 `video_gen.image_url`。URL 本身只有可访问性,不受单独 TTL 限制;但容器一旦重启,该文件物理消失,URL 变 404。
|
||||||
|
|
||||||
**Q: `PUBLIC_BASE_URL` 不设会怎样?**
|
**Q: `PUBLIC_BASE_URL` 不设会怎样?**
|
||||||
A: fallback 到 `http://localhost:3000`,AI 拿到的 curl 是 `http://localhost:3000/upload`。外网访问不到。本机调试无所谓,生产请显式设置。
|
A: fallback 到 `http://localhost:3000`,AI 拿到的 curl 是 `http://localhost:3000/upload`。外网访问不到。本机调试无所谓,生产请显式设置。
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "mcp-video-gen",
|
"name": "mcp_video_gen",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "MCP server for video generation via Zhipu BigModel cogvideox-flash (text-to-video / image-to-video, async)",
|
"description": "MCP server for video generation via Zhipu BigModel cogvideox-flash (text-to-video / image-to-video, async)",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -32,7 +32,7 @@ function resolvePublicBaseUrl({ port, host }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 上传文件存储目录:容器内临时目录,服务重启即丢(你明确要求)
|
// 上传文件存储目录:容器内临时目录,服务重启即丢(你明确要求)
|
||||||
const UPLOAD_DIR = process.env.UPLOAD_DIR || "/tmp/video-gen-uploads";
|
const UPLOAD_DIR = process.env.UPLOAD_DIR || "/tmp/video_gen_uploads";
|
||||||
const UPLOAD_PATH_PREFIX = "/uploads"; // 对外的 URL 路径前缀
|
const UPLOAD_PATH_PREFIX = "/uploads"; // 对外的 URL 路径前缀
|
||||||
const UPLOAD_MAX_BYTES = 8 * 1024 * 1024; // 8MB(智谱 image_url 上限 5MB,留余量)
|
const UPLOAD_MAX_BYTES = 8 * 1024 * 1024; // 8MB(智谱 image_url 上限 5MB,留余量)
|
||||||
const UPLOAD_ALLOWED_MIME = new Set([
|
const UPLOAD_ALLOWED_MIME = new Set([
|
||||||
@@ -56,7 +56,7 @@ async function cleanupUploads({ now = Date.now(), dir = UPLOAD_DIR } = {}) {
|
|||||||
entries = await fs.promises.readdir(dir);
|
entries = await fs.promises.readdir(dir);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e && e.code === "ENOENT") return { kept: 0, removed: 0, errors: 0 };
|
if (e && e.code === "ENOENT") return { kept: 0, removed: 0, errors: 0 };
|
||||||
console.error(`[video-gen] cleanup: readdir failed: ${e.message}`);
|
console.error(`[video_gen] cleanup: readdir failed: ${e.message}`);
|
||||||
return { kept: 0, removed: 0, errors: 1 };
|
return { kept: 0, removed: 0, errors: 1 };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ async function cleanupUploads({ now = Date.now(), dir = UPLOAD_DIR } = {}) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e && e.code === "ENOENT") return;
|
if (e && e.code === "ENOENT") return;
|
||||||
errors++;
|
errors++;
|
||||||
console.error(`[video-gen] cleanup: ${name}: ${e.message}`);
|
console.error(`[video_gen] cleanup: ${name}: ${e.message}`);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -233,7 +233,7 @@ async function queryAsyncResult({ token, id }) {
|
|||||||
function buildServer({ publicBaseUrl }) {
|
function buildServer({ publicBaseUrl }) {
|
||||||
const server = new McpServer(
|
const server = new McpServer(
|
||||||
{
|
{
|
||||||
name: "video-gen",
|
name: "video_gen",
|
||||||
version: "1.0.0",
|
version: "1.0.0",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -245,9 +245,9 @@ function buildServer({ publicBaseUrl }) {
|
|||||||
|
|
||||||
const uploadUrl = `${publicBaseUrl}/upload`;
|
const uploadUrl = `${publicBaseUrl}/upload`;
|
||||||
|
|
||||||
// ---------- 工具 1:video-gen ----------
|
// ---------- 工具 1:video_gen ----------
|
||||||
server.tool(
|
server.tool(
|
||||||
"video-gen",
|
"video_gen",
|
||||||
`Submit a video generation task (text-to-video or image-to-video).
|
`Submit a video generation task (text-to-video or image-to-video).
|
||||||
Returns the task_id immediately; poll the result later with query_video.
|
Returns the task_id immediately; poll the result later with query_video.
|
||||||
prompt is required. Add image_url for image-to-video.
|
prompt is required. Add image_url for image-to-video.
|
||||||
@@ -364,7 +364,7 @@ Uploaded files live in container temp storage and are discarded on restart — d
|
|||||||
task_id: z
|
task_id: z
|
||||||
.string()
|
.string()
|
||||||
.min(1)
|
.min(1)
|
||||||
.describe("The task id returned by video-gen."),
|
.describe("The task id returned by video_gen."),
|
||||||
},
|
},
|
||||||
async (args, extra) => {
|
async (args, extra) => {
|
||||||
const headers = extra?.requestInfo?.headers;
|
const headers = extra?.requestInfo?.headers;
|
||||||
@@ -451,7 +451,7 @@ async function startHttp({ port, host }) {
|
|||||||
app.use(express.json({ limit: "2mb" }));
|
app.use(express.json({ limit: "2mb" }));
|
||||||
|
|
||||||
const publicBaseUrl = resolvePublicBaseUrl({ port, host });
|
const publicBaseUrl = resolvePublicBaseUrl({ port, host });
|
||||||
console.log(`[video-gen] PUBLIC_BASE_URL = ${publicBaseUrl}`);
|
console.log(`[video_gen] PUBLIC_BASE_URL = ${publicBaseUrl}`);
|
||||||
|
|
||||||
// ===== /upload:接收图片,返回 URL(不走 MCP)=====
|
// ===== /upload:接收图片,返回 URL(不走 MCP)=====
|
||||||
// 磁盘存储:保证 UPLOAD_DIR 存在(容器内临时,重启即丢)
|
// 磁盘存储:保证 UPLOAD_DIR 存在(容器内临时,重启即丢)
|
||||||
@@ -461,20 +461,20 @@ async function startHttp({ port, host }) {
|
|||||||
cleanupUploads()
|
cleanupUploads()
|
||||||
.then((r) =>
|
.then((r) =>
|
||||||
console.log(
|
console.log(
|
||||||
`[video-gen] startup cleanup: kept=${r.kept} removed=${r.removed} errors=${r.errors} ttl=${UPLOAD_TTL_HOURS}h`
|
`[video_gen] startup cleanup: kept=${r.kept} removed=${r.removed} errors=${r.errors} ttl=${UPLOAD_TTL_HOURS}h`
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.catch((e) => console.error(`[video-gen] startup cleanup failed: ${e.message}`));
|
.catch((e) => console.error(`[video_gen] startup cleanup failed: ${e.message}`));
|
||||||
const cleanupTimer = setInterval(() => {
|
const cleanupTimer = setInterval(() => {
|
||||||
cleanupUploads()
|
cleanupUploads()
|
||||||
.then((r) => {
|
.then((r) => {
|
||||||
if (r.removed > 0 || r.errors > 0) {
|
if (r.removed > 0 || r.errors > 0) {
|
||||||
console.log(
|
console.log(
|
||||||
`[video-gen] periodic cleanup: kept=${r.kept} removed=${r.removed} errors=${r.errors}`
|
`[video_gen] periodic cleanup: kept=${r.kept} removed=${r.removed} errors=${r.errors}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((e) => console.error(`[video-gen] periodic cleanup failed: ${e.message}`));
|
.catch((e) => console.error(`[video_gen] periodic cleanup failed: ${e.message}`));
|
||||||
}, UPLOAD_CLEANUP_INTERVAL_MS);
|
}, UPLOAD_CLEANUP_INTERVAL_MS);
|
||||||
cleanupTimer.unref(); // 不阻止进程退出
|
cleanupTimer.unref(); // 不阻止进程退出
|
||||||
|
|
||||||
@@ -530,7 +530,7 @@ async function startHttp({ port, host }) {
|
|||||||
const sessions = new Map();
|
const sessions = new Map();
|
||||||
|
|
||||||
app.get("/health", (_req, res) => {
|
app.get("/health", (_req, res) => {
|
||||||
res.json({ status: "ok", service: "video-gen", sessions: sessions.size });
|
res.json({ status: "ok", service: "video_gen", sessions: sessions.size });
|
||||||
});
|
});
|
||||||
|
|
||||||
async function handleSessionRequest(req, res) {
|
async function handleSessionRequest(req, res) {
|
||||||
@@ -593,7 +593,7 @@ async function startHttp({ port, host }) {
|
|||||||
|
|
||||||
app.listen(port, host, () => {
|
app.listen(port, host, () => {
|
||||||
console.log(
|
console.log(
|
||||||
`[video-gen] MCP HTTP server listening on http://${host}:${port}/mcp`
|
`[video_gen] MCP HTTP server listening on http://${host}:${port}/mcp`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -606,18 +606,18 @@ async function startStdio() {
|
|||||||
);
|
);
|
||||||
const transport = new StdioServerTransport();
|
const transport = new StdioServerTransport();
|
||||||
await server.connect(transport);
|
await server.connect(transport);
|
||||||
console.error("[video-gen] MCP stdio server started");
|
console.error("[video_gen] MCP stdio server started");
|
||||||
}
|
}
|
||||||
|
|
||||||
const args = parseArgs(process.argv.slice(2));
|
const args = parseArgs(process.argv.slice(2));
|
||||||
if (args.http) {
|
if (args.http) {
|
||||||
startHttp({ port: args.port, host: args.host }).catch((e) => {
|
startHttp({ port: args.port, host: args.host }).catch((e) => {
|
||||||
console.error("[video-gen] failed to start http server:", e);
|
console.error("[video_gen] failed to start http server:", e);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
startStdio().catch((e) => {
|
startStdio().catch((e) => {
|
||||||
console.error("[video-gen] failed to start stdio server:", e);
|
console.error("[video_gen] failed to start stdio server:", e);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# web-search-free
|
# web_search
|
||||||
|
|
||||||
免费网页搜索 MCP server 的本地重构版(上游开源实现:[@sheep233_/dsh-web-search-free](https://github.com/sheep-programmer/dsh-web-search-free),MIT)。
|
免费网页搜索 MCP server 的本地重构版(上游开源实现:[@sheep233_/dsh-web-search-free](https://github.com/sheep-programmer/dsh-web-search-free),MIT)。
|
||||||
|
|
||||||
@@ -35,8 +35,8 @@ MCP 端点:
|
|||||||
|
|
||||||
## Docker
|
## Docker
|
||||||
|
|
||||||
`docker-compose.yml` 中的 `mcp-web-search-free` 服务直接构建本目录,Dockerfile 已改为拷贝源码启动(不再有 `npm install -g`)。
|
`docker-compose.yml` 中的 `mcp_web_search` 服务直接构建本目录,Dockerfile 已改为拷贝源码启动(不再有 `npm install -g`)。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker compose build mcp-web-search-free && docker compose up -d mcp-web-search-free
|
docker compose build mcp_web_search && docker compose up -d mcp_web_search
|
||||||
```
|
```
|
||||||
@@ -13,7 +13,7 @@ export const PARALLEL_MCP_URL = 'https://search.parallel.ai/mcp';
|
|||||||
/** Exa 免费 MCP 端点(匿名可用;EXA_API_KEY 可提升限额)。 */
|
/** Exa 免费 MCP 端点(匿名可用;EXA_API_KEY 可提升限额)。 */
|
||||||
export const EXA_MCP_URL = 'https://mcp.exa.ai/mcp';
|
export const EXA_MCP_URL = 'https://mcp.exa.ai/mcp';
|
||||||
|
|
||||||
const USER_AGENT = 'web-search-free/1.0.0';
|
const USER_AGENT = 'web_search/1.0.0';
|
||||||
/** 单次上游搜索请求的超时,避免远端挂起拖死 MCP 请求。 */
|
/** 单次上游搜索请求的超时,避免远端挂起拖死 MCP 请求。 */
|
||||||
const REQUEST_TIMEOUT_MS = Number(process.env.SEARCH_TIMEOUT_MS ?? 30_000);
|
const REQUEST_TIMEOUT_MS = Number(process.env.SEARCH_TIMEOUT_MS ?? 30_000);
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
import { parallelSearch, exaSearch } from './core.js';
|
import { parallelSearch, exaSearch } from './core.js';
|
||||||
|
|
||||||
export const SERVER_NAME = 'dsh-web-search-free';
|
export const SERVER_NAME = 'web_search';
|
||||||
export const VERSION = '1.0.0';
|
export const VERSION = '1.0.0';
|
||||||
const DEFAULT_PROTOCOL = '2025-03-26';
|
const DEFAULT_PROTOCOL = '2025-03-26';
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "web-search-free",
|
"name": "web_search",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Free web search tool. Uses Parallel by default or Exa as fallback.",
|
"description": "Free web search tool. Uses Parallel by default or Exa as fallback.",
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"web-search-mcp": "server.js"
|
"web_search": "server.js"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
*
|
*
|
||||||
* ## 双传输
|
* ## 双传输
|
||||||
* - **stdio**(默认):`node server.js`
|
* - **stdio**(默认):`node server.js`
|
||||||
* - `claude mcp add web-search -- node <路径>/server.js`
|
* - `claude mcp add web_search -- node <路径>/server.js`
|
||||||
* - **HTTP/SSE**(监听端口):`node server.js --http --port 3000 --host 0.0.0.0`
|
* - **HTTP/SSE**(监听端口):`node server.js --http --port 3000 --host 0.0.0.0`
|
||||||
* - 兼容 Streamable HTTP(`POST /`)与老式 SSE(`GET /sse` + `POST /messages`)
|
* - 兼容 Streamable HTTP(`POST /`)与老式 SSE(`GET /sse` + `POST /messages`)
|
||||||
* - `GET /` 或 `GET /health` 返回服务信息,可做健康检查
|
* - `GET /` 或 `GET /health` 返回服务信息,可做健康检查
|
||||||
@@ -108,7 +108,7 @@ function runHttp(host, port) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
server.listen(port, host, () => {
|
server.listen(port, host, () => {
|
||||||
process.stdout.write(`[web-search-mcp] HTTP/SSE listening on http://${host}:${port} (MCP: POST /, GET /sse + POST /messages)\n`);
|
process.stdout.write(`[web_search] HTTP/SSE listening on http://${host}:${port} (MCP: POST /, GET /sse + POST /messages)\n`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user