Skip to main content
Glama

sd-api-mcp

一个将 Stable Diffusion REST API 暴露给 AI 智能体的 MCP(Model Context Protocol)服务器。支持 SD1.5、SDXL 和 Illustrious XL 流水线,用于文生图、修复(inpainting)、模型管理和模型合并。

它基于 SD API Backend 项目构建。

使用 MCP Python SDK 构建,并通过 uv 进行管理。

环境要求

  • Python >= 3.11

  • uv 包管理器

  • 一个正在运行的 Stable Diffusion API 实例(默认:http://localhost:8000

Related MCP server: Segmind MCP Server

安装

git clone <repo-url>
cd sd-api-mcp
uv sync

用法

stdio(默认)

适用于管理服务器进程的 MCP 客户端(例如 Claude Code、Claude Desktop):

uv run sd-api-mcp

SSE

uv run sd-api-mcp --transport sse --host 0.0.0.0 --port 8080

Streamable HTTP(推荐用于网络部署)

uv run sd-api-mcp --transport streamable-http --host 0.0.0.0 --port 8080

MCP 端点将位于 http://<host>:<port>/mcp

Claude Desktop 配置

添加到你的 claude_desktop_config.json

{
  "mcpServers": {
    "stable-diffusion": {
      "command": "uv",
      "args": ["run", "--project", "/path/to/sd-api-mcp", "sd-api-mcp"],
      "env": {
        "SD_API_URL": "http://localhost:8000"
      }
    }
  }
}

Claude Code 配置

claude mcp add stable-diffusion -- uv run --project /path/to/sd-api-mcp sd-api-mcp

OpenCode 配置

添加到你的 opencode.json

{
  "mcp": {
    "stable-diffusion": {
      "type": "stdio",
      "command": "uv",
      "args": ["run", "--project", "/path/to/sd-api-mcp", "sd-api-mcp"],
      "env": {
        "SD_API_URL": "http://localhost:8000"
      }
    }
  }
}

对于 SSE 或 Streamable HTTP 传输方式,请单独启动服务器,并使用远程 URL:

{
  "mcp": {
    "stable-diffusion": {
      "type": "sse",
      "url": "http://localhost:8080/sse"
    }
  }
}

环境变量

变量

默认值

描述

SD_API_URL

http://localhost:8000

Stable Diffusion API 的基础 URL

SD_POLL_INTERVAL

2.0

作业状态轮询间隔(秒)

SD_POLL_TIMEOUT

600.0

等待作业完成的最大秒数

MCP_TRANSPORT

stdio

传输协议(stdiossestreamable-http

MCP_HOST

127.0.0.1

SSE/HTTP 传输的绑定地址

MCP_PORT

8080

SSE/HTTP 传输的端口

可用工具

图像生成

工具

描述

generate_image

生成图像并等待结果

inpaint_image

修复遮罩区域并等待结果

submit_generate

提交生成作业,立即返回作业 ID

submit_inpaint

提交修复作业,立即返回作业 ID

batch_generate

一次提交最多 10 个生成请求

compare_models

使用相同提示词,用 2-6 个模型生成图像进行比较

所有生成工具都接受 pipeline 参数:"sd15""sdxl""illustrious"

模型管理

工具

描述

list_models

列出可用的 checkpoint、LoRA 或 VAE

get_model_metadata

从模型的 safetensors 头部读取元数据

作业管理

工具

描述

list_jobs

列出所有作业及其状态和进度

get_job_status

获取指定作业的状态和结果

cancel_job

取消待处理或正在运行的作业

系统

工具

描述

health_check

检查 SD API 是否可访问

system_info

获取 GPU、缓存和队列统计信息

list_schedulers

列出可用的噪声调度器

get_app_settings

获取当前配置参数

模型合并

工具

描述

merge_models

合并两个 checkpoint(linear、slerp、additive、subtract)

batch_merge_models

将基础模型与多个目标模型合并

recipe_merge

执行多步骤合并配方

示例

生成图像(智能体视角)

AI 智能体会使用以下参数调用 generate_image 工具:

{
  "pipeline": "sdxl",
  "positive_prompt": "a cat sitting on a windowsill, golden hour lighting, photorealistic",
  "negative_prompt": "blurry, low quality",
  "model_checkpoint": "dreamshaperXL_v2.safetensors",
  "width": 1024,
  "height": 1024,
  "steps": 30,
  "cfg_scale": 7.0,
  "seed": -1,
  "scheduler": "DPM++ 2M"
}

该工具将作业提交到 SD API,轮询直至完成,并返回包含生成图像的完整结果。

列出可用模型

{
  "model_type": "sdxl",
  "resource_type": "checkpoints"
}

合并两个模型

{
  "model_type": "sd15",
  "base_model": "v1-5-pruned.safetensors",
  "target_model": "dreamshaper_8.safetensors",
  "output_name": "merged_model.safetensors",
  "method": "slerp",
  "alpha": 0.5
}

项目结构

src/sd_api_mcp/
    __init__.py   # CLI entry point with transport selection
    server.py     # MCPServer instance and tool definitions
    client.py     # Async HTTP client for the SD API

许可证

本项目采用 GNU General Public License v3.0 授权。详情请参阅 LICENSE

Install Server
A
license - permissive license
A
quality
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

  • Generate images, GIFs, and PDFs from HTML, URLs, or templates — from your AI agent.

  • Create and manage cinematic AI video renders through the Future Video Studio Agent API.

  • LLM chat, text summarization and AI image generation

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mcaimi/sd-api-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server