An MCP adaptor for a stable-diffusion.cpp
(sd.cpp) server. It exposes a single generate_image tool over StreamableHTTP so that
models in llama.cpp's webui can generate images
inline in their responses.
The model controls only the prompt and negative prompt. Image size is fixed by a
flag; everything else (seed, sampler, steps, cfg, model) is configured on the sd.cpp
server. Requests are forwarded to sd.cpp's OpenAI-compatible /v1/images/generations
endpoint; the PNG comes back as an MCP image content block that the webui renders inline.
go build
./sdmcp -sd-url http://localhost:1234 -size 512x512 -listen :1235| Flag | Default | Description |
|---|---|---|
-listen |
:1235 |
Address this MCP server listens on. |
-sd-url |
http://localhost:1234 |
Base URL of the sd.cpp server. |
-size |
512x512 |
Fixed image size (WxH) sent to sd.cpp. |
-path |
/mcp |
MCP endpoint path. |
Add an MCP server with the full endpoint path (not just the host):
http://localhost:1235/mcp
sdmcp sends permissive CORS headers and answers preflight OPTIONS, so the browser-based
webui connects directly with no proxy and no auth. Note: browsers block an https:// page
from calling an http:// server — keep both on http (the usual localhost setup) or serve
sdmcp over HTTPS.
- The tool returns the image plus a short text instruction telling the model the image is already shown to the user, which stops models from echoing the attachment placeholder into their reply.
- On any sd.cpp failure the tool returns an error result rather than a transport error.
- Generation can be slow; sdmcp sets no request/write timeout and relies on the MCP client's per-tool timeout (the webui default is 300 s).
Public domain (The Unlicense). See UNLICENSE.