Tongyi Wanx MCP server

Enables image generation through Alibaba's Tongyi Wanx API, handling authentication, communication, and response formatting for applications requiring AI-generated visuals.
Back to servers
Setup instructions
Provider
Suixinlei
Release date
Apr 11, 2025
Language
TypeScript
Stats
5 stars

The Tongyi Wanxiang MCP server provides a TypeScript-based implementation of the Model Context Protocol (MCP) that allows Large Language Models (LLMs) to directly access Alibaba Cloud's Tongyi Wanxiang text-to-image and text-to-video generation capabilities.

Installation and Setup

Prerequisites

  • Node.js >= 16.x
  • npm >= 8.x or pnpm

Setting Up with Bailian Platform

You can quickly set up the server by adding it to your configuration:

{
  "mcpServers": {
    "tongyi-wanxiang": {
      "command": "npx",
      "args": [
        "-y",
        "tongyi-wanx-mcp-server@latest"
      ],
      "env": {
        "DASHSCOPE_API_KEY": "<your Tongyi Wanxiang API key>"
      }
    }
  }
}

Running the Server

If you want to run the server directly:

# Install and run with npx
npx tongyi-wanx-mcp-server@latest

Make sure to set the DASHSCOPE_API_KEY environment variable with your API key.

Using the MCP Tools

The server provides several MCP tools for image and video generation:

Text-to-Image Generation

Starting an Image Generation Task

Use the wanx-t2i-image-generation tool to start an image generation task:

Parameters:

  • prompt: Description of the image you want to generate
  • negative_prompt: Elements you don't want in the image

Example:

{
  "prompt": "A scenic mountain landscape with a lake at sunset",
  "negative_prompt": "people, buildings, text"
}

The tool returns a task ID that you'll use to retrieve the results.

Getting Image Generation Results

Use the wanx-t2i-image-generation-result tool to get the results:

Parameters:

  • task_id: The task ID from the previous step

Example:

{
  "task_id": "your-task-id-here"
}

The response will include the URL to the generated image.

Text-to-Video Generation

Starting a Video Generation Task

Use the wanx-t2v-video-generation tool:

Parameters:

  • prompt: Description of the video you want to generate

Example:

{
  "prompt": "Waves crashing on a beach at sunset"
}

Getting Video Generation Results

Use the wanx-t2v-video-generation-result tool:

Parameters:

  • task_id: The task ID from the previous step

Example:

{
  "task_id": "your-task-id-here"
}

The response will include the URL to the generated video.

Advanced Parameters

Text-to-Image Additional Parameters

You can customize image generation with these optional parameters:

  • model: Model name, default is wanx2.1-t2i-turbo
  • size: Image dimensions, default is 1024*1024
  • n: Number of images to generate, default is 1
  • seed: Random seed for reproducible results
  • prompt_extend: Whether to enable prompt extension, default is true
  • watermark: Whether to add a watermark, default is false

Important Notes

  1. Ensure you have valid Tongyi Wanxiang API access and key
  2. Image generation typically takes from a few seconds to tens of seconds
  3. Video generation is more time-consuming, usually taking several minutes
  4. Video generation status queries may fail multiple times - the system will automatically retry
  5. Video tasks require more patience; consider increasing polling intervals and retry counts

Additional Resources

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "tongyi-wanxiang" '{"command":"npx","args":["-y","tongyi-wanx-mcp-server@latest"],"env":{"DASHSCOPE_API_KEY":"<\u4f60\u7684\u901a\u4e49\u4e07\u76f8 API \u5bc6\u94a5>"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "tongyi-wanxiang": {
            "command": "npx",
            "args": [
                "-y",
                "tongyi-wanx-mcp-server@latest"
            ],
            "env": {
                "DASHSCOPE_API_KEY": "<\u4f60\u7684\u901a\u4e49\u4e07\u76f8 API \u5bc6\u94a5>"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "tongyi-wanxiang": {
            "command": "npx",
            "args": [
                "-y",
                "tongyi-wanx-mcp-server@latest"
            ],
            "env": {
                "DASHSCOPE_API_KEY": "<\u4f60\u7684\u901a\u4e49\u4e07\u76f8 API \u5bc6\u94a5>"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later