Logotipo de ModelScope Qwen-Image

ModelScope Qwen-Image

Comunidad
zym9863

A MCP (Model Context Protocol) server for generating images using ModelScope Qwen-Image model.

Editorzym9863
Repositoriomodelscope-image-mcp
IdiomaPython
Forks
1
Estrellas
2
Herramientas disponibles
0
Tipo de transportestdio
Categorías
LicenciaMIT
Enlaces
  • Conecta herramientas a flujos de trabajo con IA

    ModelScope Qwen-Image ofrece funciones MCP que pueden usar los clientes y agentes de IA compatibles.

  • 0 herramientas disponibles

    Explora a continuación las acciones que se pueden invocar, con sus nombres y descripciones cuando el servidor los proporcione.

  • Configuración lista para copiar

    Usa los ejemplos de instalación para configurar este servidor en tu cliente MCP preferido.

  • Indicadores de interés en el código abierto

    2 estrellas y 1 forks en el repositorio enlazado.

ModelScope Image MCP Server

English | 中文

An MCP (Model Context Protocol) server for generating images via the ModelScope image generation API. This server provides seamless integration with AI assistants, enabling them to create images through natural language prompts with robust async processing and local file management.

IMPORTANT: Earlier drafts of this README mentioned features like returning base64 data, negative prompts, and additional parameters. The current released code (see src/modelscope_image_mcp/server.py) implements a focused minimal feature set: one tool generate_image that submits an async task and saves the resulting image locally. Planned / upcoming features are listed in the roadmap below.

Current Features

  • Asynchronous image generation using ModelScope async task API
  • Periodic task status polling (every 5 seconds, up to 2 minutes)
  • Saves the first generated image to a local file
  • Returns task status and image URL to the MCP client
  • Robust error handling + timeout messaging
  • Simple one-command start with uvx

Environment Variable

The server reads your credential from:

MODELSCOPE_SDK_TOKEN

If it is missing, the server will raise an error. Obtain a token from: https://modelscope.cn/my/myaccesstoken

Set on Windows (cmd):

set MODELSCOPE_SDK_TOKEN=your_token_here

PowerShell:

$env:MODELSCOPE_SDK_TOKEN="your_token_here"

Unix/macOS bash/zsh:

export MODELSCOPE_SDK_TOKEN=your_token_here

Installation & MCP Client Configuration

You can register the server directly in an MCP-compatible client (e.g. Claude Desktop) without a prior manual install thanks to uvx.

Option 1: PyPI (Recommended once published)

jsonc
{
  "mcpServers": {
    "modelscope-image": {
      "command": "uvx",
      "args": ["modelscope-image-mcp"],
      "env": {
        "MODELSCOPE_SDK_TOKEN": "your_token_here"
      }
    }
  }
}

Option 2: Direct from GitHub

jsonc
{
  "mcpServers": {
    "modelscope-image": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/zym9863/modelscope-image-mcp.git",
        "modelscope-image-mcp"
      ],
      "env": {
        "MODELSCOPE_SDK_TOKEN": "your_token_here"
      }
    }
  }
}

Option 3: Local Development Checkout

bash
git clone https://github.com/zym9863/modelscope-image-mcp.git
cd modelscope-image-mcp
uv sync

Then configure MCP client entry using:

jsonc
{
  "mcpServers": {
    "modelscope-image": {
      "command": "uvx",
      "args": ["--from", ".", "modelscope-image-mcp"],
      "env": { "MODELSCOPE_SDK_TOKEN": "your_token_here" }
    }
  }
}

Quick Local Smoke Test

bash
# Run directly (local checkout)
uvx --from . modelscope-image-mcp

When running successfully you should see log lines showing task submission and polling.


## Usage Examples

### Basic Image Generation

```jsonc
{
  "name": "generate_image",
  "arguments": {
    "prompt": "A serene mountain landscape at sunset"
  }
}

Advanced Configuration

jsonc
{
  "name": "generate_image",
  "arguments": {
    "prompt": "A futuristic city with flying cars, cyberpunk style",
    "model": "Qwen/Qwen-Image",
    "size": "1024x1024",
    "output_filename": "cyberpunk_city.png",
    "output_dir": "./generated_images"
  }
}

Creative Prompts

  • Art Style: "in the style of Van Gogh", "watercolor painting", "digital art"
  • Composition: "close-up portrait", "wide-angle landscape", "bird's eye view"
  • Lighting: "dramatic lighting", "golden hour", "studio lighting"
  • Mood: "mysterious atmosphere", "vibrant colors", "minimalist design"

Best Practices

  1. Be Specific: Detailed prompts produce better results than vague ones
  2. Use References: Mention specific art styles, artists, or time periods
  3. Experiment: Try variations of your prompt to find the best result
  4. Organize Outputs: Use descriptive filenames and organized directories
  5. Check Status: Monitor the async task status for long-running generations

generate_image

Creates an image from a text prompt using the ModelScope async API.

Parameters:

  • prompt (string, required): The text description of the desired image
  • model (string, optional, default: Qwen/Qwen-Image): Model name passed to API
  • size (string, optional, default: 1024x1024): Image resolution size, Qwen-Image supports: [64x64,1664x1664]
  • output_filename (string, optional, default: result_image.jpg): Local filename to save the first output image
  • output_dir (string, optional, default: ./outputs): Directory path where the image will be saved

Sample invocation (conceptual JSON sent by MCP client):

jsonc
{
  "name": "generate_image",
  "arguments": {
    "prompt": "A golden cat playing in a garden",
    "size": "1024x1024",
    "output_filename": "cat.jpg",
    "output_dir": "./my_images"
  }
}

Sample textual response payload (returned to the client):

图片生成成功!
提示词: A golden cat playing in a garden
模型: Qwen/Qwen-Image
保存路径: /path/to/my_images/cat.jpg
输出目录: /path/to/my_images
文件名: cat.jpg
图片URL: https://.../generated_image.jpg

Notes:

  • Only the first image URL is used (if multiple are ever returned)
  • If the task fails or times out you receive a descriptive message
  • No base64 data is currently returned (roadmap item)

Internal Flow

  1. Submit async generation request with header X-ModelScope-Async-Mode: true
  2. Poll task endpoint /v1/tasks/{task_id} every 5 seconds (max 120 attempts ~= 2 minutes)
  3. On SUCCEED download first image and save via Pillow (PIL)
  4. Return textual metadata to MCP client
  5. Provide clear error / timeout messages otherwise

Roadmap

Planned enhancements (not yet implemented in server.py):

  • Optional base64 return data
  • Negative prompt & guidance parameters
  • Adjustable polling interval & timeout via arguments
  • Multiple image outputs selection
  • Streaming progress notifications

Development

bash
# Install all (including dev) dependencies
uv sync --dev

# Run server module directly
uv run python -m modelscope_image_mcp.server

# Or via uvx using local source
uvx --from . modelscope-image-mcp

# Run with environment variable
MODELSCOPE_SDK_TOKEN=your_token_here uv run python -m modelscope_image_mcp.server

# Format code (if ruff is configured)
uv run ruff format .

# Lint code (if ruff is configured)
uv run ruff check . --fix

Project Structure

modelscope-image-mcp/
├── src/modelscope_image_mcp/
│   ├── __init__.py
│   └── server.py          # Main MCP server implementation
├── pyproject.toml         # Project configuration and dependencies
├── uv.lock               # Lock file for reproducible builds
├── README.md             # This file
└── README-zh.md         # Chinese documentation

Troubleshooting

SymptomPossible CauseAction
ValueError: 需要设置 MODELSCOPE_SDK_TOKEN 环境变量Token missingExport / set environment variable then restart
图片生成超时Slow model processingRe-run; later we will expose longer timeout argument
网络相关 httpx.TimeoutExceptionConnectivity issuesCheck network / retry
PIL cannot identify image fileInvalid image data receivedTry a different prompt or model
Permission denied when savingOutput directory permissionsCheck write permissions or change output_dir
No such file or directoryOutput directory doesn't existServer will create it automatically, or specify existing path

Changelog

1.0.1

  • Added size parameter support for customizable image resolution
  • Improved image generation with Qwen-Image model resolution range [64x64,1664x1664]
  • Enhanced documentation with size parameter usage examples

1.0.0

  • Major update with improved async handling and output directory support
  • Added configurable output directory parameter
  • Enhanced error handling and logging
  • Updated dependencies to use httpx for better async support
  • Fixed notification_options bug from initial release

0.1.0

  • Initial minimal implementation with async polling & local image save
  • Fixed bug: notification_options previously None causing AttributeError

License

MIT License

Contributing

PRs & issues welcome. Please describe reproduction steps for any failures.

Disclaimer

This is an unofficial integration example. Use at your own risk; abide by ModelScope Terms of Service.

Instalación

TypingMind
Requisitos:

Node.js 18+

{
  "mcpServers": {
    "modelscope-image": {
      "command": "uvx",
      "args": [
        "modelscope-image-mcp"
      ],
      "env": {
        "MODELSCOPE_SDK_TOKEN": "your_token_here"
      }
    }
  }
}

Usa el MCP de ModelScope Qwen-Image con varios modelos de IA

TypingMind conecta las herramientas MCP a nivel del espacio de trabajo, por lo que, una vez conectado ModelScope Qwen-Image, puedes usarlo con distintos modelos de IA en TypingMind sin tener que configurarlo por separado para cada modelo. Esta integración MCP se ejecuta localmente en tu dispositivo a través del conector MCP de TypingMind.

Guía de configuración para usar el conector local

Usa esta opción si el servidor MCP necesita acceder a archivos locales, aplicaciones o recursos privados de tu ordenador.

1

Abre los ajustes de MCP

En TypingMind, ve a Ajustes, luego a Ajustes avanzados y a Model Context Protocol, y elige Configurar conector.

  1. Abre TypingMind en tu navegador.
  2. Haz clic en el icono de Ajustes.
  3. Ve a Ajustes avanzados.
  4. Abre la sección Model Context Protocol.
  5. Haz clic en Configurar conector y elige Este dispositivo.
Pantalla de configuración del conector MCP de TypingMind con «Este dispositivo» seleccionado
2

Ejecuta el comando del conector

Elige Este dispositivo, copia el comando de TypingMind y ejecútalo en Terminal. Mantén el proceso en ejecución mientras uses MCP.

  1. Copia el comando de configuración que muestra TypingMind.
  2. Abre Terminal en macOS o Windows Terminal en Windows.
  3. Pega y ejecuta el comando.
  4. Acepta la instalación del paquete si Terminal te pide confirmación para continuar.
  5. Mantén el proceso en ejecución en la ventana de Terminal mientras uses las herramientas MCP.
3

Añade ModelScope Qwen-Image como servidor

Cuando el estado del conector sea «Listo», haz clic en «Edita servidores» y pega la configuración del servidor MCP.

  1. Espera hasta que el estado del conector indique «Listo».
  2. Haz clic en Edita servidores.
  3. Pega la configuración del servidor MCP de ModelScope Qwen-Image.
  4. Guarda la lista de servidores.
  5. Actualiza para comprobar que el conector sigue listo.
Ajustes de MCP de TypingMind con un servidor activo y el botón «Edita servidores»
{
  "mcpServers": {
    "modelscope-qwen-image": {
      "command": "npx",
      "args": [
        "-y",
        "modelscope-image-mcp"
      ]
    }
  }
}
4

Úsala con distintos modelos

Guarda la lista de servidores, abre Plugins, activa las herramientas MCP de ModelScope Qwen-Image y selecciona cualquier modelo de IA compatible en TypingMind para usar las herramientas en el chat o asignárselas a un agente de IA.

  1. Abre la página Plugins en TypingMind.
  2. Activa las herramientas MCP de ModelScope Qwen-Image.
  3. Inicia un chat y elige el modelo de IA que quieras usar.
  4. Usa las herramientas MCP en el chat o asígnalas a un agente de IA.
  5. Cambia a otro modelo de IA cuando lo necesites sin volver a conectar MCP.
Chat de TypingMind que usa herramientas MCP activadas con un modelo de IA seleccionado
¿Puedes usar ModelScope Qwen-Image para ayudarme con esta tarea?
ModelScope Qwen-Image
Claro. Lo he leído.
Esto he encontrado usando ModelScope Qwen-Image.

Preguntas frecuentes

¿Para qué sirve el servidor MCP ModelScope Qwen-Image?

ModelScope Qwen-Image es un servidor MCP que permite a los clientes de IA compatibles conectarse a herramientas y contexto externos. En TypingMind, basta con añadir este servidor MCP una vez para que sus herramientas estén disponibles en tu espacio de trabajo de IA.

¿Puedo usar el servidor MCP ModelScope Qwen-Image con varios modelos de IA en TypingMind?

Sí. TypingMind conecta las herramientas MCP a nivel del espacio de trabajo, por lo que puedes usar ModelScope Qwen-Image con distintos modelos de IA, como Claude, ChatGPT, Gemini u otros que hayas configurado en TypingMind, sin configurar el servidor MCP por separado para cada modelo.

¿Por qué usar el conector MCP de ModelScope Qwen-Image con TypingMind?

TypingMind es una de las mejores interfaces de chat con LLM porque reúne varios modelos de IA, prompts, plugins, agentes de IA, claves de API y herramientas MCP en un solo espacio de trabajo. Con ModelScope Qwen-Image conectado, puedes usar sus herramientas MCP con tus modelos preferidos y mantener organizado tu flujo de trabajo de chat en TypingMind.

¿Cómo conecto el servidor MCP ModelScope Qwen-Image a TypingMind?

ModelScope Qwen-Image funciona a través del conector MCP local de TypingMind. Es la mejor opción cuando el servidor MCP necesita acceder a archivos locales, aplicaciones de escritorio, herramientas de línea de comandos o recursos privados de tu ordenador.

¿Qué herramientas ofrece el servidor MCP ModelScope Qwen-Image en TypingMind?

ModelScope Qwen-Image ofrece funciones MCP que puedes activar desde la página Plugins de TypingMind y usar en el chat o asignar a agentes de IA.

¿Tengo que compartir mis claves de API con TypingMind para usar el servidor MCP ModelScope Qwen-Image?

No. TypingMind prioriza el funcionamiento local y te permite mantener el control de tus proveedores de modelos, claves de API, prompts y configuración MCP. Si ModelScope Qwen-Image requiere autenticación, añade las cabeceras, los ajustes de OAuth o la configuración local necesarios para ese servidor MCP al crear la conexión.

Servidores MCP relacionados

Ver todos

Crea ya tu propio espacio de trabajo IA

Suscríbete a nuestro boletín para recibir avisos sobre nuevas funciones y próximos sorteos 👇