# MCP Server Bailian Image
阿里云百炼-通义万相图像生成MCP服务器
## 功能特性
- 🎨 **文生图功能**: 基于通义万相2.1/2.2文生图V2版API
- 🚀 **多模型支持**: 支持wan2.2-t2i-flash、wan2.2-t2i-plus等多种模型
- 🎯 **精确控制**: 支持正向提示词、反向提示词、图像尺寸、生成数量等参数
- ⚡ **同步调用**: 使用DashScope SDK进行同步调用,简化使用流程
- 🔧 **易于集成**: 标准MCP协议,可与支持MCP的AI助手无缝集成
## 安装
### 从PyPI安装
```bash
pip install mcp-server-bailian-image
```
### 从源码安装
```bash
git clone https://github.com/aliyun/mcp-server-bailian-image.git
cd mcp-server-bailian-image
pip install -e .
```
## 配置
### 1. 获取API Key
1. 访问[阿里云百炼控制台](https://bailian.console.aliyun.com/)
2. 创建应用并获取API Key
3. 确保已开通通义万相文生图服务
### 2. 设置环境变量
```bash
# Windows
set DASHSCOPE_API_KEY=your_api_key_here
# Linux/macOS
export DASHSCOPE_API_KEY=your_api_key_here
```
## 使用方法
### 启动MCP服务器
```bash
# 使用uvx启动(推荐)
uvx mcp-server-bailian-image
# 或者直接传入API Key
uvx mcp-server-bailian-image --api-key your_api_key_here
```
### 在Claude Desktop中配置
在Claude Desktop的配置文件中添加以下配置:
```json
{
"mcpServers": {
"bailian-image": {
"command": "uvx",
"args": ["mcp-server-bailian-image"],
"env": {
"DASHSCOPE_API_KEY": "your_api_key_here"
}
}
}
}
```
## 支持的工具
### text2imagev2
基于通义万相文生图V2版API的文生图工具。
**参数说明:**
- `prompt` (必填): 正向提示词,描述期望生成的图像内容
- `negative_prompt` (可选): 反向提示词,描述不希望出现的内容
- `model` (可选): 模型名称,默认为 `wan2.2-t2i-flash`
- `size` (可选): 图像尺寸,默认为 `1024*1024`
- `n` (可选): 生成图片数量,取值范围1-4,默认为1
**支持的模型:**
- `wan2.2-t2i-flash`: 万相2.2极速版(推荐)
- `wan2.2-t2i-plus`: 万相2.2专业版(推荐)
- `wanx2.1-t2i-turbo`: 万相2.1极速版
- `wanx2.1-t2i-plus`: 万相2.1专业版
- `wanx2.0-t2i-turbo`: 万相2.0极速版
**支持的图像尺寸:**
- `1024*1024` (默认)
- `720*1280`
- `1280*720`
- `1024*576`
- `576*1024`
**使用示例:**
```python
# 基础文生图
result = await call_tool("text2imagev2", {
"prompt": "一只坐着的橘黄色的猫,表情愉悦,活泼可爱,逼真准确"
})
# 使用反向提示词
result = await call_tool("text2imagev2", {
"prompt": "雪地,白色小教堂,极光,冬日场景,柔和的光线",
"negative_prompt": "人物",
"model": "wan2.2-t2i-plus",
"size": "1280*720",
"n": 2
})
```
## 错误处理
常见错误及解决方案:
1. **API Key未设置**
```
错误: DASHSCOPE_API_KEY environment variable is required
解决: 设置环境变量或通过命令行参数传入API Key
```
2. **模型不支持**
```
错误: Unsupported model: xxx
解决: 使用支持的模型名称
```
3. **图像尺寸不支持**
```
错误: Unsupported size: xxx
解决: 使用支持的图像尺寸
```
## 开发
### 环境要求
- Python 3.8+
- DashScope SDK
- MCP SDK
### 本地开发
```bash
# 克隆仓库
git clone https://github.com/aliyun/mcp-server-bailian-image.git
cd mcp-server-bailian-image
# 安装依赖
pip install -e .
# 运行测试
python -m pytest
# 启动开发服务器
python -m mcp_server_bailian_image.server
```
## 许可证
MIT License
## 相关链接
- [通义万相文生图V2版API文档](https://help.aliyun.com/zh/model-studio/text-to-image-v2-api-reference)
- [阿里云百炼控制台](https://bailian.console.aliyun.com/)
- [DashScope SDK文档](https://help.aliyun.com/zh/dashscope/)
- [MCP协议文档](https://github.com/modelcontextprotocol/specification)
## 支持
如有问题或建议,请提交[Issue](https://github.com/aliyun/mcp-server-bailian-image/issues)。
Raw data
{
"_id": null,
"home_page": null,
"name": "mcp-server-bailian-image",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "mcp, model-context-protocol, aliyun, bailian, tongyi, wanxiang, image, text-to-image, generation, ai, artificial-intelligence, computer-vision",
"author": null,
"author_email": "AliyunBailian <support@aliyun.com>",
"download_url": "https://files.pythonhosted.org/packages/0a/af/ac57ab033edbaa0d64e8dd5a216924da847796f35f4f57df1257be138d05/mcp_server_bailian_image-1.0.4.tar.gz",
"platform": null,
"description": "# MCP Server Bailian Image\n\n\u963f\u91cc\u4e91\u767e\u70bc-\u901a\u4e49\u4e07\u76f8\u56fe\u50cf\u751f\u6210MCP\u670d\u52a1\u5668\n\n## \u529f\u80fd\u7279\u6027\n\n- \ud83c\udfa8 **\u6587\u751f\u56fe\u529f\u80fd**: \u57fa\u4e8e\u901a\u4e49\u4e07\u76f82.1/2.2\u6587\u751f\u56feV2\u7248API\n- \ud83d\ude80 **\u591a\u6a21\u578b\u652f\u6301**: \u652f\u6301wan2.2-t2i-flash\u3001wan2.2-t2i-plus\u7b49\u591a\u79cd\u6a21\u578b\n- \ud83c\udfaf **\u7cbe\u786e\u63a7\u5236**: \u652f\u6301\u6b63\u5411\u63d0\u793a\u8bcd\u3001\u53cd\u5411\u63d0\u793a\u8bcd\u3001\u56fe\u50cf\u5c3a\u5bf8\u3001\u751f\u6210\u6570\u91cf\u7b49\u53c2\u6570\n- \u26a1 **\u540c\u6b65\u8c03\u7528**: \u4f7f\u7528DashScope SDK\u8fdb\u884c\u540c\u6b65\u8c03\u7528\uff0c\u7b80\u5316\u4f7f\u7528\u6d41\u7a0b\n- \ud83d\udd27 **\u6613\u4e8e\u96c6\u6210**: \u6807\u51c6MCP\u534f\u8bae\uff0c\u53ef\u4e0e\u652f\u6301MCP\u7684AI\u52a9\u624b\u65e0\u7f1d\u96c6\u6210\n\n## \u5b89\u88c5\n\n### \u4ecePyPI\u5b89\u88c5\n\n```bash\npip install mcp-server-bailian-image\n```\n\n### \u4ece\u6e90\u7801\u5b89\u88c5\n\n```bash\ngit clone https://github.com/aliyun/mcp-server-bailian-image.git\ncd mcp-server-bailian-image\npip install -e .\n```\n\n## \u914d\u7f6e\n\n### 1. \u83b7\u53d6API Key\n\n1. \u8bbf\u95ee[\u963f\u91cc\u4e91\u767e\u70bc\u63a7\u5236\u53f0](https://bailian.console.aliyun.com/)\n2. \u521b\u5efa\u5e94\u7528\u5e76\u83b7\u53d6API Key\n3. \u786e\u4fdd\u5df2\u5f00\u901a\u901a\u4e49\u4e07\u76f8\u6587\u751f\u56fe\u670d\u52a1\n\n### 2. \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\n\n```bash\n# Windows\nset DASHSCOPE_API_KEY=your_api_key_here\n\n# Linux/macOS\nexport DASHSCOPE_API_KEY=your_api_key_here\n```\n\n## \u4f7f\u7528\u65b9\u6cd5\n\n### \u542f\u52a8MCP\u670d\u52a1\u5668\n\n```bash\n# \u4f7f\u7528uvx\u542f\u52a8\uff08\u63a8\u8350\uff09\nuvx mcp-server-bailian-image\n\n# \u6216\u8005\u76f4\u63a5\u4f20\u5165API Key\nuvx mcp-server-bailian-image --api-key your_api_key_here\n```\n\n### \u5728Claude Desktop\u4e2d\u914d\u7f6e\n\n\u5728Claude Desktop\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a\n\n```json\n{\n \"mcpServers\": {\n \"bailian-image\": {\n \"command\": \"uvx\",\n \"args\": [\"mcp-server-bailian-image\"],\n \"env\": {\n \"DASHSCOPE_API_KEY\": \"your_api_key_here\"\n }\n }\n }\n}\n```\n\n## \u652f\u6301\u7684\u5de5\u5177\n\n### text2imagev2\n\n\u57fa\u4e8e\u901a\u4e49\u4e07\u76f8\u6587\u751f\u56feV2\u7248API\u7684\u6587\u751f\u56fe\u5de5\u5177\u3002\n\n**\u53c2\u6570\u8bf4\u660e\uff1a**\n\n- `prompt` (\u5fc5\u586b): \u6b63\u5411\u63d0\u793a\u8bcd\uff0c\u63cf\u8ff0\u671f\u671b\u751f\u6210\u7684\u56fe\u50cf\u5185\u5bb9\n- `negative_prompt` (\u53ef\u9009): \u53cd\u5411\u63d0\u793a\u8bcd\uff0c\u63cf\u8ff0\u4e0d\u5e0c\u671b\u51fa\u73b0\u7684\u5185\u5bb9\n- `model` (\u53ef\u9009): \u6a21\u578b\u540d\u79f0\uff0c\u9ed8\u8ba4\u4e3a `wan2.2-t2i-flash`\n- `size` (\u53ef\u9009): \u56fe\u50cf\u5c3a\u5bf8\uff0c\u9ed8\u8ba4\u4e3a `1024*1024`\n- `n` (\u53ef\u9009): \u751f\u6210\u56fe\u7247\u6570\u91cf\uff0c\u53d6\u503c\u8303\u56f41-4\uff0c\u9ed8\u8ba4\u4e3a1\n\n**\u652f\u6301\u7684\u6a21\u578b\uff1a**\n\n- `wan2.2-t2i-flash`: \u4e07\u76f82.2\u6781\u901f\u7248\uff08\u63a8\u8350\uff09\n- `wan2.2-t2i-plus`: \u4e07\u76f82.2\u4e13\u4e1a\u7248\uff08\u63a8\u8350\uff09\n- `wanx2.1-t2i-turbo`: \u4e07\u76f82.1\u6781\u901f\u7248\n- `wanx2.1-t2i-plus`: \u4e07\u76f82.1\u4e13\u4e1a\u7248\n- `wanx2.0-t2i-turbo`: \u4e07\u76f82.0\u6781\u901f\u7248\n\n**\u652f\u6301\u7684\u56fe\u50cf\u5c3a\u5bf8\uff1a**\n\n- `1024*1024` (\u9ed8\u8ba4)\n- `720*1280`\n- `1280*720`\n- `1024*576`\n- `576*1024`\n\n**\u4f7f\u7528\u793a\u4f8b\uff1a**\n\n```python\n# \u57fa\u7840\u6587\u751f\u56fe\nresult = await call_tool(\"text2imagev2\", {\n \"prompt\": \"\u4e00\u53ea\u5750\u7740\u7684\u6a58\u9ec4\u8272\u7684\u732b\uff0c\u8868\u60c5\u6109\u60a6\uff0c\u6d3b\u6cfc\u53ef\u7231\uff0c\u903c\u771f\u51c6\u786e\"\n})\n\n# \u4f7f\u7528\u53cd\u5411\u63d0\u793a\u8bcd\nresult = await call_tool(\"text2imagev2\", {\n \"prompt\": \"\u96ea\u5730\uff0c\u767d\u8272\u5c0f\u6559\u5802\uff0c\u6781\u5149\uff0c\u51ac\u65e5\u573a\u666f\uff0c\u67d4\u548c\u7684\u5149\u7ebf\",\n \"negative_prompt\": \"\u4eba\u7269\",\n \"model\": \"wan2.2-t2i-plus\",\n \"size\": \"1280*720\",\n \"n\": 2\n})\n```\n\n## \u9519\u8bef\u5904\u7406\n\n\u5e38\u89c1\u9519\u8bef\u53ca\u89e3\u51b3\u65b9\u6848\uff1a\n\n1. **API Key\u672a\u8bbe\u7f6e**\n ```\n \u9519\u8bef: DASHSCOPE_API_KEY environment variable is required\n \u89e3\u51b3: \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u6216\u901a\u8fc7\u547d\u4ee4\u884c\u53c2\u6570\u4f20\u5165API Key\n ```\n\n2. **\u6a21\u578b\u4e0d\u652f\u6301**\n ```\n \u9519\u8bef: Unsupported model: xxx\n \u89e3\u51b3: \u4f7f\u7528\u652f\u6301\u7684\u6a21\u578b\u540d\u79f0\n ```\n\n3. **\u56fe\u50cf\u5c3a\u5bf8\u4e0d\u652f\u6301**\n ```\n \u9519\u8bef: Unsupported size: xxx\n \u89e3\u51b3: \u4f7f\u7528\u652f\u6301\u7684\u56fe\u50cf\u5c3a\u5bf8\n ```\n\n## \u5f00\u53d1\n\n### \u73af\u5883\u8981\u6c42\n\n- Python 3.8+\n- DashScope SDK\n- MCP SDK\n\n### \u672c\u5730\u5f00\u53d1\n\n```bash\n# \u514b\u9686\u4ed3\u5e93\ngit clone https://github.com/aliyun/mcp-server-bailian-image.git\ncd mcp-server-bailian-image\n\n# \u5b89\u88c5\u4f9d\u8d56\npip install -e .\n\n# \u8fd0\u884c\u6d4b\u8bd5\npython -m pytest\n\n# \u542f\u52a8\u5f00\u53d1\u670d\u52a1\u5668\npython -m mcp_server_bailian_image.server\n```\n\n## \u8bb8\u53ef\u8bc1\n\nMIT License\n\n## \u76f8\u5173\u94fe\u63a5\n\n- [\u901a\u4e49\u4e07\u76f8\u6587\u751f\u56feV2\u7248API\u6587\u6863](https://help.aliyun.com/zh/model-studio/text-to-image-v2-api-reference)\n- [\u963f\u91cc\u4e91\u767e\u70bc\u63a7\u5236\u53f0](https://bailian.console.aliyun.com/)\n- [DashScope SDK\u6587\u6863](https://help.aliyun.com/zh/dashscope/)\n- [MCP\u534f\u8bae\u6587\u6863](https://github.com/modelcontextprotocol/specification)\n\n## \u652f\u6301\n\n\u5982\u6709\u95ee\u9898\u6216\u5efa\u8bae\uff0c\u8bf7\u63d0\u4ea4[Issue](https://github.com/aliyun/mcp-server-bailian-image/issues)\u3002\n",
"bugtrack_url": null,
"license": null,
"summary": "\u963f\u91cc\u4e91\u767e\u70bc-\u901a\u4e49\u4e07\u76f8\u56fe\u50cf\u751f\u6210MCP\u670d\u52a1\u5668",
"version": "1.0.4",
"project_urls": {
"Bug Reports": "https://github.com/aliyun/mcp-server-bailian-image/issues",
"Documentation": "https://help.aliyun.com/zh/model-studio/text-to-image-v2-api-reference",
"Homepage": "https://github.com/aliyun/mcp-server-bailian-image",
"Repository": "https://github.com/aliyun/mcp-server-bailian-image"
},
"split_keywords": [
"mcp",
" model-context-protocol",
" aliyun",
" bailian",
" tongyi",
" wanxiang",
" image",
" text-to-image",
" generation",
" ai",
" artificial-intelligence",
" computer-vision"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "edbcfc62e83f57a0c987ca9de69cc81fafbbbb9781c35ac99977e1e3dd04d49e",
"md5": "7e35e2cb31a0e9c6c15fbd76291b06e5",
"sha256": "275ada9bd1cef02eeedad00ef5ca6deb6f23820d4696a8c75472664813576480"
},
"downloads": -1,
"filename": "mcp_server_bailian_image-1.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7e35e2cb31a0e9c6c15fbd76291b06e5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 13365,
"upload_time": "2025-08-16T15:05:19",
"upload_time_iso_8601": "2025-08-16T15:05:19.083238Z",
"url": "https://files.pythonhosted.org/packages/ed/bc/fc62e83f57a0c987ca9de69cc81fafbbbb9781c35ac99977e1e3dd04d49e/mcp_server_bailian_image-1.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "0aafac57ab033edbaa0d64e8dd5a216924da847796f35f4f57df1257be138d05",
"md5": "c86216148ce549cefc4467b1a4f32fc0",
"sha256": "10df48dfe1305a7bea99b10aa6c77d3166c9f65611e6566e0a7c39ca2f1b3682"
},
"downloads": -1,
"filename": "mcp_server_bailian_image-1.0.4.tar.gz",
"has_sig": false,
"md5_digest": "c86216148ce549cefc4467b1a4f32fc0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 16457,
"upload_time": "2025-08-16T15:05:21",
"upload_time_iso_8601": "2025-08-16T15:05:21.148238Z",
"url": "https://files.pythonhosted.org/packages/0a/af/ac57ab033edbaa0d64e8dd5a216924da847796f35f4f57df1257be138d05/mcp_server_bailian_image-1.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-16 15:05:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "aliyun",
"github_project": "mcp-server-bailian-image",
"github_not_found": true,
"lcname": "mcp-server-bailian-image"
}