Skip to main content

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

配置指南

身份验证

  1. 阿里云 API 密钥 (必需): 用于调用百炼平台生图能力。

    export DASHSCOPE_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxx"
    
  2. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bailian_imagegen_mcp_edited-0.2.2.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bailian_imagegen_mcp_edited-0.2.2-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file bailian_imagegen_mcp_edited-0.2.2.tar.gz.

File metadata

  • Download URL: bailian_imagegen_mcp_edited-0.2.2.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

Hashes for bailian_imagegen_mcp_edited-0.2.2.tar.gz
Algorithm Hash digest
SHA256 44ef7b1a9c31d57133d65343a7390221b7ee1bd7d277e9308542690dc9da7a99
MD5 0c1d598c3914f0e15bd39434d07b5fc5
BLAKE2b-256 3960cc87f18729d37597488757b3a94b4d288f5baa08565817dba3a6516ecba3

See more details on using hashes here.

File details

Details for the file bailian_imagegen_mcp_edited-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: bailian_imagegen_mcp_edited-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 18.3 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

Hashes for bailian_imagegen_mcp_edited-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 514f3373133f3b7454b2a7e0396a069506b381150d76ca589379098c7cb1f92c
MD5 dd91abccc9e5303cfc41b43eeab6bddd
BLAKE2b-256 6680b2b9ca85ef1fd5d5f7d4f649e899e3f1d897d57dbe468a80844ca8235f8a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page