图像生成API集成

Draw Things MCP是一个通过Model Context Protocol (MCP)将Draw Things API集成到Cursor中的工具,用于根据文本提示生成图像。

  • by jaokuohsuan
  • JavaScript
  • 本地部署
  • 17 星标
  • 更新于
在 GitHub 查看 jaokuohsuan/draw-things-mcp-cursor

使用说明

绘制事物MCP

使用模型上下文协议(MCP)为Cursor绘制事物API集成。

先决条件

  • Node.js>=14.0.0
  • Draw Things API正在运行http://127.0.0.1:7888

安装

# Install globally
npm install -g draw-things-mcp-cursor

# Or run directly
npx draw-things-mcp-cursor

光标集成

要在Cursor中设置此工具,请参阅中的详细指南 cursor-setup.md.

快速设置:

  1. 创建或编辑 ~/.cursor/claude_desktop_config.json:
{
  "mcpServers": {
    "draw-things": {
      "command": "draw-things-mcp-cursor",
      "args": []
    }
  }
}
  1. 重新启动游标
  2. 在游标中使用: generateImage({"prompt": "a cute cat"})

CLI使用情况

生成图像

echo '{"prompt": "your prompt here"}' | npx draw-things-mcp-cursor

参数

  • prompt:图像生成的文本提示(必填)
  • negative_prompt:图像生成的负面提示
  • width:图像宽度(默认值:360)
  • height:图像高度(默认值:360)
  • steps:生成步骤数(默认值:8)
  • model:用于生成的模型(默认值:“flux_1_schnell_q5p.ckpt”)
  • sampler:采样方法(默认值:“DPM++2M AYS”)

例子:

echo '{
  "prompt": "a happy smiling dog, professional photography",
  "negative_prompt": "ugly, deformed, blurry",
  "width": 360,
  "height": 360,
  "steps": 4
}' | npx draw-things-mcp-cursor

MCP工具集成

当在Cursor中用作MCP工具时,该工具将注册为 generateImage 具有以下参数:

{
  prompt: string;       // Required - The prompt to generate the image from
  negative_prompt?: string;  // Optional - The negative prompt
  width?: number;       // Optional - Image width (default: 360)
  height?: number;      // Optional - Image height (default: 360)
  model?: string;       // Optional - Model name
  steps?: number;       // Optional - Number of steps (default: 8)
}

生成的图像将保存在 images 文件名格式为的目录: <sanitized_prompt>_<timestamp>.png

响应格式

成功:

{
  "type": "success",
  "content": [{
    "type": "image",
    "data": "base64 encoded image data",
    "mimeType": "image/png"
  }],
  "metadata": {
    "parameters": { ... }
  }
}

错误:

{
  "type": "error",
  "error": "error message",
  "code": 500
}

故障排除

如果您遇到问题:

  • 确保Draw Things API正在运行http://127.0.0.1:7888
  • 检查中的日志文件 ~/.cursor/logs 如果与游标一起使用
  • 确保src/index.js具有执行权限: chmod +x src/index.js

许可证

麻省理工学院