Skip to main content

SD API MCP

Stable Diffusion WebUI API (AUTOMATIC1111/ForgeUI) を操作する MCP サーバ

前提条件

  • Stable Diffusion WebUI(または ForgeUI)が起動していること
  • uv がインストール済みであること

MCPクライアント設定

Claude Code

claude mcp add sd-api-mcp uvx sd-api-mcp

または .claude/settings.json に追加:

{
  "mcpServers": {
    "sd-api-mcp": {
      "command": "uvx",
      "args": ["sd-api-mcp"],
      "env": {
        "SD_WEBUI_URL": "http://localhost:7860"
      }
    }
  }
}

Cursor

.cursor/mcp.json に追加:

{
  "mcpServers": {
    "sd-api-mcp": {
      "command": "uvx",
      "args": ["sd-api-mcp"],
      "env": {
        "SD_WEBUI_URL": "http://localhost:7860"
      }
    }
  }
}

VS Code (GitHub Copilot)

.vscode/mcp.json に追加:

{
  "servers": {
    "sd-api-mcp": {
      "command": "uvx",
      "args": ["sd-api-mcp"],
      "env": {
        "SD_WEBUI_URL": "http://localhost:7860"
      }
    }
  }
}

環境変数

変数名 デフォルト 説明
SD_WEBUI_URL http://host.docker.internal:7860 SD WebUI のベース URL
SD_AUTH_USER (なし) Basic 認証ユーザー名(任意)
SD_AUTH_PASS (なし) Basic 認証パスワード(任意)
SD_OUTPUT_DIR ./output 生成画像の保存先ディレクトリ
REQUEST_TIMEOUT 300 HTTP リクエストのタイムアウト秒数

ツールリファレンス

txt2img

テキストプロンプトから画像を生成し、ファイルに保存します。

パラメータ デフォルト 説明
prompt str 必須 生成プロンプト
negative_prompt str "" ネガティブプロンプト
steps int 20 サンプリングステップ数(1〜150)
width int 512 画像の幅 px(64〜2048)
height int 512 画像の高さ px(64〜2048)
cfg_scale float 7.0 CFG スケール(1.0〜30.0)
sampler_name str "Euler a" サンプラー名
scheduler_name str "Automatic" スケジューラー名
seed int -1 シード値(-1 でランダム)
batch_size int 1 生成枚数(1〜4)
restore_faces bool false 顔修復を有効にする
tiling bool false タイリング画像を生成する
distilled_cfg_scale float 3.5 Distilled CFG スケール(1.0〜30.0)
controlnet_units list null ControlNet ユニットのリスト
output_dir str "./output" 出力ディレクトリ

戻り値: 生成された画像ファイルの絶対パスリスト

img2img

入力画像とプロンプトから画像を生成し、ファイルに保存します。

パラメータ デフォルト 説明
init_image str 必須 入力画像のファイルパス
prompt str 必須 生成プロンプト
negative_prompt str "" ネガティブプロンプト
denoising_strength float 0.75 デノイズ強度(0.0〜1.0)
steps int 20 サンプリングステップ数(1〜150)
width int 512 画像の幅 px(64〜2048)
height int 512 画像の高さ px(64〜2048)
cfg_scale float 7.0 CFG スケール(1.0〜30.0)
sampler_name str "Euler a" サンプラー名
scheduler_name str "Automatic" スケジューラー名
seed int -1 シード値(-1 でランダム)
batch_size int 1 生成枚数(1〜4)
restore_faces bool false 顔修復を有効にする
tiling bool false タイリング画像を生成する
controlnet_units list null ControlNet ユニットのリスト
output_dir str "./output" 出力ディレクトリ

戻り値: 生成された画像ファイルの絶対パスリスト

get_sd_models

利用可能な Stable Diffusion モデルの一覧を返します。

パラメータなし。戻り値: モデル名の文字列リスト

set_sd_model

アクティブな Stable Diffusion モデルを変更します。

パラメータ デフォルト 説明
model_name str 必須 設定するモデル名

戻り値: 設定完了メッセージ(文字列)

get_sd_upscalers

利用可能なアップスケーラーの一覧を返します。

パラメータなし。戻り値: アップスケーラー名の文字列リスト

upscale_images

画像をアップスケールして保存します。

パラメータ デフォルト 説明
images list[str] 必須 アップスケールする画像ファイルパスのリスト
resize_mode int 0 0=倍率指定, 1=サイズ指定
upscaling_resize float 4.0 アップスケール倍率(resize_mode=0 時)
upscaling_resize_w int 512 目標幅 px(resize_mode=1 時)
upscaling_resize_h int 512 目標高さ px(resize_mode=1 時)
upscaler_1 str "R-ESRGAN 4x+" プライマリアップスケーラー
upscaler_2 str "None" セカンダリアップスケーラー
output_dir str "./output" 出力ディレクトリ

戻り値: 保存された画像ファイルの絶対パスリスト

get_controlnet_models

利用可能な ControlNet モデルの一覧を返します。

パラメータなし。戻り値: ControlNet モデル名の文字列リスト

get_controlnet_modules

利用可能な ControlNet プリプロセッサの一覧を返します。

パラメータなし。戻り値: ControlNet プリプロセッサ名の文字列リスト

開発者向け

環境構築

git clone https://github.com/HizZaniya/sd-api-mcp.git
cd sd-api-mcp
uv sync --group dev
pre-commit install

テスト実行

uv run pytest -v

型チェック・Lint:

uv run ty check
uv run ruff check .
uv run ruff format --check .

ファイル構成

src/sd_api_mcp/
├── server.py   # MCP プロトコル層 — ツール定義・リクエスト受付
└── client.py   # SD WebUI API 通信層 — httpx による HTTP クライアント
  • server.py: FastMCP のツールデコレータでツールを定義し、MCP プロトコルを処理する。SD WebUI への直接アクセスは行わない。
  • client.py: httpx を使って SD WebUI の REST API と通信する。MCP プロトコルを知らない。

リリース手順

  1. Conventional Commits 形式でコミットを積む(例: feat: add new tool, fix: handle timeout
  2. GitHub Actions の Release ワークフローを手動トリガーする
  3. cz bump がコミット履歴からバージョンを自動決定し、CHANGELOG.md を更新してタグを作成
  4. Publish ワークフローが自動実行され、TestPyPI で検証後 PyPI に公開される

コントリビューション

  1. main ブランチから feature ブランチを作成する
  2. テストを先に書いてから実装する(TDD)
  3. PR を作成する(テンプレートに従うこと)
  4. CI(lint / format / typecheck / test)がすべてパスしたらレビューを依頼する

コミットメッセージは Conventional Commits 形式を推奨します。

ライセンス

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sd_api_mcp-0.3.1.tar.gz (123.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sd_api_mcp-0.3.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file sd_api_mcp-0.3.1.tar.gz.

File metadata

  • Download URL: sd_api_mcp-0.3.1.tar.gz
  • Upload date:
  • Size: 123.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sd_api_mcp-0.3.1.tar.gz
Algorithm Hash digest
SHA256 75e7862936bdcb7e6c45e8f19c6f0e0aa593c37298349460cdae37fb0a7f1907
MD5 c9e0db7122283f0b3076ef483de083ea
BLAKE2b-256 ca84499e39e1da45052f2dbf010501383557e73b64f17eaef0e78cfc3f8e2c16

See more details on using hashes here.

Provenance

The following attestation bundles were made for sd_api_mcp-0.3.1.tar.gz:

Publisher: publish.yml on HizZaniya/sd-api-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sd_api_mcp-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: sd_api_mcp-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sd_api_mcp-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 47810cf50520782de2df981a0ceafe4fb47ae77d680b36af37a1a6e19e418bc5
MD5 b7dd7e9b83bb65d8af68e640b4913b72
BLAKE2b-256 032bf905d7488fa8f9e87ed0298724133b8f08dd52a958d45809412991914fd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for sd_api_mcp-0.3.1-py3-none-any.whl:

Publisher: publish.yml on HizZaniya/sd-api-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page