Aliyun Bailian Image Generation MCP Server
Project description
阿里云百炼生图 MCP 服务器
一个 Model Context Protocol 服务器,提供阿里云百炼平台的图像生成和编辑功能。该服务器使LLM能够调用阿里云百炼API来生成、编辑图像,支持多种图像分辨率、多模型选择(Qwen, Z-Image, Wan系列)和自定义参数。
最新功能:
- 全异步架构:完美适配 MCP SSE 协议,不会阻塞服务器心跳。
- 直接返回结果:无需二次查询,生图请求直接返回图片 URL。
- 多模型支持:支持 Qwen-Image, Wan (万相) 等最新模型。
- 安全保护:支持 Bearer Token 鉴权,保护 HTTP/SSE 服务不被非法访问。
可用工具
generate_image - 生成图像 (同步返回)
使用文本提示词生成图像,请求等待生成完成后直接返回图片链接。
- 必需:
prompt - 可选:
model(默认 z-image-turbo),size(默认 1024*1024),prompt_extend,watermark,negative_prompt
image_edit_generation - 编辑图像 (同步返回)
基于现有图像和文本提示生成新的编辑版本。
- 必需:
prompt,image(URL) - 可选:
model(默认 qwen-image-edit-plus),negative_prompt
list_image_models - 获取模型列表
返回支持的图像模型列表及其详细说明(包括简介、分辨率限制等)。
快速开始
方式 1: 使用 uvx 直接运行 (推荐)
如果已安装 uv,无需下载代码即可运行:
# 需设置环境变量 DASHSCOPE_API_KEY
uvx --from bailian-imagegen-mcp-edited bailian-mcp-server
方式 2: 本地安装运行
# 安装包
pip install bailian-imagegen-mcp-edited
# 运行
bailian-mcp-server
配置指南
身份验证
-
阿里云 API 密钥 (必需): 用于调用百炼平台生图能力。
export DASHSCOPE_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxx"
-
MCP 访问密钥 (可选,建议在 HTTP 模式下开启): 用于保护 MCP 服务本身的安全性。开启后,客户端需在 Header 中提供
Authorization: Bearer <token>。export MCP_ACCESS_TOKEN="your_custom_secret_token"
1. Claude.app 配置 (桌面版)
编辑配置文件 (macOS: ~/Library/Application Support/Claude/claude_desktop_config.json, Windows: %APPDATA%\Claude\claude_desktop_config.json):
{
"mcpServers": {
"bailian-image": {
"command": "uvx",
"args": [
"--from",
"bailian-imagegen-mcp-edited",
"bailian-mcp-server"
],
"env": {
"DASHSCOPE_API_KEY": "sk-your-real-api-key"
}
}
}
}
2. 魔搭社区 (ModelScope) 部署配置
如果您在魔搭 MCP 广场创建服务,请使用以下配置:
- 托管类型: 可托管部署
- 服务配置:
{ "mcpServers": { "bailian-image": { "command": "uvx", "args": [ "--from", "bailian-imagegen-mcp-edited", "bailian-mcp-server" ], "env": { "DASHSCOPE_API_KEY": "sk-your-real-api-key" } } } }
3. VS Code 配置 (Cline/Roo 等插件)
在项目根目录创建 .vscode/mcp.json:
{
"mcp": {
"servers": {
"bailian-image": {
"command": "uvx",
"args": [
"--from",
"bailian-imagegen-mcp-edited",
"bailian-mcp-server"
],
"env": {
"DASHSCOPE_API_KEY": "sk-your-real-api-key"
}
}
}
}
}
开发与调试
如果您从源码运行:
# 安装依赖
pip install -e .
# 1. Stdio 模式运行 (默认,本地使用)
python bailian_mcpserver.py
# 2. HTTP/SSE 模式运行 (用于服务器远程部署)
# 如果设置了 MCP_ACCESS_TOKEN,服务将受到鉴权保护
python bailian_mcpserver.py --http --port 8000
远程连接配置
当您在服务器部署并开启鉴权后,其他 MCP 客户端连接时需要配置 Header:
{
"mcpServers": {
"bailian-image-remote": {
"command": "curl",
"args": [
"-H", "Authorization: Bearer your_custom_secret_token",
"http://your-server-ip:8000/mcp"
]
}
}
}
(注意:具体客户端的配置方式可能有所不同,部分网关支持在 URL 后接参数或通过特定的环境变量传递 Token)
调试
使用 MCP Inspector 进行调试:
npx @modelcontextprotocol/inspector python bailian_mcpserver.py
许可证
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bailian_imagegen_mcp_edited-0.1.7.tar.gz.
File metadata
- Download URL: bailian_imagegen_mcp_edited-0.1.7.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6eb2e477e21717a5008a9e52d34346d6f94bead94e8edd0b4d7166069e75c2d
|
|
| MD5 |
f91c72cfb6398c3c323733dac06a6d7a
|
|
| BLAKE2b-256 |
b78689cd58de84359e25cfad3562cf4cd749737e55bca08ab934ae3581e4c2ff
|
File details
Details for the file bailian_imagegen_mcp_edited-0.1.7-py3-none-any.whl.
File metadata
- Download URL: bailian_imagegen_mcp_edited-0.1.7-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdccdb67d7a63b943d8cce0e09a924d0f600d783a8f1a5e186655a37ee4b5432
|
|
| MD5 |
9124d2bf02054b0d308a599617816215
|
|
| BLAKE2b-256 |
989e8a38ce6b31edc030e44d3dec3b4c9253cb613e4f93bc8ea139caf42ca907
|