Skip to main content
Glama

Booru-Pictag-Get-MCP

⚠️ 纯 AI 生成声明 | Pure AI-Generated Notice — 详见 AIGC_NOTICE.md

An MCP server that searches booru image boards (Danbooru / AIBooru / e621 / Gelbooru / Rule34) and cleans their tags into ready-to-use AI-art prompts for Stable Diffusion / Illustrious / Pony / SDXL and any booru-tag-driven model.

This is a Python port + MCP integration of booru-prompt-gallery by Mexes-GM (MIT). The prompt-cleaning pipeline — tag extraction, multi-subject guard, smart tag combination, redundancy folding, category splitting, background modes — is a 1:1 port of the original TypeScript modules. Wrapped as 9 callable MCP tools (4 prompt-building + 5 Danbooru character/tag analysis tools, the latter ported from the former standalone Danbooru-Search-MCP so callers have a single booru MCP), no Web UI, no Supabase/Redis/Cloudflare deps. See AIGC_NOTICE.md for the full derivation & attribution.

Upstream

Mexes-GM/booru-prompt-gallery — TypeScript + Next.js 15 web app (MIT)

This repo

echo-xianyu/Booru-Pictag-Get-MCP — Python 3 + FastMCP server

License

MIT — original credit preserved, dual attribution. See LICENSE


Install

Option A — local path

Clone, then point uvx at the local checkout:

git clone https://github.com/echo-xianyu/Booru-Pictag-Get-MCP.git
cd Booru-Pictag-Get-MCP
uvx --from . booru-pictag-get-mcp

Option B — cloud / direct from GitHub

uvx --from "git+https://github.com/echo-xianyu/Booru-Pictag-Get-MCP" booru-pictag-get-mcp
uvx --from . --with h2 booru-pictag-get-mcp

e621's TLS stack frequently errors out on HTTP/1.1 keep-alive. The HTTP client auto-detects h2 and falls back to HTTP/1.1 if absent.


Related MCP server: civitai-mcp-ultimate

Configure (opencode / any MCP client)

{
  "mcp": {
    "booru-pictag-get": {
      "command": "uvx",
      // Option A — local:
      "args": ["--from", "E:\\MCP\\booru-pictag-get-mcp", "booru-pictag-get-mcp"],
      // Option B — cloud (no checkout on disk):
      // "args": ["--from", "git+https://github.com/echo-xianyu/Booru-Pictag-Get-MCP", "booru-pictag-get-mcp"],
      // HTTP/2 for e621 — prepend "--with", "h2" to args above.
      "environment": {
        "BOORU_DEFAULT_PROVIDER": "danbooru",
        "DANBOORU_USERNAME_APIKEY": "youruser:yourkey",    // optional, raises rate limit
        "GELBOORU_USER_ID": "<your_user_id>",             // required by Gelbooru since 2025-08
        "GELBOORU_API_KEY": "<your_api_key>",
        "RULE34_USER_ID": "<your_user_id>",               // required by Rule34 since 2025-08
        "RULE34_API_KEY": "<your_api_key>",
        "BOORU_MAX_TAGS_DANBOORU": "6"                     // optional: raise a provider's per-search tag cap (default: danbooru/aibooru/e621 = 2, gelbooru/rule34 = 10)
      }
    }
  }
}

API key policy (Aug 2025): Danbooru, AIBooru, and e621 work with no key. Gelbooru and Rule34 tightened auth and now require keys. Without them, those two providers return 401; the others keep working.

Multi-tag search limits: every provider caps how many plain tags one query may combine — danbooru / aibooru / e621 = 2 tags (per site docs; Danbooru Gold accounts get 6), gelbooru / rule34 = 10 tags (per their API docs' "any tag combination"). Metatags (order:rank, rating:safe, sort:score, …) do not count toward the limit. Exceeding the cap returns a clear error telling you how to fix it. To raise (or lower) a cap, set BOORU_MAX_TAGS_<PROVIDER> (e.g. BOORU_MAX_TAGS_DANBOORU=6 for a Gold account).


Tools

Prompt-building tools (multi-provider: Danbooru / AIBooru / e621 / Gelbooru / Rule34)

Tool

Use it for

search_prompts

Recommended for ready-to-use prompts. Search a booru tag → cleaned prompt + category split. One step.

build_prompt

Clean an already-known tag set (no network). Accepts raw booru format or comma-list.

search_posts

Raw post list (no cleaning). Inspect original tags before deciding how to process them.

autocomplete_tags

Turn a natural word, partial fragment, or non-English term (Chinese / Japanese other_names) into the canonical booru tag form. Alias + fuzzy + auto-correction aware. Call BEFORE search if unsure of a tag's spelling.

Danbooru character / tag analysis tools (Danbooru-only — ported from the former Danbooru-Search-MCP)

These answer a different question from the prompt builders above. The prompt builders return sample images each turned into a prompt; the analysis tools describe a known character/tag: visual-trait frequency tables, wiki text, tag-implication chains, costume variants.

Tool

Use it for

danbooru_get_character_profile

Recommended first for character lookups. One call returns: trait frequencies (e.g. halo/ahoge/pink_hair for Hoshino), wiki page + multilingual aliases, and bidirectional tag implications (source work + all costume variants). Auto-resolves misspellings/Chinese names.

danbooru_search_character

Just the visual-trait co-occurrence table for a character tag (with optional category filter and frequency threshold).

danbooru_lookup_tag

Find or verify a tag's exact canonical name. Alias/fuzzy/prefix matching; supports * wildcards; falls back to tags.json. Use to list e.g. all *_(blue_archive) character variants.

danbooru_get_wiki_page

Get the textual wiki page for a tag (DText stripped to readable plain text; exposes other_names).

danbooru_get_tag_implications

Get the implication chain for a tag (what does this tag auto-add). For reverse direction (costume variants implying this tag) use danbooru_get_character_profile instead.

Routing guidance

Each tool's description in tools/list carries full guidance, but the short version:

  • "What does character X look like?" / "list X's costume variants" / "describe tag Y" → danbooru_get_character_profile (it aggregates everything). Do not route these to search_prompts — that returns sample-image prompts, not a description.

  • Find the canonical tag name for a Chinese/Japanese term or a misspelling → autocomplete_tags (alias / fuzzy / other_names aware). search_prompts cannot do this.

  • Booru search is tag-based AND, not keyword search. Multi-tag queries are supported up to each provider's limit (danbooru/aibooru/e621 = 2, gelbooru/rule34 = 10), but prefer a single tag (hatsune_miku) over stacking (hatsune_miku blue_hair smile), which usually returns 0 posts.

  • Multi-word tags use underscore: blue_hair, never blue hair.

  • Don't write natural-language queries ("a girl with blue hair sitting in a classroom"); translate to booru tags first via autocomplete_tags.


Scope & design choices

  • Pure Python — no Supabase / Redis / Cloudflare / Vercel. Endpoints are public booru APIs; no proprietary backend.

  • Tag-conflict rules are off by default in the prompt pipeline (mirrors the original cleanPrompt.ts, which never called tag-conflicts.ts). The 180+ rules were authored assuming a single subject — enabling them by default would mangle legitimate multi-character prompts (e.g. 1girl+1boy sex scenes, smile+crying bittersweet scenes, long_hair+short_hair two-character shots). The resolver remains callable via booru_mcp.core.tag_conflicts.resolve_conflicts() for explicit opt-in.

  • optimize_tags has a multi-subject guard: when the prompt contains multi-character markers (2girls / 2boys / multiple_* / couple / group / duo …), it skips the hair-length / breast-size / eye-color "keep best per hierarchy" pick and the shared-noun tag combination — so two characters with different features survive intact.

  • Tag categories for Gelbooru/Rule34 come from a static data/tag_categories.json dictionary (one-shot dump from Danbooru's public tags.json, generated by scripts/dump_tag_categories.py) with a keyword-classifier fallback. No external database at runtime.

  • Tag-conflict rules are overridable via data/tag_conflicts_overrides.json (additive — overrides can only widen a built-in rule, never narrow it). See data/tag_conflicts_overrides.example.json. Audit current rules with python scripts/inspect_tag_conflicts.py --builtin.

  • Danbooru character/tag analysis tools are integrated. The five danbooru_get_character_profile / danbooru_search_character / danbooru_lookup_tag / danbooru_get_wiki_page / danbooru_get_tag_implications tools were originally a separate MCP (Danbooru-Search-MCP). They now live inside this package via core/danbooru_meta.py, all reusing the same HTTP client — so Danbooru Basic Auth uses the same env vars as the rest of this server (DANBOORU_USERNAME + DANBOORU_API_KEY, or the combined DANBOORU_USERNAME_APIKEY), not the old DANBOORU_LOGIN/DANBOORU_API_KEY pair. The standalone Danbooru-Search-MCP can be removed from your MCP client config once this version is installed.


Credits

Prompt-cleaning pipeline ported (1:1 line-for-line where possible) from booru-prompt-gallery by Mexes-GM (MIT). Original copyright preserved in LICENSE.

Python port + MCP server by echo-xianyu. The vast majority of the code was generated by AI (opencode + GLM-5.2); see AIGC_NOTICE.md for the full statement.

Available Tools

9 tools
autocomplete_tagsA

Autocomplete a tag fragment against the booru tag index, returning the canonical tag name with its post count and category. Use this to turn a natural word, partial fragment, or NON-ENGLISH term (Chinese/Japanese other_names like '星野', 'ホシノ') into the exact booru tag form before calling the search tools: user says → autocomplete query → pick returned name 'blue hair' → 'blue hair' → 'blue_hair' 'miku' → 'miku' → 'hatsune_miku' (or other) 'knight' → 'knight' → 'knight', 'female_knight', ... '星野'/'ホシノ' → '星野' → 'hoshino_(blue_archive)' (resolved via other_names + alias) 'amamya_kokoro' → 'amamya_kokoro' → 'amamiya_kokoro' (auto-corrected)

Behavior:

  • On Danbooru (default) the query goes through the /autocomplete.json?type=tag_query endpoint, which performs ALIAS resolution, FUZZY/prefix matching, and matches against a tag's other_names (so Chinese/Japanese/Romaji inputs resolve to the English canonical tag). Auto-correction: if the input is a misspelling that resolves to a single canonical tag, the first result is the correct one (and is_alias will mark alias entries).

  • You do NOT need a trailing '*'; the underlying endpoint treats the query as a tag-query prefix/fuzzy term.

  • Multi-word fragments are allowed (pass verbatim, e.g. 'long skirt' or 'long_skirt').

  • post_count lets you reject obscure tags (likely to return ~0 results in search_prompts). Prefer tags with post_count > 100.

  • category: 0=general, 1=artist, 3=copyright, 4=character, 5=meta — use this to choose between, e.g. 'blue_archive' (3, copyright) vs an artist named 'blue_archive' (1).

  • is_alias (bool) marks results that are alias entries; the name field already holds the canonical (non-alias) tag name to use.

  • For AIBooru (provider='aibooru') the Danbooru autocomplete index is used (since AIBooru mirrors its tag database); for rule34/gelbooru/e621 search use search_prompts/search_posts once you've found the tag name here (booru tags are largely cross-compatible).

Inputs: query (required), limit, provider.

build_promptA

Clean an already-known set of booru tags into a ready-to-use prompt. Use this when you already have a tag list (e.g. user pasted one or you received raw tags from search_posts) and only want the cleaned output. No network request is made.

tag_string accepts the SAME raw booru format that search_posts returns in raw_tags: space-separated, multi-word tags joined by UNDERSCORE ('1girl long_hair blue_eyes smile'). It also accepts a comma-separated list of already-cleaned tags ('1girl, long hair, blue eyes, smile') for idempotent re-cleaning. Do NOT pass natural-language sentences — split them into booru tags first (use autocomplete_tags to find the canonical form of each).

Inputs: tag_string (required), exclude, optimize, meta_tags, +9 more.

danbooru_get_character_profileA
Read-onlyIdempotent

RECOMMENDED FIRST CHOICE for any character/tag lookup.

Returns everything in one call: visual traits (co-occurrence frequencies), wiki description, multilingual aliases, and tag implications in both directions (what this tag implies, and what tags imply this one — e.g. all costume variants).

Aggregates these data sources in parallel:

  1. Related tags (co-occurrence frequencies) -> visual traits.

  2. Wiki page -> textual description and multilingual aliases.

  3. Tag implications (antecedent) -> tags auto-added by this tag.

  4. Tag implications (consequent) -> tags that auto-add this tag (e.g. costume variants like hoshino_(swimsuit)_(blue_archive) imply hoshino_(blue_archive)).

Each source degrades gracefully: a missing wiki page or empty implications do not fail the whole request.

When auto_resolve is enabled (default) and the queried tag does not exist on Danbooru, the tool corrects the tag name via autocomplete and rebuilds the profile. The correction is reported in resolved_from.

Args: tag (str): Character tag, e.g. 'hoshino_(blue_archive)'. Spaces are automatically converted to underscores; non-English queries (Chinese/Japanese other_names like '星野'/'ホシノ') are resolved via the autocomplete index. limit (int): Max characteristic tags (1-100, default 25). response_format (str): 'markdown' or 'json'. auto_resolve (bool): Auto-correct misspelled/non-canonical tags (default True).

Returns: str: Markdown profile or JSON. Error: "Error: ".

Examples: - "Give me everything about Hoshino from Blue Archive" -> tag='hoshino_(blue_archive)'. - "Full profile of Rem from Re:Zero" -> tag='rem_(re:zero)'.

Inputs: tag (required), limit, auto_resolve, response_format. Returns: result

danbooru_get_tag_implicationsA
Read-onlyIdempotent

Get the implication chain for a tag (A -> B auto-adds).

For character costume variants, use danbooru_get_character_profile which queries both directions. This tool queries only the antecedent direction (what does this tag imply).

A Danbooru implication A -> B means every post tagged A is automatically also tagged B. This tool queries the antecedent direction (what does this tag imply). For the reverse direction (what tags imply this tag, e.g. costume variants), use danbooru_get_character_profile which queries both directions.

For characters this often encodes the source work (hoshino_(blue_archive) -> blue_archive) and structural traits. Not every character tag has implications, so an empty list is a valid result.

Args: tag (str): Antecedent tag, e.g. 'hoshino_(blue_archive)'. Spaces are automatically converted to underscores. limit (int): Max implications (1-1000, default 50). response_format (str): 'markdown' or 'json'.

Returns: str: Markdown table or JSON. Error: "Error: ".

Examples: - "What tags are auto-added when tagging Hoshino?" -> tag='hoshino_(blue_archive)'. - "Trace the implication chain of pink_hair" -> tag='pink_hair'.

Inputs: tag (required), limit, response_format. Returns: result

danbooru_get_wiki_pageA
Read-onlyIdempotent

Get the textual wiki description for a tag.

For complete character info, use danbooru_get_character_profile instead. This tool retrieves the wiki page only. Wiki pages contain the canonical description, often listing a character's appearance, source work, voice actor, and alternate costumes.

The body is written in Danbooru DText markup; this tool converts it to readable plain text in markdown mode.

Args: title (str): Wiki title, e.g. 'hoshino_(blue_archive)'. Spaces are automatically converted to underscores. body_limit (int): Truncate body to N chars (0 = no limit). Useful because some wiki pages are very long. response_format (str): 'markdown' or 'json'.

Returns: str: Markdown or JSON. A 404 returns "Error: Resource not found. ...". Error: "Error: " otherwise.

Examples: - "Describe Hoshino from Blue Archive" -> title='hoshino_(blue_archive)'. - "What does the ahoge tag mean?" -> title='ahoge'.

Inputs: title (required), body_limit, response_format. Returns: result

danbooru_lookup_tagA
Read-onlyIdempotent

Utility: find or verify a tag's exact canonical name.

NOT for character analysis — use danbooru_get_character_profile or danbooru_search_character for that. This tool is for finding/verifying tag names and listing related tag variants (e.g. all costume variants of a character).

Uses Danbooru's autocomplete endpoint as the primary search engine because it reliably resolves aliases (e.g. amamya_kokoro -> amamiya_kokoro) and performs prefix matching without requiring explicit * wildcards. The tags.json endpoint is used only as a fallback when autocomplete returns nothing.

Args: query (str): Name pattern. Wildcards (*) supported but often unnecessary — autocomplete does prefix/fuzzy matching, and also matches against the tag's other_names (so Chinese/Japanese queries resolve to the English canonical tag). category (str|None): Filter to one category: 'general', 'artist', 'copyright', 'character', or 'meta'. Omit for all categories. limit (int): Max results (1-200, default 25). order (str): 'count' (post count desc, default), 'name' (name asc), or 'date' (created desc). hide_empty (bool): Hide zero-post tags (default True). response_format (str): 'markdown' or 'json'. auto_resolve (bool): Fall back to tags.json if autocomplete returns nothing (default True).

Returns: str: Markdown table or JSON. Error: "Error: ".

Examples: - "Does the tag amamiya_kokoro exist?" -> query='amamiya_kokoro'. - "Find Amamiya Kokoro even if misspelled" -> query='amamya_kokoro' (autocomplete corrects it to amamiya_kokoro). - "List all Blue Archive character tags" -> query='*_(blue_archive)', category='character', order='count'.

Inputs: query (required), limit, order, category, +3 more. Returns: result

danbooru_search_characterA
Read-onlyIdempotent

Get visual trait frequencies for a character tag.

Best tool for character visual trait analysis. Use danbooru_get_character_profile if you also need wiki/implications. Given a character or copyright tag (e.g. hoshino_(blue_archive)), it returns the tags that most frequently appear alongside it on Danbooru posts. A tag with frequency 0.92 (like ahoge or pink_hair for Hoshino) appears in 92% of posts carrying the query tag, so it is a defining visual trait.

Results are ordered by co-occurrence frequency (descending). Meta tags such as highres are excluded by default because they describe image quality, not the character.

When auto_resolve is enabled (default) and the queried tag does not exist on Danbooru, the tool automatically queries the autocomplete endpoint to find the correct name (e.g. correcting a misspelled amamya_kokoro to amamiya_kokoro), re-runs the search with the corrected name, and reports the correction in resolved_from.

Args: tag (str): Canonical Danbooru tag, e.g. 'hoshino_(blue_archive)'. Spaces -> underscores automatically; non-English queries resolve via the autocomplete index when auto_resolve is on. limit (int): Max related tags to return (1-100, default 25). category (str|None): Filter to one category: 'general', 'artist', 'copyright', 'character', or 'meta'. Omit for all categories. min_frequency (float): Min co-occurrence frequency 0-1. A tag with frequency 0.9 appears in 90% of posts that carry the query tag. exclude_meta (bool): Drop meta tags (default True). response_format (str): 'markdown' or 'json'. auto_resolve (bool): Auto-correct misspelled tags (default True).

Returns: str: Markdown table or JSON. Error: "Error: ".

Examples: - "What does Hoshino from Blue Archive look like?" -> tag='hoshino_(blue_archive)' -> returns ahoge, pink_hair, blue_eyes, heterochromia, halo, ... - "Find all copyright tags related to this character" -> tag='hoshino_(blue_archive)', category='copyright'.

Inputs: tag (required), limit, category, auto_resolve, +3 more. Returns: result

search_postsA

Search a booru and return the raw post list (no cleaning). The same search semantics as search_prompts apply:

  • Query with one or more booru TAGs (underscores for multi-word: 'blue_hair', 'hatsune_miku'), never write natural language.

  • Tags AND together — every tag must be present in each returned post. PREFER A SINGLE TAG; stacking tags usually returns 0 posts. The cleaned prompt is where 'more detail' lives, not in the search query.

  • MULTI-TAG SEARCH IS SUPPORTED but each provider caps how many plain tags you may combine per query: danbooru/aibooru/e621 = 2, gelbooru/rule34 = 10 (metatags like order:rank or rating:safe do not count). Exceeding the limit returns an error; raise a provider's cap with the BOORU_MAX_TAGS_ env var.

  • When unsure how a concept is tagged, call autocomplete_tags first. Use this tool when you want to inspect the original tags before deciding how to process them. Each post carries its raw tag_string, the artist/character/copyright splits (when available), and optionally preview/file URLs.

Inputs: tags (required), page, limit, order, +5 more.

search_promptsA

Search an image booru (Danbooru/AIBooru/e621/Gelbooru/Rule34) by TAG and return ready-to-use, cleaned AI-art prompts. Each result has the full prompt string plus its category split (appearance/clothing/pose/scenery/character/quality/other). This is the recommended tool for finding 'ready-to-use AI painting tags'.

== WHEN TO USE A DIFFERENT TOOL INSTEAD ==

  • 'What does character X look like?' / 'list costume variants of X' / 'what tags describe X' -> use danbooru_get_character_profile (one call: trait frequency table + wiki + bidirectional implications). It is built for describing a known character, while search_prompts returns sample images each turned into a prompt — different goals.

  • 'Find the canonical tag name for a Chinese/Japanese term or a misspelling' -> use autocomplete_tags (alias/fuzzy/other_names aware).

== SEARCH SEMANTICS — read this before calling ==

  • This is NOT a keyword-search engine like Google. You query with one or more booru TAGS, and results are images ALL of whose tags are present.

  • A booru tag is a single token, multi-word tags use UNDERSCORE: 'blue_hair', 'hatsune_miku', 'sitting_on_chair' — never 'blue hair'.

  • MULTI-TAG SEARCH IS SUPPORTED but each provider caps how many plain tags you may combine per query: danbooru/aibooru/e621 = 2, gelbooru/rule34 = 10 (metatags like order:rank or rating:safe do not count). Exceeding the limit returns an error telling you how to fix it; you can also raise a provider's cap with the BOORU_MAX_TAGS_ env var (e.g. BOORU_MAX_TAGS_DANBOORU=6 for a Gold account).

  • STRONGLY PREFER A SINGLE TAG to start. 'hatsune_miku' returns thousands of well-tagged images; 'hatsune_miku blue_hair school_uniform smile' is treated as AND → dramatically fewer results (often zero). The cleaned prompt already contains far more detail than your search tag, so adding search tags is at best redundant and at worst returns nothing.

  • When you need a pure-quality / generalized set (no specific character or franchise yet), search '1girl' or '1boy' alone, or use 'random' order.

  • Do not write natural-language queries ('a girl with blue hair sitting in a classroom') — that is not supported. Translate to booru tags first.

  • Use autocomplete_tags if you are not sure how a concept is spelled as a booru tag (e.g. user said '法国女仆' → try 'french', 'maid' and let autocomplete return 'french maid', 'maid_uniform', etc.).

  • Common useful single-tag starting points: a character tag ('hatsune_miku'), an artist tag, a copyright tag ('blue_archive'), a character + single qualifier ('2girls' for group shots), or 'order:rank' / 'random' for non-themed browsing via order param.

Inputs: tags (required), page, limit, order, +13 more.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A4.1/5.0

    Scored across 9 tools

    Disambiguation2/5

    Several tools have heavily overlapping purposes: danbooru_lookup_tag and autocomplete_tags both resolve canonical tag names; danbooru_get_character_profile and danbooru_search_character both return trait co-occurrence frequencies; and danbooru_get_wiki_page / danbooru_get_tag_implications are subsets of the profile tool. This makes it difficult for an agent to confidently choose the right tool.

    Naming Consistency2/5

    Naming is mixed: some tools use a danbooru_ prefix (danbooru_lookup_tag, danbooru_get_character_profile), while others use bare verbs (search_prompts, search_posts, autocomplete_tags, build_prompt). Verb choices also vary (lookup, search, get, autocomplete, build) without a clear pattern.

    Tool Count4/5

    At 9 tools, the count is within a reasonable range, but several tools are near-duplicates (e.g., danbooru_lookup_tag vs autocomplete_tags, danbooru_get_character_profile vs danbooru_search_character). A more streamlined set of 6-7 tools would feel tighter without losing functionality.

    Completeness4/5

    The tool surface covers the core domain well: tag resolution, character profiling, wiki text, implications, post/prompt search, and prompt building. Minor gaps include no direct tool for browsing popular tags or fetching a single post by ID, but these are peripheral to the server's stated purpose.

    Maintenance

    ActivityInactive
    ResponsivenessLimited data

    Related MCP Connectors

    Related MCP Servers