复制MCP服务器
轻量级MCP服务器,用于使用Replicate的官方模型生成和编辑AI图像。
作者 过度
概述
这是一个专门为图像生成工作流设计的专注、最小的MCP服务器。与功能齐全的Replicate MCP服务器不同,此服务器仅公开Flux、SDXL和Seedream等官方型号的图像生成和编辑所需的内容。
推荐用法:提前告诉你的助手你喜欢哪种型号以及任何具体的设置(质量、纵横比、风格)。这减少了工具调用,并更快地获得更好的结果。
系统提示添加示例:
For image generation, use black-forest-labs/flux-schnell with 16:9 aspect ratio unless I specify otherwise.通知
此repo以两种方式工作:
- 作为一个 节点/HONO服务器 用于本地工作流
- 作为一个 Cloudflare工作人员 用于远程交互
特性
- 搜索模型 --查找具有完整输入模式的图像生成模型
- 生成图像 --运行预测并获取过期URL的结果
- 轻量级 --只有2个工具
- API密钥认证 --简单的Bearer令牌或X-Api-Key标头身份验证
- 双运行时 --Node.js/Bun或Cloudflare Workers
设计原则
- LLM友好:两个聚焦工具,而不是1:1 API镜像
- 模式感知:搜索返回输入模式,以便代理知道确切的参数
- 安全:复制存储为机密的API密钥,客户端使用单独的承载令牌
- 清晰的反馈:模型参数、生成时间、降价就绪输出
______________________________________________________________________
安装
跑步方式(选一种)
- 地方发展 --带有承载令牌身份验证的标准设置
- Cloudflare Worker(牧者开发) --本地工人测试
- Cloudflare Worker(部署) --远程生产
______________________________________________________________________
1.地方发展——快速起步
- 获取复制API令牌:
- 访问 replicate.com/account/api-tokes - 创建新的API令牌 - 复制令牌(以开头 r8_)
- 配置环境:
cd replicate-mcp
bun install
cp env.example .env编辑 .env:
PORT=3000
# Generate with: openssl rand -hex 32
API_KEY=your-random-auth-token
# Replicate API Token (from replicate.com)
REPLICATE_API_TOKEN=r8_your_token_here- 运行:
bun dev
# MCP: http://127.0.0.1:3000/mcp克劳德桌面/光标:
{
"mcpServers": {
"replicate": {
"command": "npx",
"args": ["mcp-remote", "http://localhost:3000/mcp", "--transport", "http-only"],
"env": { "NO_PROXY": "127.0.0.1,localhost" }
}
}
}______________________________________________________________________
2.Cloudflare Worker(本地开发人员)
bun x wrangler dev --local | cat创建 .dev.vars 关于地方秘密:
API_KEY=your_random_auth_token
REPLICATE_API_TOKEN=r8_your_replicate_token端点: http://127.0.0.1:8787/mcp
______________________________________________________________________
3.Cloudflare Worker(部署)
- 为会话存储创建KV命名空间:
bun x wrangler kv:namespace create TOKENS输出将显示:
Add the following to your wrangler.toml:
[[kv_namespaces]]
binding = "TOKENS"
id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"- 更新
wrangler.toml使用您的KV命名空间ID:
[[kv_namespaces]]
binding = "TOKENS"
id = "your-kv-namespace-id-from-step-1"- 设置秘密:
# Generate a random token for client authentication
openssl rand -hex 32
bun x wrangler secret put API_KEY
# Paste the generated token when prompted
# Replicate API token
bun x wrangler secret put REPLICATE_API_TOKEN
# Paste your Replicate token when prompted- 部署:
bun x wrangler deploy端点: https://..workers.dev/mcp
______________________________________________________________________
客户端配置
爱丽丝应用程序
添加为MCP服务器:
- 网址:
https://your-worker.workers.dev/mcp - 类型:
streamable-http - 头球
Authorization: Bearer
克劳德桌面/光标(本地服务器)
{
"mcpServers": {
"replicate": {
"command": "npx",
"args": ["mcp-remote", "http://localhost:3000/mcp", "--transport", "http-only"],
"env": { "NO_PROXY": "127.0.0.1,localhost" }
}
}
}克劳德桌面/光标(Cloudflare Worker)
{
"mcpServers": {
"replicate": {
"command": "npx",
"args": ["mcp-remote", "https://your-worker.workers.dev/mcp", "--transport", "http-only"]
}
}
}MCP检查员(快速测试)
bunx @modelcontextprotocol/inspector
# Connect to: http://localhost:3000/mcp (local) or https://your-worker.workers.dev/mcp (remote)______________________________________________________________________
工具
search_models
搜索模型并获取其输入模式。最多返回5个具有完整参数详细信息的模型。
// Input
{
query: string; // Model name, task, or keywords
}
// Output
### owner/name
Description of the model
Runs: 1,234,567
Input parameters:
- prompt [REQUIRED]: string
- aspect_ratio: enum: ["1:1", "16:9", "9:16"] = "1:1"
- num_outputs: integer = 1
...例子:
{ "query": "flux" }generate_image
运行图像生成模型并等待结果。
// Input
{
model: string; // "owner/name" format
input: Record; // Model-specific parameters
}
// Output
## Image Generated in 2.3s
Model: black-forest-labs/flux-schnell
Display the image to the user using markdown syntax:

Note: URLs expire in 1 hour.常见输入模式:
// Text-to-image
{
"model": "black-forest-labs/flux-schnell",
"input": {
"prompt": "a cat on the moon",
"aspect_ratio": "16:9"
}
}
// Image editing
{
"model": "black-forest-labs/flux-kontext-pro",
"input": {
"prompt": "change the sky to sunset",
"image": "https://example.com/source.jpg"
}
}______________________________________________________________________
热门型号
| 型号 | 速度 | 最适合 |
|---|---|---|
black-forest-labs/flux-schnell | ~2s | 快速生成,草稿 |
black-forest-labs/flux-dev | ~10s | 更高质量,更详细 |
bytedance/seedream-4 | ~5s | 多功能、多参考 |
black-forest-labs/flux-kontext-pro | ~8s | 使用文本编辑图像 |
纵横比指南
| 比率 | 用例 |
|---|---|
1:1 | 肖像、图标、个人资料图片 |
16:9 | 风景、电影、桌面壁纸 |
9:16 | 移动壁纸、故事、垂直内容 |
4:3 | 经典照片格式 |
21:9 | 超宽电影 |
______________________________________________________________________
HTTP端点
| 端点 | 方法 | 目的 |
|---|---|---|
/mcp | 发布 | MCP JSON-RPC 2.0 |
/health | GET | 健康检查 |
______________________________________________________________________
环境变量
Node.js(.env)
| 变量 | 必填 | 描述 |
|---|---|---|
REPLICATE_API_TOKEN | ✓ | 复制API令牌(r8\_…) |
API_KEY | ✓ | MCP客户端的认证令牌 |
PORT | 服务器端口(默认值:3000) | |
HOST | 服务器主机(默认值:127.0.0.1) |
Cloudflare Workers(wrangler.toml+机密)
牧马人。汤姆瓦尔斯:
[vars]
MCP_TITLE = "Replicate MCP Server"
MCP_VERSION = "1.0.0"秘密(通过设置 wrangler secret put):
API_KEY--客户端的随机身份验证令牌REPLICATE_API_TOKEN-复制API令牌
KV命名空间:
[[kv_namespaces]]
binding = "TOKENS"
id = "your-kv-namespace-id"______________________________________________________________________
发展
bun dev # Start with hot reload
bun run typecheck # TypeScript check
bun run lint # Lint code
bun run build # Production build
bun start # Run production______________________________________________________________________
建筑
src/
├── config/
│ └── metadata.ts # Tool descriptions
├── tools/
│ ├── search-models.tool.ts # Search with schema enrichment
│ └── generate-image.tool.ts # Run predictions
├── services/
│ └── api/
│ └── replicate.service.ts # Replicate API client
├── http/
│ ├── app.ts # Hono server
│ └── middlewares/
│ └── auth.ts # API key validation
├── index.ts # Node.js entry
└── worker.ts # Workers entry______________________________________________________________________
故障排除
| 问题 | 解决方案 |
|---|---|
| 401未经授权 | 检查 API_KEY 已设置,客户端发送 Authorization: Bearer |
| “REPLICATE_API_TOKEN未配置” | 设置机密: wrangler secret put REPLICATE_API_TOKEN |
| “模型格式无效” | 使用 owner/name 格式(例如。, black-forest-labs/flux-schnell) |
| “缺少必需的参数” | 调用 search_models 查看精确的输入模式 |
| “超出速率限制” | 请稍候,然后重试 |
| “图像URL已过期” | URL将在1小时后过期--重新生成 |
| KV命名空间错误 | 运行 wrangler kv:namespace create TOKENS 并更新wrangler.toml |
调试
MCP检验员测试:
bunx @modelcontextprotocol/inspector
# Connect to your endpoint and test tools检查Worker日志:
wrangler tail______________________________________________________________________
许可证
麻省理工学院
