本项目是一个 MCP (Model Context Protocol) 服务器实现,可借助 Replicate 的 black-forest-labs/flux-schnell 模型生成图像。它既适合与 Cursor 的 MCP 功能搭配使用,也能和其他 MCP 客户端兼容。
克隆仓库。
安装依赖:
npm install
将你的 Replicate API 令牌直接在 src/imageService.ts 中更新 apiToken 常量:
// 在这里直接添加您的 API 令牌,因为环境变量在 Cursor 中不易设置
const apiToken = "your-replicate-api-token-here";
⚠️ 重要提示
如果使用 Claude,请在根目录创建一个
.env文件,并将 API 令牌设置为:
REPLICATE_API_TOKEN=your-replicate-api-token-here
然后构建项目:
npm run build
与 Cursor 一起使用时:
node ./path/to/dist/server.js。| 参数名称 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
prompt |
string | 是 | - | 文本提示,用于生成图像 |
output_dir |
string | 是 | - | 服务器上的保存图像目录路径 |
go_fast |
boolean | 否 | false | 开启更快的生成模式 |
megapixels |
string | 否 | "1" | 分辨率质量("1","2","4") |
num_outputs |
number | 否 | 1 | 要生成的图像数量(1 - 4) |
aspect_ratio |
string | 否 | "1:1" | 宽高比("1:1","4:3","16:9") |
output_format |
string | 否 | "webp" | 图像格式("webp","png","jpeg") |
output_quality |
number | 否 | 80 | 压缩质量(1 - 100) |
num_inference_steps |
number | 否 | 4 | 去噪化步骤数量(4 - 20) |
{
"prompt": "黑色森林蛋糕,上面写着 'FLUX SCHNELL'",
"output_dir": "/var/output/images",
"filename": "black_forest_cake",
"output_format": "webp",
"go_fast": true,
"megapixels": "1",
"num_outputs": 2,
"aspect_ratio": "1:1"
}
{
"status": "success",
"message": "图像已生成并保存到指定目录。",
"data": {
"filename": "black_forest_cake.png",
"size": "2.5 MB",
"dimensions": "1920x1080"
}
}
该代码受 MIT License 保护。