🎨 图像生成MCP服务器
   ](https://www.npmjs.com/package/@stonezone/imagegen-mcp)
一个强大的模型上下文协议(MCP)服务器,使AI助手(Claude、Gemini、Cody)能够使用多个提供者生成和操纵图像。 开始免费生成图像 使用Pollings.ai-不需要API密钥!
✨ 特性
🎨 多个AI图像提供商
| 供应商 | 成本 | API密钥 | 质量 | 速度 | 注释 |
|---|---|---|---|---|---|
| 投票.ai | ✅ 免费 | ❌ 无 | ⭐⭐⭐⭐ | ⚡ 快速 | 推荐 -无限使用! |
| 抱抱脸 | ✅ 免费等级 | ✅ 必填 | ⭐⭐⭐⭐⭐ | 🐢 慢 | FLUX和稳定扩散模型 |
| 开放人工智能 | 💰 已付 | ✅ 必填 | ⭐⭐⭐⭐⭐ | ⚡ 快速 | GPT-Image-1(DALL-E) |
🛠️ 图像处理工具
- 调整大小:使用宽高比控制缩放图像
- 格式转换:png↔ JPEG图像↔ Webp↔ 天赋异禀
- 元数据抽取:尺寸、格式、文件大小
- 自定义尺寸:任何尺寸(512x512、1920x1080等)
🔧 支持平台
- ✅ 克劳德桌面
- ✅ 克劳德代码(CLI)
- ✅ 源代码图科迪(VS代码)
- ✅ Gemini CLI
- ✅ 任何兼容MCP的客户端
______________________________________________________________________
📦 安装
选项1:NPM(推荐)
# Install globally
npm install -g @stonezone/imagegen-mcp
# Or install locally in your project
npm install @stonezone/imagegen-mcp选项2:Python(pip)
# Clone the repository
git clone https://github.com/stonezone/imagegenMCP.git
cd imagegenMCP
# Install with pip
pip install -e .
# Or for development
pip install -e ".[dev]"选项3:直接从GitHub
pip install git+https://github.com/stonezone/imagegenMCP.git______________________________________________________________________
🔑 API密钥(可选)
Pollations.ai(默认-免费!)
不需要API密钥! 这是默认提供程序,安装后立即工作。
拥抱脸(可选-免费等级)
- 在以下网址创建免费帐户 huggingface.co
- 获取您的令牌: huggingface.co/settings/tokens
- 设置环境变量:
export HUGGINGFACE_API_KEY="your-token-here"OpenAI(可选-付费)
- 从获取API密钥 platform.openai.com
- 设置环境变量:
export OPENAI_API_KEY="your-api-key-here"______________________________________________________________________
⚙️ 配置
🖥️ 克劳德桌面
地点: ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)或 %APPDATA%\Claude\claude_desktop_config.json (Windows)
NPM安装:
{
"mcpServers": {
"imagegen": {
"command": "npx",
"args": ["@stonezone/imagegen-mcp"]
}
}
}Python安装:
{
"mcpServers": {
"imagegen": {
"command": "python",
"args": ["/absolute/path/to/imagegenMCP/src/imagegen_mcp/server.py"]
}
}
}使用API密钥(可选):
{
"mcpServers": {
"imagegen": {
"command": "npx",
"args": ["@stonezone/imagegen-mcp"],
"env": {
"OPENAI_API_KEY": "sk-...",
"HUGGINGFACE_API_KEY": "hf_..."
}
}
}
}重新启动克劳德桌面 编辑配置文件后。
______________________________________________________________________
💻 克劳德代码(CLI)
地点: .claudecode/config.json 在您的项目或 ~/.config/claudecode/config.json 全球范围内
{
"mcpServers": {
"imagegen": {
"command": "npx",
"args": ["@stonezone/imagegen-mcp"]
}
}
}或者在shell中设置环境变量:
export OPENAI_API_KEY="sk-..."
export HUGGINGFACE_API_KEY="hf_..."______________________________________________________________________
🤖 源代码图科迪(VS代码)
地点: VS代码设置(JSON)
按 Cmd+Shift+P (Mac)或 Ctrl+Shift+P (Windows/Linux),键入“首选项:打开用户设置(JSON)”
{
"openctx.providers": {
"https://openctx.org/npm/@openctx/provider-modelcontextprotocol": {
"imagegen": {
"command": "npx",
"args": ["@stonezone/imagegen-mcp"],
"env": {
"OPENAI_API_KEY": "sk-...",
"HUGGINGFACE_API_KEY": "hf_..."
}
}
}
}
}注: MCP通过Cody的代理上下文收集工作,而不是通过@提及。
______________________________________________________________________
🔮 Gemini CLI
地点: ~/.gemini/settings.json (全球)或 .gemini/settings.json (项目)
首先,安装Gemini CLI:
npm install -g @google/gemini-cli@latest然后配置MCP服务器:
{
"mcpServers": {
"imagegen": {
"command": "npx",
"args": ["@stonezone/imagegen-mcp"],
"env": {
"OPENAI_API_KEY": "sk-...",
"HUGGINGFACE_API_KEY": "hf_..."
}
}
}
}______________________________________________________________________
🚀 用法示例
生成图像(免费!)
Generate an image of a serene Hawaiian beach at sunset with palm trees*默认情况下使用Pollinations.ai——完全免费!*
指定提供者
Generate using huggingface: a futuristic cyberpunk cityscape
Generate using openai: a professional headshot photo
Generate using pollinations with turbo model: a cute cat自定义尺寸
Generate a 1920x1080 desktop wallpaper of mountains
Generate a 512x768 portrait of a sunset
Create a square 1024x1024 image of abstract art图像处理
Resize that image to 512x512 pixels
Convert the image to JPEG format
What are the dimensions and format of this image?
Resize to width 800 maintaining aspect ratio高级选项
Generate with seed 12345: a landscape (reproducible results with Pollinations)
Generate using huggingface model stabilityai/stable-diffusion-xl-base-1.0: a portrait______________________________________________________________________
🔧 可用工具
generate_image
使用AI模型生成图像。
参数:
prompt(必填):要生成的图像的描述provider(可选):"pollinations"(默认,免费),"openai","huggingface"size(可选):图像尺寸。,"1024x1024","512x768","1920x1080"model(可选):
- 授粉: "flux" (默认)或 "turbo" - HuggingFace:型号ID类似 "black-forest-labs/FLUX.1-dev"
seed(可选):随机种子可重复性(仅限授粉)output_filename(可选):自定义文件名
退货:
{
"image_path": "/path/to/generated_images/image.png",
"url": "https://...",
"size": "1024x1024",
"prompt": "...",
"provider": "pollinations"
}resize_image
调整现有图像的大小。
参数:
image_path(必填):图像路径width(可选):目标宽度(像素)height(可选):目标高度(像素)maintain_aspect(可选):保持纵横比(默认值:true)output_path(可选):自定义输出路径
convert_image_format
将图像转换为不同格式。
参数:
image_path(必需):源图像的路径target_format(必填):"PNG","JPEG","WEBP",或"GIF"quality(可选):有损格式的质量(1-100,默认值:95)output_path(可选):自定义输出路径
get_image_info
获取图像元数据。
参数:
image_path(必填):图像路径
______________________________________________________________________
🧪 测试
运行测试套件:
pytest直接生成测试图像:
python -c "
import asyncio
from pathlib import Path
from src.imagegen_mcp.server import generate_image_pollinations
async def test():
result = await generate_image_pollinations(
prompt='a red circle on white background',
size='256x256'
)
print(f'Success! Image saved to: {result[\"image_path\"]}')
asyncio.run(test())
"______________________________________________________________________
🐛 故障排除
入门指南
- ✅ 先尝试Pollinations.ai -无需设置,完全免费
- 如果您看到错误,请检查您使用的是哪个提供商
- 请确保已安装Python 3.10+:
python --version
提供商特定问题
Pollations.ai(推荐)
- ✅ 不需要API密钥
- ✅ 无费率限制
- ✅ 非常快速可靠
- ❌ 如果失败,请检查您的互联网连接
抱抱脸
- 获取免费代币: huggingface.co/settings/tokens
- 免费套餐每月有信用额度
- 冷启动: 首次请求可能需要1-2分钟(模型加载)
- 如果你得到
503 Service Unavailable,请稍候,然后重试 - 错误
402 Payment Required:您已超过每月免费积分
开放人工智能
- 需要来自的付费API密钥 platform.openai.com
- 检查您的API配额和账单
- 提示必须遵循OpenAI的内容政策
- 型号名称:
gpt-image-1
常见问题
“未找到命令”或“未找到模块”
# For NPM installation
npm install -g @stonezone/imagegen-mcp
# For Python installation
pip install -e .“权限被拒绝”
# Make sure the server script is executable
chmod +x src/imagegen_mcp/server.py图像未保存
# Check the generated_images directory exists and is writable
mkdir -p generated_images
chmod 755 generated_imagesPython版本问题
# Check Python version (must be 3.10+)
python --version
# Use python3 if needed
python3 --version______________________________________________________________________
📁 项目结构
imagegenMCP/
├── src/
│ └── imagegen_mcp/
│ ├── __init__.py
│ └── server.py # Main MCP server
├── bin/
│ └── imagegen-mcp.js # NPM executable wrapper
├── generated_images/ # Output directory (auto-created)
├── tests/ # Test suite
├── package.json # NPM package config
├── pyproject.toml # Python package config
├── README.md
├── LICENSE
└── CHANGELOG.md______________________________________________________________________
🔄 更新中
NPM安装
npm update -g @stonezone/imagegen-mcpPython安装
cd imagegenMCP
git pull
pip install -e .______________________________________________________________________
🛠️ 发展
设置开发环境
git clone https://github.com/stonezone/imagegenMCP.git
cd imagegenMCP
pip install -e ".[dev]"代码质量工具
# Format code
black src/
# Lint code
ruff check src/
# Type checking
mypy src/
# Run tests
pytest贡献
- 分叉存储库
- 创建要素分支:
git checkout -b feature/amazing-feature - 进行更改
- 运行测试和梳理
- 承诺:
git commit -m 'Add amazing feature' - 推:
git push origin feature/amazing-feature - 打开拉取请求
______________________________________________________________________
🗺️ 路线图
- \[x\] Pollations.ai提供商(免费!)
- \[x\] HuggingFace推论API
- \[x\] OpenAI GPT-Image-1
- \[x\] NPM包分发
- \[x\] 多平台支持
- \[\]稳定AI集成
- \[\]Replicate.com提供商
- \[\]图像到图像的转换
- \[\]批量图像生成
- \[\]图像放大
- \[\]高级操作(裁剪、旋转、过滤器)
- \[\]提示模板库
- \[\]图像缓存系统
______________________________________________________________________
📊 比较:为什么选择MCP服务器?
| 功能 | 此服务器 | 替代方案 |
|---|---|---|
| 免费提供商 | ✅ Pollations.ai(无限制) | ❌ 通常只支付 |
| 多个供应商 | ✅ 3家供应商 | ⚠️ 通常1 |
| 没有要启动的API密钥 | ✅ 立即工作 | ❌ 需要API密钥 |
| 自定义尺寸 | ✅ 任何尺寸 | ⚠️ 选择有限 |
| 图像处理 | ✅ 调整大小、转换、信息 | ❌ 仅限世代 |
| NPM分布 | ✅ 易于安装 | ⚠️ 手动设置 |
| 多平台 | ✅ 4+平台 | ⚠️ 有限 |
______________________________________________________________________
📄 许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
______________________________________________________________________
👤 作者
扎克·乔丹
______________________________________________________________________
🙏 致谢
______________________________________________________________________
📚 资源
______________________________________________________________________
⭐ 明星历史
如果你觉得这个项目有用,请考虑在GitHub上给它一颗星!它帮助其他人发现项目。
______________________________________________________________________
🤝 支持
- 📫 问题:
- 💬 讨论:
- 📖 文档: 维基
______________________________________________________________________
由以下材料制成❤️ 对于MCP社区
