Danbooru Tag RAG MCP Server

Danbooru Tag RAG MCP Server

Enables semantic search of Danbooru tags using natural language queries to generate precise prompts for anime-style image generation.

Category
Visit Server

README

Danbooru Tag RAG MCP Server

Danbooruタグのセマンティック検索を提供するMCP (Model Context Protocol) サーバーです。

概要

このMCPサーバーは、自然言語のクエリからDanbooruタグを検索する機能を提供します。SDXLアニメモデルはDanbooruタグで学習されているため、適切なタグを使用することで画像生成の精度が向上します。

特徴

  • セマンティック検索: キーワード一致ではなく、意味的に関連するタグを検索
  • 日本語・英語対応: multilingual-e5-small モデルによる多言語サポート
  • ローカル実行: 外部APIを使用せず、完全にローカルで動作
  • 軽量: LanceDBによる効率的なベクトル検索

技術スタック

コンポーネント 技術 理由
MCP SDK mcp (公式SDK) 標準プロトコル準拠
ベクトルDB LanceDB 軽量、ローカル実行に最適
埋め込みモデル multilingual-e5-small 日英対応、高精度、CPU対応
パッケージ管理 uv モダンで高速

インストール

Claude Desktopの設定ファイル(claude_desktop_config.json)に以下を追加:

{
  "mcpServers": {
    "danbooru-rag": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/Zaozaotvk40/danbooru-rag-mcp.git", "danbooru-rag-mcp"]
    }
  }
}

初回起動時にインデックスが自動構築されます(約60,000タグ、数分かかります)。

使用例

Claude Desktopでこのツールを有効にすると、自然言語でプロンプト生成を依頼できます。

例1: キャラクター描写

あなた: 「青い髪のツインテールの女の子が魔法を使っているシーンのプロンプトを作って」

Claude: semantic_searchで関連タグを検索し、以下のようなプロンプトを生成します:
→ 1girl, blue hair, twintails, magic, casting spell, glowing, magical effects, ...

例2: 風景シーン

あなた: 「夕焼けのファンタジー風景のプロンプトをお願い」

Claude: 関連タグを検索して組み合わせます:
→ scenery, sunset, fantasy, sky, clouds, orange sky, landscape, no humans, ...

例3: 複雑なシーン

あなた: 「カフェで本を読んでいる眼鏡の女の子、窓から光が差し込んでいる感じで」

Claude: 複数の要素を検索して統合します:
→ 1girl, glasses, book, reading, cafe, indoors, window, sunlight, sitting, ...

Claudeが自動的にsemantic_searchツールを使用し、Danbooruタグに基づいた画像生成プロンプトを作成します。

プロジェクト構造

danbooru-rag-mcp/
├── README.md                 # このファイル
├── pyproject.toml            # パッケージ設定
├── danbooru-tags.txt         # ソースデータ
├── src/
│   └── danbooru_rag/
│       ├── __init__.py       # パッケージ初期化
│       ├── __main__.py       # モジュールエントリーポイント
│       ├── config.py         # 設定定数
│       ├── embeddings.py     # 埋め込み生成
│       ├── database.py       # LanceDB操作
│       ├── builder.py        # インデックス自動構築
│       └── server.py         # MCPサーバー本体
├── scripts/
│   └── build_index.py        # インデックス手動構築
└── tests/
    └── ...                   # テスト

データベース保存先:

  • Windows: %LOCALAPPDATA%\danbooru-rag\lancedb
  • macOS: ~/Library/Application Support/danbooru-rag/lancedb
  • Linux: ~/.local/share/danbooru-rag/lancedb

設計判断

なぜmultilingual-e5-smallか?

  1. 日本語・英語両対応: ユーザーがどちらの言語でクエリしても対応
  2. 高精度: all-MiniLM-L6-v2より高いベンチマークスコア
  3. CPU対応: GPUなしでも実用的な速度で動作
  4. E5プレフィックス: query:/passage: プレフィックスで精度向上

なぜLanceDBか?

  1. サーバー不要: ファイルベースでローカル実行に最適
  2. Pythonネイティブ: 簡単にインストール・使用可能
  3. 高速: ベクトル検索に最適化

なぜ出現頻度100以下をフィルタリングするか?

  1. 学習データの品質: 低頻度タグはSDXLモデルの学習が不十分
  2. インデックス効率: 99,999件 → 約60,000件に削減
  3. 検索精度向上: ノイズとなる低頻度タグを除外

開発

テスト実行

uv run pytest tests/

コード品質

# 型チェック
uv run mypy src/

# フォーマット
uv run ruff format src/

# リント
uv run ruff check src/

ライセンス

MIT License

データソース

danbooru-tags.txt は ComfyUI-Custom-Scripts で利用されている以下のデータをベースにしています:

https://gist.githubusercontent.com/pythongosssss/1d3efa6050356a08cea975183088159a/raw/a18fb2f94f9156cf4476b0c24a09544d6c0baec6/danbooru-tags.txt

オリジナルのタグ名はアンダーバー区切り(例: blue_hair)ですが、本プロジェクトではスペース区切り(例: blue hair)に変換して使用しています。

謝辞

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured