z_ai_image_gen_mcp
This server provides an MCP interface for Z.AI's image and video generation models, enabling programmatic creation of visual content. Key capabilities include:
Image Generation: Discover available models (GLM-Image, CogView-4) with
list_models, generate images synchronously (generate_image) or asynchronously (generate_image_async) from text prompts, download results as base64 or files (download_image), and combine generation with download in one step (generate_and_download_image).Video Generation: List video models (CogVideoX-3, Vidu Q1, Vidu 2) with
list_video_models, generate videos asynchronously (generate_video) from text, images, or start-end frames with control over resolution, duration, style, and audio, poll results (get_video_result), and generate plus download in one operation (generate_and_download_video).Asynchronous Handling: Long-running tasks use automatic retries with exponential backoff, and you can check status with
get_async_resultorget_video_result.Model Discovery:
list_modelsandlist_video_modelsprovide available models and their specific parameters (resolution, aspect ratio, etc.).Flexible Inputs: Support for text-to-image/video, image-to-video, start-end frame animation, and reference-based generation.
Output Options: Receive generated media as base64 data or save directly to local files.
Easy Configuration: Set API key, base URL, default models, timeouts, and retries via environment variables.
Seamless Integration: Works with MCP clients like Claude Desktop and OpenCode, with full TypeScript support and input validation.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@z_ai_image_gen_mcp generate a realistic image of a cat sitting on a chair"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Z.AI Image & Video Generation MCP Server
A Model Context Protocol (MCP) server that provides access to Z.AI's image and video generation models for LLM applications.
Features
Image Generation: GLM-Image and CogView-4 models for high-quality image generation
Video Generation: CogVideoX-3, Vidu Q1, and Vidu 2 models for AI video creation
Multiple Input Modes: Text-to-image/video, image-to-video, start-end frame animation
Asynchronous Processing: Submit long-running tasks and poll for results
Automatic Downloads: Generate and download in a single operation
Automatic Retries: Built-in retry logic with exponential backoff
Comprehensive Validation: Input validation with clear error messages
Type-Safe: Full TypeScript support with detailed type definitions
Related MCP server: glm-image-mcp-server
Installation
npm install z-ai-image-mcpConfiguration
Set your Z.AI API key as an environment variable:
export ZAI_API_KEY=your_api_key_hereGet your API key from the Z.AI API Keys page or sign up for the GLM Coding Plan.
Optional Configuration
Environment Variable | Description | Default |
| API base URL |
|
| Default model |
|
| Default image size |
|
| Request timeout (ms) |
|
| Max retry attempts |
|
| Initial retry delay (ms) |
|
Usage
With Claude Desktop
Add to your Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"z-ai-image": {
"command": "npx",
"args": ["z-ai-image-mcp"],
"env": {
"ZAI_API_KEY": "your_api_key_here"
}
}
}
}With Other MCP Clients
Run the server directly:
npx z-ai-image-mcpOr programmatically:
import { createServer, loadConfig } from 'z-ai-image-mcp';
const config = loadConfig();
const server = createServer(config);
// Connect to your transport...With OpenCode
Add to your OpenCode configuration (opencode.json or opencode.jsonc in your project root):
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"z-ai-image": {
"type": "local",
"command": ["npx", "z-ai-image-mcp"],
"enabled": true,
"environment": {
"ZAI_API_KEY": "your_api_key_here"
}
}
}
}Or using an environment variable reference:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"z-ai-image": {
"type": "local",
"command": ["npx", "z-ai-image-mcp"],
"enabled": true,
"environment": {
"ZAI_API_KEY": "{env:ZAI_API_KEY}"
}
}
}
}Using with OpenCode prompts:
Generate a professional logo for a tech startup. use z-ai-imageOr add to your AGENTS.md:
When generating images, use the `z-ai-image` MCP server tools.Per-agent configuration (optional):
To enable the MCP server only for specific agents:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"z-ai-image": {
"type": "local",
"command": ["npx", "z-ai-image-mcp"],
"enabled": true,
"environment": {
"ZAI_API_KEY": "{env:ZAI_API_KEY}"
}
}
},
"tools": {
"z-ai-image*": false
},
"agent": {
"design-agent": {
"tools": {
"z-ai-image*": true
}
}
}
}Available Tools
1. list_models
List all available image generation models and their capabilities.
Use this tool to discover available models, their features, and recommended settings.2. generate_image
Generate an image synchronously from a text prompt.
Parameters:
prompt(required): Text description of the image (max 4000 characters)model(optional):glm-imageorcogview-4-250304(default:glm-image)size(optional): Image dimensions, e.g.,1280x1280(default:1280x1280)quality(optional):hdorstandard(default:hdfor GLM-Image)user_id(optional): End user ID for abuse prevention (6-128 characters)
Example:
Generate an image of a cute kitten sitting on a windowsill with a sunset background.3. generate_image_async
Start an asynchronous image generation task. Returns a task ID for polling.
Parameters:
prompt(required): Text description of the imagemodel(optional): Onlyglm-imagesupports async (default:glm-image)size(optional): Image dimensions (default:1280x1280)quality(optional): Onlyhdsupported for async (default:hd)user_id(optional): End user ID for abuse prevention
Example:
Start async generation of a complex poster design.4. get_async_result
Retrieve the result of an asynchronous image generation task.
Parameters:
task_id(required): The task ID fromgenerate_image_async
Example:
Check the status of task ID "task-12345".5. download_image
Download an image from a URL and return it as base64 or save to a file.
Parameters:
url(required): The URL of the image to download (e.g., fromgenerate_imageorget_async_result)output(optional):base64orfile_output(default:base64)file_output(optional): Absolute path to save the image file (required if output isfile_output). Example:/path/to/image.png
Output Modes:
base64: Returns the image data directly as base64 (auto-switches to file if > 1MB)file_output: Saves the image to disk at the specified path
Example:
Download the generated image and save it to /home/user/images/logo.pngNote: Z.AI image URLs expire after 30 days. Use this tool to download and store images permanently.
6. generate_and_download_image ⭐ Recommended
Generate an image and automatically download it in a single operation. This is the most convenient tool when you want the image data immediately.
Parameters:
prompt(required): Text description of the image (max 4000 characters)model(optional):glm-imageorcogview-4-250304(default:glm-image)size(optional): Image dimensions, e.g.,1280x1280(default:1280x1280)quality(optional):hdorstandard(default:hdfor GLM-Image)user_id(optional): End user ID for abuse prevention (6-128 characters)output(optional):base64orfile_output(default:base64)file_output(optional): Absolute path to save the image file (required if output isfile_output)poll_interval(optional): Seconds to wait between polling for async results (default: 3)max_wait(optional): Maximum seconds to wait for generation (default: 120)
Output Modes:
base64: Returns the image data directly as base64 (auto-switches to file if > 1MB)file_output: Saves the image to disk at the specified path
Examples:
# Generate and get as base64
Generate a logo for my company and show me the image.
# Generate and save to file
Generate a logo and save it to /home/user/images/logo.pngBehavior:
For GLM-Image: Uses async API with automatic polling until complete
For CogView-4: Uses synchronous API
Automatically downloads the result once generation completes
Returns image as base64 or saves to specified path
Video Generation Tools
7. list_video_models
List all available video generation models and their capabilities.
Use this tool to discover available video models, their features, and supported parameters.8. generate_video
Generate a video asynchronously from text or images. Returns a task ID for polling.
Parameters:
model(required): Video generation modelcogvideox-3: Z.AI flagship model (up to 4K, 5-10s, audio support)viduq1-text: Text-to-video, 1080P, 5sviduq1-image: Image-to-video, 1080P, 5sviduq1-start-end: Start-end frame, 1080P, 5svidu2-image: Image-to-video, 720P, 4s (faster, cheaper)vidu2-start-end: Start-end frame, 720P, 4svidu2-reference: Reference-based, 720P, 4s
prompt(optional): Text description (max 512 characters)image_url(optional): Image URL(s) for image-to-video generationquality(CogVideoX-3):qualityorspeedsize(optional): Video resolutionduration(optional): Video duration in secondsfps(CogVideoX-3): 30 or 60with_audio(optional): Generate AI sound effectsstyle(Vidu Q1 text):generaloranimeaspect_ratio(Vidu Q1/2):16:9,9:16, or1:1movement_amplitude(Vidu):auto,small,medium, orlargeuser_id(optional): End user ID for abuse prevention
Examples:
# Text-to-video
Generate a video of a cat playing with a ball.
# Image-to-video
Animate this image: [image_url]
# Start-end frame
Create a smooth transition from [first_frame] to [last_frame].9. get_video_result
Retrieve the result of an asynchronous video generation task.
Parameters:
task_id(required): The task ID fromgenerate_video
Note: Video generation typically takes 30 seconds to several minutes depending on duration and quality.
10. generate_and_download_video ⭐ Recommended
Generate a video and automatically download it. Polls for completion and saves the video file.
Parameters:
All parameters from
generate_videoplus:file_output(optional): Absolute path to save the video filepoll_interval(optional): Seconds to wait between polling (default: 10)max_wait(optional): Maximum seconds to wait (default: 300)
Example:
Generate a video of a sunset over the ocean and save it to /home/user/videos/sunset.mp4Note: Videos are always saved to file (too large for base64). Video URLs expire after 1 day.
Models
GLM-Image
Z.AI's flagship image generation model with a hybrid autoregressive + diffusion architecture.
Best for: Complex compositions, text rendering, detailed illustrations, commercial posters
Quality options:
hd(detailed, ~20s),standard(faster, ~5-10s)Size range: 1024-2048px per dimension (divisible by 32)
Recommended sizes: 1280×1280, 1568×1056, 1056×1568, 1472×1088, 1088×1472, 1728×960, 960×1728
Async support: Yes
CogView-4-250304
General-purpose image generation with fast text understanding.
Best for: General image generation, quick iterations
Quality options:
hd,standardSize range: 512-2048px per dimension (divisible by 16)
Recommended sizes: 1024×1024, 768×1344, 864×1152, 1344×768, 1152×864, 1440×720, 720×1440
Async support: No
Video Models
CogVideoX-3
Z.AI's flagship video generation model with improved frame stability and clarity.
Best for: Text-to-video, image-to-video, start-end frame animation
Resolution: Up to 4K (3840x2160)
Duration: 5 or 10 seconds
Features: Audio generation, 30/60 FPS, quality/speed modes
Price: $0.20/video
Vidu Q1
High-quality video generation with 1080P output.
Model | Capability | Duration | Price |
| Text-to-video | 5s | $0.40 |
| Image-to-video | 5s | $0.40 |
| Start-end frame | 5s | $0.40 |
Features: General/anime styles, motion amplitude control
Vidu 2
Fast and cost-effective video generation with 720P output.
Model | Capability | Duration | Price |
| Image-to-video | 4s | $0.20 |
| Start-end frame | 4s | $0.20 |
| Reference-based | 4s | $0.40 |
Features: Audio generation, motion amplitude control, multi-image reference
Error Handling
The server handles various error scenarios:
Error Type | Description |
| Invalid or missing API key |
| Too many requests - will auto-retry |
| Invalid parameters |
| Z.AI server issues - will auto-retry |
| Connection issues - will auto-retry |
| Request timeout - will auto-retry |
| Prompt blocked by content policy |
Development
Setup
git clone https://github.com/GeorgH93/z_ai_image_gen_mcp.git
cd z_ai_image_gen_mcp
npm install
cp .env.example .env
# Edit .env with your API keyScripts
npm run build # Build TypeScript
npm run dev # Run in development mode
npm test # Run all tests
npm run test:unit # Run unit tests only
npm run test:integration # Run integration tests
npm run test:e2e # Run E2E tests
npm run test:coverage # Run tests with coverage
npm run typecheck # Type check without emitLicense
MIT
Links
Available Tools
10 toolsdownload_imageA
Download an image from a URL and return it as base64 or save to a file. Use this after generating an image to get the actual image data. Note: Z.AI image URLs expire after 30 days.
Inputs: url (required), output, file_output.
generate_and_download_imageA
Generate an image and automatically download it. This combines generate_image and download_image into a single operation. Returns the image as base64 or saves to a file. Best for when you want the image data immediately.
Inputs: prompt (required), size, model, output, +5 more.
generate_and_download_videoA
Generate a video and automatically download it. Polls for completion and returns the video file. Best for when you want the video data immediately.
Inputs: model (required), fps, size, style, +11 more.
generate_imageA
Generate an image synchronously from a text prompt. Returns the image URL directly. Use this for most image generation tasks.
Inputs: prompt (required), size, model, quality, +1 more.
generate_image_asyncA
Start an asynchronous image generation task. Returns a task ID to poll for results. Use this for long-running generations or when you need to process multiple images.
Inputs: prompt (required), size, model, quality, +1 more.
generate_videoA
Generate a video asynchronously from text or images. Returns a task ID to poll for results. Supports multiple models: CogVideoX-3 (text/image/start-end frame), Vidu Q1 (1080P), Vidu 2 (720P, faster).
Inputs: model (required), fps, size, style, +8 more.
get_async_resultA
Retrieve the result of an asynchronous image generation task. Use the task ID from generate_image_async.
Inputs: task_id (required).
get_video_resultA
Retrieve the result of an asynchronous video generation task. Use the task ID from generate_video.
Inputs: task_id (required).
list_modelsA
List available Z.AI image generation models and their capabilities
Inputs: no named parameters.
list_video_modelsA
List available Z.AI video generation models and their capabilities
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 10 tools
Tools are mostly distinct: image vs video generation, sync vs async, and combined download operations. However, there is some overlap between generate_image_async+get_async_result and generate_image (sync), but descriptions clarify usage.
Names follow a mostly consistent verb_noun pattern (e.g., list_models, generate_image). A minor inconsistency: 'get_async_result' is ambiguous (could be image or video), but the complementary 'get_video_result' helps. Compound names like 'generate_and_download_image' break the pattern slightly.
10 tools cover the core workflows for image and video generation without being excessive. Each tool has a clear purpose, and the number is well-scoped for the domain.
Covers essential operations: model listing, generation (sync/async), result retrieval, and download. Lacks a synchronous video generation option and management tools (e.g., list/cancel tasks), but the main generation pipeline is complete.
Maintenance
Related MCP Connectors
MCP server for Qwen Image 3 AI image generation
MCP server for Hailuo (MiniMax) AI video generation
MCP server for Wan AI video generation
MCP server for MiniMax H3 multimodal video generation
Related MCP Servers
- AlicenseAqualityCmaintenanceMCP server for generating images and videos using Volcengine's Jimeng APIs, supporting text-to-image, image-to-image, multi-image fusion, text-to-video, and image-to-video.31MIT
- AlicenseAqualityDmaintenanceMCP server for generating images using Z.AI's glm-image model. Supports image generation with various sizes and qualities, and includes batch CLI functionality.123 npmMIT
- AlicenseBqualityDmaintenanceMCP server that provides image analysis, OCR text extraction, and image description using the GLM-4V Flash model from Zhipu AI.38MIT
- AlicenseNot gradedqualityDmaintenanceMCP server for generating images via Zhipu CogView, supporting synchronous and asynchronous generation with progress notifications, plus health check endpoints.MIT