此 MCP 服务器借助 Replicate Flux 模型,为用户提供强大的图像生成功能,助力用户轻松实现各种图像创作需求。
此 MCP 服务器使用 Replicate Flux 模型提供图像生成功能。下面将为你详细介绍安装、设置以及使用的步骤。
通过 Smithery 可自动为 Claude Desktop 安装图像生成 MCP 服务器,操作命令如下:
npx -y @smithery/cli install @GongRzhe/Image-Generation-MCP-Server --client claude
直接从 npm 使用包而无需本地安装,npx 会自行处理相关操作:
# 无需安装,npx 自行处理
若你需要进行本地安装,可参考以下命令:
# 全局安装
npm install -g @gongrzhe/image-gen-server
# 或者本地安装
npm install @gongrzhe/image-gen-server
你需要编辑 Claude Desktop 的配置文件,不同系统的配置文件路径如下:
~/Library/Application Support/Claude/claude_desktop_config.json此方法可直接从 npm 运行服务器,无需本地文件,配置示例如下:
{
"mcpServers": {
"image-gen": {
"command": "npx",
"args": ["@gongrzhe/image-gen-server"],
"env": {
"REPLICATE_API_TOKEN": "your-replicate-api-token",
"MODEL": "alternative-model-name"
},
"disabled": false,
"autoApprove": []
}
}
}
如果你选择了本地安装,配置示例如下:
{
"mcpServers": {
"image-gen": {
"command": "node",
"args": ["/path/to/image-gen-server/build/index.js"],
"env": {
"REPLICATE_API_TOKEN": "your-replicate-api-token",
"MODEL": "alternative-model-name"
},
"disabled": false,
"autoApprove": []
}
}
}
获取 Replicate API Token 的步骤如下:
your-replicate-api-token。REPLICATE_API_TOKEN(必填):用于身份验证的 Replicate API token。MODEL(选填):指定要使用的模型,默认为 "stable-diffusion"。该工具可生成图像并返回 URL 列表。
{
"prompt": "输入你的提示词,例如:'一只飞翔的蓝鸟'",
"negative_prompt": "可选,输入负面提示词",
"width": 512,
"height": 512,
"samples": 1,
"num_images": 1
}
const response = await fetch('http://localhost:4000/api/generate-image', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
prompt: "一只飞翔的蓝鸟",
negative_prompt: "",
width: 512,
height: 512,
samples: 1,
num_images: 1
})
});
const data = await response.json();
console.log(data.urls); // 输出 URL 列表
此项目遵循 MIT License 进行开源。