npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@bashcat/ai-image-chat-mcp

v2.3.5

Published

MCP server for AI image generation, video generation and chat completion with support for multiple AI providers including Tongyi Wanxiang

Readme

AI Image Chat MCP 工具

這是一個通用的 AI 圖片生成和對話完成 Model Context Protocol (MCP) 工具,支持多種 AI 服務提供商。

功能特性

  • 🖼️ 圖片生成: 使用 AI 模型生成圖片
  • 💬 對話完成: 使用 AI 模型進行智能對話
  • 🚀 阿里雲 DashScope: 支援阿里雲 DashScope 高品質文生圖 API
  • 📁 自動保存: 生成的圖片會自動下載並保存到指定目錄
  • 📝 智能命名: 檔名根據用戶的 prompt 自動生成
  • 🔐 安全配置: API 密鑰安全保存在 .env 文件中
  • 🎛️ 自定義提示: 支持自定義系統提示詞,如未提供則使用預設值

安裝與設置

1. 安裝依賴

npm install

2. 配置環境變數

編輯 .env 文件,設置你的 API 密鑰:

AI_API_KEY=your_api_key_here
AI_API_BASE_URL=https://api.laozhang.ai/v1
AI_IMAGE_SAVE_PATH=/path/to/your/images/directory
ALI_API_KEY=your_ali_api_key_here
# 或者使用
DASHSCOPE_API_KEY=your_dashscope_api_key_here

環境變數說明:

  • AI_API_KEY: 您的 AI API 密鑰(必須)
  • AI_API_BASE_URL: API 基礎 URL(可選,預設為 https://api.laozhang.ai/v1
  • AI_IMAGE_SAVE_PATH: 圖片保存路徑(可選,預設為 ~/generated_images
  • ALI_API_KEY: 阿里雲 DashScope API 密鑰(使用阿里雲功能時必須)
  • DASHSCOPE_API_KEY: 阿里雲 DashScope API 密鑰的別名(與 ALI_API_KEY 二選一)

支持的 API 服務商:

  • 老張 AI: https://api.laozhang.ai/v1
  • 阿里雲 DashScope: https://dashscope.aliyuncs.com/api/v1
  • OpenAI: https://api.openai.com/v1
  • 其他 OpenAI 兼容的 API 服務

3. 編譯項目

npm run build

4. 啟動服務

npm start

MCP (Model Context Protocol) 設置

在 Claude Desktop 中使用

編輯您的 Claude Desktop 配置文件 (~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "ai-image-chat-mcp": {
      "command": "npx",
      "args": ["-y", "@bashcat/ai-image-chat-mcp"],
      "env": {
        "AI_API_KEY": "your_api_key_here",
        "AI_API_BASE_URL": "https://api.laozhang.ai/v1",
        "AI_IMAGE_SAVE_PATH": "~/Pictures/AI_Generated_Images",
        "ALI_API_KEY": "your_ali_api_key_here"
      }
    }
  }
}

在 VS Code 中使用

編輯您的 VS Code 設置 (settings.json):

{
  "mcp": {
    "servers": {
      "ai-image-chat-mcp": {
        "command": "npx",
        "args": ["-y", "@bashcat/ai-image-chat-mcp"],
        "env": {
          "AI_API_KEY": "your_api_key_here",
          "AI_API_BASE_URL": "https://api.laozhang.ai/v1",
          "AI_IMAGE_SAVE_PATH": "~/Pictures/AI_Generated_Images",
          "ALI_API_KEY": "your_ali_api_key_here"
        }
      }
    }
  }
}

環境變數配置

| 環境變數 | 必需 | 預設值 | 說明 | | -------------------- | ---- | ---------------------------- | ---------------------- | | AI_API_KEY | ✅ | - | 您的 AI API 密鑰 | | AI_API_BASE_URL | ❌ | https://api.laozhang.ai/v1 | API 基礎 URL | | AI_IMAGE_SAVE_PATH | ❌ | ~/generated_images | 圖片保存路徑 | | ALI_API_KEY | ❌ | - | 阿里雲 DashScope 密鑰 | | DASHSCOPE_API_KEY | ❌ | - | 阿里雲密鑰的別名 |

圖片保存功能

  • 🖼️ 自動保存: 生成的圖片會自動保存到指定目錄
  • 📁 動態路徑: 通過 AI_IMAGE_SAVE_PATH 環境變數自定義保存路徑
  • 📝 智能命名: 檔名根據 prompt 自動生成,例如:台灣男性工程師-2025-09-21T07-15-30-123Z.jpg
  • 📂 目錄創建: 如果指定目錄不存在,會自動創建
  • 🔄 格式轉換: 支援 base64 圖片解碼和格式轉換
  • 🎨 多格式支援: 支援 JPG、PNG、WebP 輸出格式
  • 🏠 友好顯示: 路徑顯示使用 ~ 代替 home 目錄,更簡潔易讀

圖片保存路徑設定範例:

# 預設保存到使用者主目錄
export AI_IMAGE_SAVE_PATH="~/generated_images"

# 自定義絕對路徑
export AI_IMAGE_SAVE_PATH="/Users/username/Pictures/AI_Images"

# 相對於專案的路徑
export AI_IMAGE_SAVE_PATH="./images"

可用工具

1. generate_image

使用老張 AI 生成圖片的工具。

參數:

  • prompt (必需): 圖片生成的提示詞
  • system_prompt (可選): 系統提示詞,預設為 "You are a helpful assistant that generates images."
  • model (可選): 模型名稱,可選 "gpt-image-1" 或 "gpt-4o-image",預設為 "gpt-4o-image"
  • output_format (可選): 輸出圖片格式,可選 "jpg"、"jpeg"、"png"、"webp",預設為 "jpg"

範例:

{
  "prompt": "生成一張卡通風格的熊貓宇航員圖片,背景是星空",
  "system_prompt": "You are a creative image generator.",
  "model": "gpt-4o-image",
  "output_format": "png"
}

或使用新的 Gemini 模型(v2.3.4+ 支援 base64 圖片自動保存):

{
  "prompt": "賽博朋克風格的未來城市夜景",
  "model": "gemini-2.5-flash-image-preview",
  "aspect_ratio": "16:9",
  "n": 2
}

⭐ Gemini 模型特色功能

  • 支援 base64 格式圖片自動保存到本地檔案
  • 高速生成,品質優秀
  • 支援多種輸出格式(jpg, png, webp)

2. tongyi_wanxiang_generate_image (推薦)

使用通義萬相文生圖完整生圖流程。

參數:

  • prompt (必需): 正向提示詞
  • model (可選): 模型選擇,可選值:
    • wanx2.1-t2i-turbo: 速度快 (0.14元/張)
    • wanx2.1-t2i-plus: 品質高 (0.20元/張)
    • wanx2.0-t2i-turbo: 性價比高,擅長人像 (0.04元/張)
  • negative_prompt (可選): 反向提示詞,預設為 "人物"
  • size (可選): 圖像分辨率,預設為 "1024*1024"
  • n (可選): 生成圖片數量 (1-4),預設為 1
  • seed (可選): 隨機數種子
  • prompt_extend (可選): 是否開啟智能改寫,預設為 true
  • watermark (可選): 是否添加水印,預設為 false
  • output_format (可選): 輸出格式,預設為 "jpg"
  • max_wait_minutes (可選): 最大等待時間(分鐘),預設為 5

範例:

{
  "prompt": "一隻可愛的橘貓坐在櫻花樹下,春天的陽光灑在它身上",
  "model": "wanx2.1-t2i-plus",
  "size": "1024*1024",
  "output_format": "png"
}

3. tongyi_wanxiang_create_task

創建通義萬相文生圖任務。

4. tongyi_wanxiang_query_task

查詢通義萬相文生圖任務結果。

5. chat_completion

進行對話的工具。

參數:

  • message (必需): 用戶訊息
  • system_prompt (可選): 系統提示詞,預設為 "You are a helpful assistant."
  • model (可選): 模型名稱,預設為 "gpt-4"

範例:

{
  "message": "請幫我寫一首關於春天的詩",
  "system_prompt": "You are a professional poet.",
  "model": "gpt-4"
}

API 參考

本工具使用老張 AI 的聊天完成 API:

POST https://api.laozhang.ai/v1/chat/completions

請求格式:

{
  "model": "gpt-image-1",
  "messages": [
    { "role": "system", "content": "系統提示詞" },
    { "role": "user", "content": "用戶訊息" }
  ]
}

開發

開發模式

npm run dev

這會啟動 TypeScript 編譯器的監聽模式,當你修改代碼時會自動重新編譯。

項目結構

laozhang_mcp/
├── src/
│   └── index.ts          # 主要服務器代碼
├── dist/                 # 編譯後的輸出
├── .env                  # 環境變數配置
├── package.json          # 項目配置
├── tsconfig.json         # TypeScript 配置
└── README.md            # 說明文檔

通義萬相文生圖集成

本工具支援阿里雲通義萬相文生圖V2版本的三種模型。詳細說明請參考:

模型對比

| 模型 | 特點 | 價格 | 適用場景 | |------|------|------|----------| | wanx2.1-t2i-turbo | 速度快 | 0.14元/張 | 快速生成 | | wanx2.1-t2i-plus | 品質高 | 0.20元/張 | 精細作品 | | wanx2.0-t2i-turbo | 性價比高 | 0.04元/張 | 人像專長 |

快速開始

  1. 阿里雲百炼平台 獲取 API Key
  2. 設置環境變數 ALI_API_KEY
  3. 使用 tongyi_wanxiang_generate_image 工具生成圖片

注意事項

  1. 請確保你有有效的 AI API 密鑰
  2. 使用阿里雲功能需要設置 ALI_API_KEYDASHSCOPE_API_KEY
  3. 不要將 .env 文件提交到版本控制系統
  4. 圖片生成可能需要較長時間,請耐心等待
  5. API 有使用限制,請適度使用

許可證

MIT License