sd-api-mcp
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-mcpSSE
uv run sd-api-mcp --transport sse --host 0.0.0.0 --port 8080Streamable HTTP(推荐用于网络部署)
uv run sd-api-mcp --transport streamable-http --host 0.0.0.0 --port 8080MCP 端点将位于 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-mcpOpenCode 配置
添加到你的 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"
}
}
}环境变量
变量 | 默认值 | 描述 |
|
| Stable Diffusion API 的基础 URL |
|
| 作业状态轮询间隔(秒) |
|
| 等待作业完成的最大秒数 |
|
| 传输协议( |
|
| SSE/HTTP 传输的绑定地址 |
|
| SSE/HTTP 传输的端口 |
可用工具
图像生成
工具 | 描述 |
| 生成图像并等待结果 |
| 修复遮罩区域并等待结果 |
| 提交生成作业,立即返回作业 ID |
| 提交修复作业,立即返回作业 ID |
| 一次提交最多 10 个生成请求 |
| 使用相同提示词,用 2-6 个模型生成图像进行比较 |
所有生成工具都接受 pipeline 参数:"sd15"、"sdxl" 或 "illustrious"。
模型管理
工具 | 描述 |
| 列出可用的 checkpoint、LoRA 或 VAE |
| 从模型的 safetensors 头部读取元数据 |
作业管理
工具 | 描述 |
| 列出所有作业及其状态和进度 |
| 获取指定作业的状态和结果 |
| 取消待处理或正在运行的作业 |
系统
工具 | 描述 |
| 检查 SD API 是否可访问 |
| 获取 GPU、缓存和队列统计信息 |
| 列出可用的噪声调度器 |
| 获取当前配置参数 |
模型合并
工具 | 描述 |
| 合并两个 checkpoint(linear、slerp、additive、subtract) |
| 将基础模型与多个目标模型合并 |
| 执行多步骤合并配方 |
示例
生成图像(智能体视角)
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。
Maintenance
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
- AlicenseNot gradedqualityCmaintenanceGive AI agents full control over your local ComfyUI by exposing 77 tools for workflow management, image generation, model handling, and real-time canvas control.3AGPL 3.0
- AlicenseNot gradedqualityCmaintenanceEnables AI image and video generation using Segmind's API with 30+ models including FLUX, Stable Diffusion XL, and more, accessible through any MCP-compatible AI assistant.50MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to generate images using ComfyUI by exposing tools for image generation, batch processing, and status checking through the Model Context Protocol.MIT
- FlicenseNot gradedqualityDmaintenanceEnables LLM clients to generate, edit, and evaluate images through the Replicate API.
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
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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