Zhipu AI Image Generator MCP Server
Enables text-to-image generation using Zhipu AI's CogView4 model with support for multiple image sizes (1024x1024, 768x768, 576x1024) and automatic local saving of generated images.
README
智谱AI图像生成MCP服务器
这是一个基于MCP (Model Context Protocol) 的服务器,提供智谱AI CogView4图像生成功能。
功能
- 使用智谱AI的CogView4模型根据文本提示词生成图片
- 支持多种图片尺寸:1024x1024、768x768、576x1024
- 自动保存生成的图片到本地
generated_images文件夹
安装
- 克隆项目:
git clone https://github.com/lisy09/zhipu_image_mcp.git
cd zhipu_image_mcp
- 使用uv安装依赖:
# 如果尚未安装uv,请先安装:curl -LsSf https://astral.sh/uv/install.sh | sh
uv sync
- 激活虚拟环境:
source .venv/bin/activate # Linux/Mac
# 或
.venv\Scripts\activate # Windows
配置
在使用前,需要设置智谱AI的API密钥:
export ZHIPU_API_KEY="your_api_key_here"
或者在Windows上:
set ZHIPU_API_KEY=your_api_key_here
使用方法
启动MCP服务器
python cogview_server.py
服务器启动后,可以通过MCP协议调用以下工具:
generate_cogview4_image
根据文本提示词生成图片。
参数:
prompt(必需): 用于生成图片的详细中文描述size(可选): 图片尺寸,可选值:'1024x1024'、'768x768'、'576x1024',默认为'1024x1024'
示例:
{
"prompt": "一只戴着宇航员头盔的猫漂浮在太空中,背景是璀璨的星河",
"size": "1024x1024"
}
生成的图片将保存在generated_images文件夹中,文件名格式为:cogview4_image_YYYYMMDD_HHMMSS.png
在IDE中配置MCP服务器
在RooCode中使用
- 打开RooCode设置
- 找到MCP服务器配置选项
- 添加新的MCP服务器配置:
{
"zhipu-image-mcp": {
"command": "python",
"args": ["/path/to/your/zhipu_image_mcp/cogview_server.py"],
"env": {
"ZHIPU_API_KEY": "your_api_key_here"
}
}
}
- 将
/path/to/your/zhipu_image_mcp替换为项目的实际路径 - 将
your_api_key_here替换为你的智谱AI API密钥 - 保存配置并重启RooCode
配置完成后,你就可以在RooCode中直接使用智谱AI图像生成功能了。
在Claude Code中使用
- 打开Claude Code设置
- 找到MCP服务器配置
- 添加以下配置:
{
"mcpServers": {
"zhipu-image-mcp": {
"command": "python",
"args": ["/path/to/your/zhipu_image_mcp/cogview_server.py"],
"env": {
"ZHIPU_API_KEY": "your_api_key_here"
}
}
}
}
- 将
/path/to/your/zhipu_image_mcp替换为项目的实际路径 - 将
your_api_key_here替换为你的智谱AI API密钥 - 保存配置并重启Claude Code
配置完成后,你就可以在Claude Code中直接使用智谱AI图像生成功能了。
通用配置注意事项
- 确保Python路径正确,可以使用绝对路径:
/usr/bin/python3或which python查看路径 - 确保项目路径使用绝对路径,避免相对路径导致的问题
- API密钥可以通过环境变量设置,也可以直接在配置中指定
- 如果使用虚拟环境,确保命令指向虚拟环境中的Python:
/path/to/.venv/bin/python
依赖安装确认
在配置MCP服务器之前,请确保已经安装了所有依赖:
-
在项目中安装依赖(推荐):
cd /path/to/your/zhipu_image_mcp uv sync # 或者 pip install -r requirements.txt -
使用虚拟环境的Python路径:
{ "command": "/path/to/your/zhipu_image_mcp/.venv/bin/python", "args": ["/path/to/your/zhipu_image_mcp/cogview_server.py"] } -
或者全局安装依赖:
pip install mcp zai-sdk -
验证依赖安装:
python -c "import mcp; import zai; print('依赖安装成功')"
如果IDE无法找到依赖,建议使用虚拟环境的完整Python路径,这样可以确保使用正确的依赖环境。
依赖
- mcp>=1.0.0
- zai-sdk>=0.1.0
- requests
- python>=3.8
许可证
MIT License
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
E2B
Using MCP to run code via e2b.