Generate images using the Together AI API. Supports custom aspect ratios, save paths, and batch generation.
基于 Together AI 的图像生成服务,专门设计用于与 Cursor MCP 服务集成。支持自定义图片宽高比、保存路径等功能,提供高质量图像生成能力。
Python 3.10+
推荐使用 pyenv 管理 Python 版本:
# macOS 安装 pyenv
brew install pyenv
# 安装 Python
pyenv install 3.13.2
pyenv global 3.13.2
uv 是一个快速的 Python 包管理器,需要先安装:
# macOS 安装 uv
brew install uv
# 或者使用 pip 安装
pip install uv
YOUR_API_KEY
git clone https://github.com/chenyeju295/mcp_generate_images.git
cd mcp_generate_images
python3 -m pip install fastmcp requests
出现证书问题可以使用:
python3 -m pip install fastmcp requests --trusted-host pypi.org --trusted-host files.pythonhosted.org --upgrade --force-reinstall --no-cache-dir
tips: 需确保安装成功,否则配置MCP 服务会报红。
在 mcp_server.py
中修改 TOGETHER_API_KEY
:
TOGETHER_API_KEY = "your_api_key_here" # 替换为你的 Together AI API 密钥
在 mcp_server.py
中可以修改以下配置:
CONFIG = {
"api": {
"url": "https://api.together.xyz/v1/images/generations",
"model": "black-forest-labs/FLUX.1-schnell-Free",
"timeout": 60,
"max_retries": 3,
"retry_delay": 5
},
"image": {
"max_width": 1024,
"max_height": 1024,
"default_width": 1024,
"default_height": 1024,
"default_steps": 3,
"max_batch_size": 4
},
"output": {
"base_folder": "你的默认保存路径",
"allowed_extensions": [".png", ".jpg", ".jpeg"],
"default_extension": ".png"
}
}
开发模式运行(带调试界面):
uv run --with fastmcp fastmcp dev /Users/username/Documents/mcp_generate_images/mcp_server.py
在 Cursor 的 MCP 配置中添加:
{
"mcpServers": {
"generate_images": {
"command": "uv",
"args": [
"run",
"--with",
"fastmcp",
"fastmcp",
"run",
"/Users/chenyeju/Documents/github/mcp_generate_images/mcp_server.py"
]
}
}
}
图像生成工具支持以下参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
prompt | 字符串 | 是 | 图片生成提示词,建议不超过500字符 |
file_name | 字符串 | 是 | 保存的文件名(不含路径,如果没有后缀则默认使用.png) |
save_folder | 字符串 | 是 | 保存目录的绝对路径 |
aspect_ratio | 字符串 | 否 | 图片的宽高比,支持 '1:1', '4:3', '16:9', '3:4', '9:16'。默认为'1:1' |
steps | 数字 | 否 | 生成的推理/采样步数,支持值1-4,默认为3。步数越多质量越高但耗时越长 |
生成一张宽高比为16:9的风景图片,使用步数2以加快生成速度:
generate_image(
prompt="A beautiful mountain landscape with sunset",
file_name="landscape.png",
save_folder="/Users/username/Documents/images",
aspect_ratio="16:9",
steps=2
)
如果遇到问题,请检查:
错误信息 | 可能原因 | 解决方案 |
---|---|---|
"未能生成图片: API 请求超时" | 网络问题或请求耗时过长 | 尝试减少steps值,或使用更简单的提示词 |
"未能生成图片: API 调用频率受限" | Together API频率限制 | 等待几分钟后再试 |
"未能生成图片: API 认证失败" | API密钥无效 | 检查并更新API密钥 |
"没有权限保存图片到..." | 目录权限问题 | 确保目录存在且有写入权限 |
"steps参数必须在1-4之间" | steps参数超出范围 | 使用1-4之间的值 |
"不支持的宽高比" | 使用了不支持的宽高比 | 使用支持的宽高比:'1:1', '4:3', '16:9', '3:4', '9:16' |
Tool platform by IBM to build, test and deploy tools for any data source
A server for CodeFuse-CGM, a graph-integrated large language model designed for repository-level software engineering tasks.
Manage Google Apps Script projects, including creation, editing, deployment, and execution. Requires Google Cloud credentials for authentication.
Bring the full power of BrowserStack’s Test Platform to your AI tools, making testing faster and easier for every developer and tester on your team.
Execute any LLM-generated code in the YepCode secure and scalable sandbox environment and create your own MCP tools using JavaScript or Python, with full support for NPM and PyPI packages
MCP server for text-to-graphql, integrates with Claude Desktop and Cursor.
Manages penetration testing reports and vulnerabilities via a REST API.
Connects to the React Native application debugger to retrieve console logs from Metro.
The definitive Vibe Coder's sanity check MCP server: Prevents cascading errors by calling a "Vibe-check" agent to ensure alignment and prevent scope creep
A comprehensive MCP server for tooling interactions(40+) and resource accessibility(60+) plus many useful prompts to interact with Algorand Blockchain.