Skip to main content
Glama

anime-diffusion-mcp

MCP server for anime image generation with Animagine XL 4.0. Gives AI agents four tools: validate and optimize Danbooru-style prompts, list local models, and generate images (text-to-image or image-to-image) with custom checkpoints and LoRAs.

Requirements

  • Python 3.11+

  • NVIDIA GPU with ~7 GB VRAM recommended (CPU works, but is very slow)

  • ~7 GB of disk for the base model (downloaded from HuggingFace on first generation)

Related MCP server: MCP Server for Replicate

Installation

git clone https://github.com/gabrielalmir/anime-diffusion-mcp.git
cd anime-diffusion-mcp
python -m venv .venv
# Windows: .venv\Scripts\activate  |  Linux/macOS: source .venv/bin/activate
pip install -e .

For CUDA, install the matching PyTorch build first (see https://pytorch.org/get-started/locally/), then pip install -e ..

Docker

GPU only. The image is a slim Python base plus the CUDA 12.4 PyTorch wheel (the wheel already contains the CUDA runtime). It always starts with --gpus all and exits if no GPU device is visible (/dev/nvidia* on Linux, /dev/dxg on Docker Desktop / WSL2) — there is no CPU fallback. The ~7 GB Animagine weights are not in the image: the first generation downloads them into .cache/huggingface/, which is bind-mounted and reused.

Requires an NVIDIA driver new enough for CUDA 12.4, plus GPU access in Docker (Docker Desktop WSL integration, or the NVIDIA Container Toolkit). An RTX 3060 12 GB is enough for the default 832×1216 render.

docker compose build
# smoke test (imports only; does not load the model)
docker run --rm --gpus all --user "$(id -u):$(id -g)" --entrypoint python anime-diffusion-mcp:latest \
  -c "import torch; assert torch.version.cuda and torch.cuda.is_available(); print(torch.version.cuda)"

Point the MCP client at the absolute path of scripts/mcp-docker.sh (see .mcp.json.example). The script runs docker run -i --rm --gpus all — stdin attached, no TTY — and bind-mounts checkpoints/, loras/, outputs/ and .cache/. Do not add -t; a TTY corrupts the MCP protocol. CUDA_VISIBLE_DEVICES defaults to 0.

A gated Hugging Face repo needs HF_TOKEN in the client env; the script forwards it. Custom checkpoints and LoRAs stay in checkpoints/ and loras/ on the host — drop files there, no rebuild.

MCP client configuration

Add the server to your MCP client (Claude Desktop, Claude Code, Cursor, ...).

Docker (recommended, see .mcp.json.example) — use the absolute path, clients often ignore the project cwd:

{
  "mcpServers": {
    "anime-diffusion": {
      "command": "/absolute/path/to/anime-diffusion-mcp/scripts/mcp-docker.sh",
      "env": { "CUDA_VISIBLE_DEVICES": "0" }
    }
  }
}

Without Docker, command is anime-diffusion-mcp (or the venv script, e.g. .venv/bin/anime-diffusion-mcp). The process uses the current working directory for checkpoints/, loras/ and outputs/, so launch it from the project folder (or set cwd).

Tools

Tool

Purpose

validate_prompt(prompt, width, height, negative_prompt)

Check a prompt against Animagine XL rules: quality tags present and last, 8+ tags, character/series consistency, resolution risk. Returns valid, issues, suggestions.

optimize_prompt(description | prompt)

Reorder tags into canonical order (subject → character → series → appearance → composition → environment → style → quality) and fill missing essentials. Returns optimized_prompt, actions, warnings.

list_models()

Discover checkpoints in checkpoints/ and LoRAs in loras/.

generate_image(prompt, ...)

Generate an image. Pass image_path for img2img. Supports checkpoint, loras + lora_scales, width/height, steps, guidance_scale, seed, render_type.

Typical agent flow: optimize_prompt → validate_prompt → generate_image.

generate_image example

{
  "prompt": "1girl, solo, hatsune miku, vocaloid, long hair, twintails, smile, upper body, city night, neon lights, masterpiece, best quality, very aesthetic, absurdres",
  "width": 832,
  "height": 1216,
  "steps": 28,
  "guidance_scale": 5.0,
  "seed": 42
}

Add "image_path": "C:/path/to/source.png", "strength": 0.5 for image-to-image (output size follows the source). Add "loras": ["my_style.safetensors"], "lora_scales": [0.8] to apply LoRAs — they are applied per call; a call without loras runs on the bare checkpoint.

Set "render_type": "gpu" to abort instead of silently falling back to a slow CPU render when CUDA isn't available.

Models

  • Base model: cagliostrolab/animagine-xl-4.0, fetched from HuggingFace (cached in ~/.cache/huggingface).

  • Custom checkpoints: drop SDXL .safetensors files into checkpoints/ and reference them by filename.

  • LoRAs: drop .safetensors files into loras/. Multiple LoRAs can be combined with independent scales.

Outputs

Images are written to outputs/YYYY-MM-DD/anime_HHMMSS.png with a sidecar .json containing prompt, negative prompt, seed, size, steps, guidance, checkpoint, LoRAs and render type — enough to reproduce the image.

Prompt rules (short version)

Animagine XL 4.0 expects Danbooru-style comma-separated tags:

  1. End with quality tags: masterpiece, best quality, very aesthetic, absurdres.

  2. Start with subject count (1girl, 1boy, 2girls, ...).

  3. Character tags should be followed by their series tag.

  4. Aim for 8+ tags; order: subject → character → series → appearance → composition → environment → style → quality.

  5. Use the default negative prompt unless you have a reason not to.

validate_prompt and optimize_prompt enforce these for you.

Development

pip install -e .
python -c "from anime_diffusion_mcp.server import mcp; print(mcp.name)"

Package layout:

src/anime_diffusion_mcp/
├── server.py        # FastMCP tools
├── prompt/          # tokenizer, classifier, validator, optimizer
├── diffusion/       # ImagePipeline (Diffusers wrapper, checkpoint/LoRA handling)
└── contracts/       # Pydantic schemas and error codes

License

MIT — see LICENSE.

Model by Cagliostro Research Lab. Built with FastMCP and Diffusers.

Available Tools

8 tools
explain_promptA

Explain what each tag in a prompt does.

Breaks down the prompt into individual tags with:

  • Category classification (quality, composition, character, etc.)

  • Explanation of what each tag affects

  • Canonically ordered version of the prompt

Inputs: prompt (required). Returns: object

generate_imageA

Generate an image with Animagine XL 4.0.

Uses the Diffusers pipeline with the lpw_stable_diffusion_xl custom pipeline. Images are saved to outputs/YYYY-MM-DD/ with accompanying metadata JSON.

Supports custom checkpoints and LoRA mixing for style control.

Recommended workflow:

  1. list_models → see available checkpoints and LoRAs

  2. validate_prompt → check for issues

  3. optimize_prompt → improve structure

  4. generate_image → create the image

Inputs: prompt (required), seed, loras, steps, +7 more. Returns: object

generate_image_from_imageA

Generate an image using img2img (image-to-image) transformation.

Takes an existing image and transforms it based on the prompt while preserving structure according to the strength parameter.

Use cases:

  • Style transfer (apply anime/comic/realistic style to photo)

  • Image refinement (improve details, fix artifacts)

  • Pose/composition preservation (keep layout, change style)

  • Character consistency (transform existing character art)

Inputs: prompt (required), image_path (required), seed, loras, +7 more. Returns: object

list_modelsA

List available checkpoints and LoRAs for image generation.

Returns all available models with metadata:

  • checkpoints: Base models (Animagine XL)

  • loras: Style modifiers and speed optimizations

Use this to discover what models are available before generation.

Returns: Dictionary with checkpoints, loras, default_checkpoint, and currently_loaded

Inputs: no named parameters. Returns: object

load_checkpointA

Pre-load a checkpoint into GPU memory.

Loading a checkpoint in advance speeds up subsequent generation calls. Use list_models() to see available checkpoints.

Inputs: checkpoint. Returns: object

optimize_promptA

Optimize a prompt for Animagine XL.

Provide either a natural language description or an existing prompt. The optimizer will:

  • Reorder tags by canonical category order

  • Move quality tags to the end

  • Add missing essential categories (composition, environment, quality)

Inputs: prompt, description. Returns: object

unload_lorasA

Unload all LoRA weights from the current pipeline.

Useful to reset to base checkpoint style without reloading the full model. This is faster than reloading the checkpoint.

Returns: Status with success, unloaded_count, and message

Inputs: no named parameters. Returns: object

validate_promptA

Validate a prompt against Animagine XL rules.

Checks for:

  • Required quality tags (masterpiece, best quality, etc.)

  • Proper tag ordering (quality tags at end)

  • Minimum tag count (8+ recommended)

  • Character/series consistency

  • Resolution compatibility

Inputs: prompt (required), width, height, negative_prompt. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.2/5.0

    Scored across 8 tools

    Disambiguation5/5

    Each tool targets a distinct operation: prompt validation, optimization, explanation, model listing, checkpoint loading, LoRA unloading, text-to-image, and image-to-image. No two tools overlap in purpose, and the descriptions make the boundaries clear.

    Naming Consistency5/5

    All tools use a consistent verb_noun pattern in snake_case (validate_prompt, list_models, generate_image). The only slightly longer name is generate_image_from_image, but it follows the same convention clearly.

    Tool Count5/5

    Eight tools cover the core workflow of prompt preparation, model management, and generation. This is a well-scoped number that avoids unnecessary redundancy.

    Completeness4/5

    The server covers the main image generation workflow, including prompt handling and model configuration. Minor gaps exist, such as no explicit checkpoint unload tool, but list_models includes currently loaded state and unload_loras provides a reset path.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      C
      quality
      D
      maintenance
      A FastMCP server implementation that facilitates resource-based access to AI model inference, focusing on image generation through the Replicate API, with features like real-time updates, webhook integration, and secure API key management.
      18
      16
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      This MCP server provides research-backed prompt optimization tools and professional domain templates designed to improve AI performance through strategies like Tree of Thoughts and Medprompt. It enables users to analyze, auto-optimize, and refine prompts using advanced reasoning patterns and safety-critical alignment techniques.
      25
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      A comprehensive MCP server for interacting with the Civitai API to search models, browse images with generation prompts, and manage downloads. It features extensive support for various base models like SDXL and Flux, includes NSFW filtering, and provides automated download commands for ComfyUI.
      21
      27 PyPI
      27
      MIT