Animagine MCP
An MCP server that lets AI agents validate, optimize, and explain anime-style prompts, manage local checkpoints/LoRAs, and generate images with Animagine XL 4.0.
Validate prompts (
validate_prompt) against Animagine XL rules — quality tags, ordering, 8+ tag count, character/series consistency, resolution risk — returningvalid,issues, andsuggestions.Optimize prompts (
optimize_prompt) from a natural-language description or existing prompt, reordering tags into canonical order (subject → character → series → appearance → composition → environment → style → quality) and filling missing essentials.Explain prompts (
explain_prompt) by breaking them into tags with category classification and per-tag effects, plus a canonically ordered version.List models (
list_models) to discover checkpoints incheckpoints/, LoRAs inloras/, the default checkpoint, and what's currently loaded.Pre-load a checkpoint (
load_checkpoint) into GPU memory to speed up later generations.Unload LoRAs (
unload_loras) to reset to the base checkpoint style without reloading the full model.Generate images (
generate_image, text-to-image) with custom checkpoints, multiple LoRAs with per-LoRA scales, width/height, steps, guidance scale, seed, negative prompt, and arender_typeguard to abort instead of falling back to slow CPU.Generate images from an image (
generate_image_from_image, img2img) with astrengthcontrol for style transfer, refinement, pose/composition preservation, or character consistency.Save reproducible outputs to
outputs/YYYY-MM-DD/with a sidecar JSON recording prompt, seed, size, steps, guidance, checkpoint, LoRAs, and render type.
Allows fetching and using models (e.g., Animagine XL 4.0) from Hugging Face for image generation.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Animagine MCP Optimize this prompt for Animagine XL: 1girl, solo, sitting in a cafe"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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 |
| Check a prompt against Animagine XL rules: quality tags present and last, 8+ tags, character/series consistency, resolution risk. Returns |
| Reorder tags into canonical order (subject → character → series → appearance → composition → environment → style → quality) and fill missing essentials. Returns |
| Discover checkpoints in |
| Generate an image. Pass |
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
.safetensorsfiles intocheckpoints/and reference them by filename.LoRAs: drop
.safetensorsfiles intoloras/. 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:
End with quality tags:
masterpiece, best quality, very aesthetic, absurdres.Start with subject count (
1girl,1boy,2girls, ...).Character tags should be followed by their series tag.
Aim for 8+ tags; order: subject → character → series → appearance → composition → environment → style → quality.
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 codesLicense
MIT — see LICENSE.
Model by Cagliostro Research Lab. Built with FastMCP and Diffusers.
Available Tools
8 toolsexplain_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:
list_models → see available checkpoints and LoRAs
validate_prompt → check for issues
optimize_prompt → improve structure
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
Scored across 8 tools
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.
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.
Eight tools cover the core workflow of prompt preparation, model management, and generation. This is a well-scoped number that avoids unnecessary redundancy.
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
MCP server for Flux AI image generation
MCP server for Qwen Image 3 AI image generation
MCP server for Luma Dream Machine AI video generation
MCP server for Hailuo (MiniMax) AI video generation
Related MCP Servers
- AlicenseCqualityDmaintenanceA 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.1816MIT
- AlicenseNot gradedqualityDmaintenanceA FastMCP server implementation that provides a standardized interface for accessing AI models hosted on Replicate's API, currently supporting image generation with customizable parameters.3MIT
- AlicenseNot gradedqualityDmaintenanceThis 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.25MIT
- AlicenseAqualityBmaintenanceA 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.2127 PyPI27MIT