Skip to content

ペイントツールKritaを操作するためのMCPサーバー

License

Notifications You must be signed in to change notification settings

halby24/KritaMCP

Repository files navigation

KritaMCP

Krita用のMCP (Model Context Protocol) サーバー。AIアシスタントからKritaを操作できるようにするプラグインです。

アーキテクチャ

AI Client (Claude等)
    │
    │  MCP (SSE transport, port 8001)
    ▼
MCP Server (kritamcp-server)
    │
    │  HTTP/SSE Bridge (port 8000)
    ▼
Krita Plugin (krita-plugin/)
    │
    │  Krita Python API
    ▼
  Krita
  • MCP Server: FastMCPベースのMCPサーバー。AIクライアントからのリクエストを受け、HTTP/SSE経由でKritaプラグインにコマンドを送信
  • Krita Plugin: KritaのPythonプラグイン。MCPサーバーからSSEでコマンドを受信し、Krita APIを使って実行

利用可能なMCPツール

ツール 説明
ping Kritaとの接続確認
get_document_info アクティブなドキュメントの情報を取得
create_document 新しいドキュメントを作成
save_document ドキュメントを保存
get_layers レイヤー階層の取得
execute_python Kritaの組み込みPython環境でコードを実行

必要な環境

  • Python 3.12+
  • Krita (Pythonプラグイン対応)
  • uv または pipx

インストール

1. MCPサーバーのインストール

方法A: uvxで直接実行 (インストール不要)

uvx kritamcp-server

依存関係は一時的な環境に自動でインストールされ、実行後にクリーンアップされます。

方法B: ツールとしてインストール

# uvの場合
uv tool install kritamcp

# pipxの場合
pipx install kritamcp

インストール後、kritamcp-server コマンドが使えるようになります。

2. Kritaプラグインのインストール

krita-plugin/kritamcp/ ディレクトリと krita-plugin/kritamcp.desktop をKritaのpykritaディレクトリにコピーまたはシンボリックリンク:

# Linux
ln -s /path/to/krita-plugin/kritamcp ~/.local/share/krita/pykrita/kritamcp
ln -s /path/to/krita-plugin/kritamcp.desktop ~/.local/share/krita/pykrita/kritamcp.desktop

# macOS
ln -s /path/to/krita-plugin/kritamcp ~/Library/Application\ Support/krita/pykrita/kritamcp
ln -s /path/to/krita-plugin/kritamcp.desktop ~/Library/Application\ Support/krita/pykrita/kritamcp.desktop

# Windows (管理者権限のPowerShell)
New-Item -ItemType SymbolicLink -Path "$env:APPDATA\krita\pykrita\kritamcp" -Target "C:\path\to\krita-plugin\kritamcp"
New-Item -ItemType SymbolicLink -Path "$env:APPDATA\krita\pykrita\kritamcp.desktop" -Target "C:\path\to\krita-plugin\kritamcp.desktop"

3. Kritaでプラグインを有効化

  1. Kritaを起動
  2. Settings > Configure Krita > Python Plugin Manager を開く
  3. KritaMCP にチェックを入れて有効化
  4. Kritaを再起動

使い方

MCPサーバーの起動

方法A: Krita内から起動 (推奨)

  1. Kritaで Settings > Dockers > KritaMCP を有効化
  2. KritaMCPパネルの Start ボタンをクリック

プラグインが自動的に kritamcp-server を起動します。

方法B: コマンドラインから起動

kritamcp-server

環境変数でポートを変更可能:

MCP_SERVER_PORT=8001 MCP_BRIDGE_PORT=8000 kritamcp-server

AIクライアントの設定

Claude Desktop等のMCPクライアントに以下を設定:

{
  "mcpServers": {
    "krita": {
      "type": "sse",
      "url": "http://localhost:8001/sse"
    }
  }
}

開発

Dev Container (Docker環境)

このプロジェクトはDev Container構成を同梱しています。VS CodeやClaude Codeで自動的に開発環境が構築されます。

# Dev Containerを起動後
uv sync

Dev Containerでは以下のサービスが起動します:

  • dev: 開発用コンテナ (Python 3.12, uv, Claude Code CLI)
  • krita: Krita GUIコンテナ (ブラウザから localhost:3001 でアクセス)

ローカル開発

# 編集可能インストール
uv tool install -e .

# 変更後は再インストール
uv tool install --force -e .

ディレクトリ構造

krita-plugin/              # Kritaプラグイン
  ├── __init__.py           # エントリーポイント
  ├── kritamcp.desktop      # プラグインメタデータ
  └── kritamcp/
      ├── __init__.py       # Extension・Dockerウィジェット登録
      ├── krita_actions.py  # Krita API操作の実装
      ├── mcp_client.py     # MCPサーバーとのSSE通信クライアント
      ├── server_manager.py # MCPサーバープロセスの管理
      └── docker_widget.py  # Krita UIウィジェット
mcp_server/                # MCPサーバー
  ├── __init__.py
  ├── server.py             # サーバーエントリーポイント
  ├── tools.py              # MCPツール定義
  └── krita_bridge.py       # Kritaプラグインとの通信ブリッジ
.devcontainer/             # Dev Container設定

ライセンス

MIT

About

ペイントツールKritaを操作するためのMCPサーバー

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published