图像生成 MCP 服务器
模型上下文协议 (MCP) 服务器,支持通过 Together AI 使用 Flux.1 Schnell 模型无缝生成高质量图像。该服务器提供标准化接口来指定图像生成参数。
特征
- 由 Flux.1 Schnell 模型提供支持的高质量图像生成
- 支持自定义尺寸(宽度和高度)
- 清除提示验证和 API 问题的错误处理
- 轻松与 MCP 兼容客户端集成
- 可选将图像以 PNG 格式保存到磁盘
安装
或者直接运行:
配置
添加到您的 MCP 服务器配置:
{
"mcpServers": {
"together-image-gen": {
"command": "npx",
"args": ["together-mcp@latest -y"],
"env": {
"TOGETHER_API_KEY": "<API KEY>"
}
}
}
}
用法
服务器提供了一个工具: generate_image
使用generate_image
此工具只有一个必需参数 - 提示符。所有其他参数均为可选参数,如果未提供,则使用合理的默认值。
参数
{
// Required
prompt: string; // Text description of the image to generate
// Optional with defaults
model?: string; // Default: "black-forest-labs/FLUX.1-schnell-Free"
width?: number; // Default: 1024 (min: 128, max: 2048)
height?: number; // Default: 768 (min: 128, max: 2048)
steps?: number; // Default: 1 (min: 1, max: 100)
n?: number; // Default: 1 (max: 4)
response_format?: string; // Default: "b64_json" (options: ["b64_json", "url"])
image_path?: string; // Optional: Path to save the generated image as PNG
}
最小请求示例
仅需要提示:
{
"name": "generate_image",
"arguments": {
"prompt": "A serene mountain landscape at sunset"
}
}
包含图像保存的完整请求示例
覆盖所有默认值并指定保存图像的路径:
{
"name": "generate_image",
"arguments": {
"prompt": "A serene mountain landscape at sunset",
"width": 1024,
"height": 768,
"steps": 20,
"n": 1,
"response_format": "b64_json",
"model": "black-forest-labs/FLUX.1-schnell-Free",
"image_path": "/path/to/save/image.png"
}
}
响应格式
响应将是一个 JSON 对象,包含以下内容:
{
"id": string, // Generation ID
"model": string, // Model used
"object": "list",
"data": [
{
"timings": {
"inference": number // Time taken for inference
},
"index": number, // Image index
"b64_json": string // Base64 encoded image data (if response_format is "b64_json")
// OR
"url": string // URL to generated image (if response_format is "url")
}
]
}
如果提供了 image_path 并且保存成功,则响应将包括保存位置的确认。
默认值
如果请求中未指定,则使用以下默认值:
- 型号:“black-forest-labs/FLUX.1-schnell-Free”
- 宽度:1024
- 高度:768
- 步骤:1
- n:1
- 响应格式:“b64_json”
重要提示
- 仅需要
prompt
参数 - 如果未提供,所有可选参数均使用默认值
- 提供时,参数必须满足其约束(例如宽度/高度范围)
- Base64 响应可能很大 - 对于较大的图像请使用 URL 格式
- 保存图像时,确保指定的目录存在且可写
先决条件
依赖项
{
"@modelcontextprotocol/sdk": "0.6.0",
"axios": "^1.6.7"
}
发展
克隆并构建项目:
git clone https://github.com/manascb1344/together-mcp-server
cd together-mcp-server
npm install
npm run build
可用脚本
npm run build
构建 TypeScript 项目npm run watch
- 观察变化并重建npm run inspector
- 运行 MCP 检查器
贡献
欢迎贡献!请按以下步骤操作:
- 分叉存储库
- 创建新分支 (
feature/my-new-feature
) - 提交你的更改
- 将树枝推到你的叉子上
- 打开拉取请求
您可以通过 GitHub Issues 提交功能请求和错误报告。请先检查现有问题,然后再创建新问题。
对于重大更改,请先打开问题来讨论您提议的更改。
执照
本项目遵循 MIT 许可证。详情请参阅 LICENSE 文件。