webcomic-background-mcp 3.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. webcomic_background_mcp-3.1.0/PKG-INFO +340 -0
  2. webcomic_background_mcp-3.1.0/README.md +319 -0
  3. webcomic_background_mcp-3.1.0/__init__.py +6 -0
  4. webcomic_background_mcp-3.1.0/_home.py +11 -0
  5. webcomic_background_mcp-3.1.0/citygen.py +366 -0
  6. webcomic_background_mcp-3.1.0/klein.py +342 -0
  7. webcomic_background_mcp-3.1.0/props.py +242 -0
  8. webcomic_background_mcp-3.1.0/pyproject.toml +56 -0
  9. webcomic_background_mcp-3.1.0/server.py +635 -0
  10. webcomic_background_mcp-3.1.0/setup.cfg +4 -0
  11. webcomic_background_mcp-3.1.0/setup_models.py +111 -0
  12. webcomic_background_mcp-3.1.0/test_client.py +19 -0
  13. webcomic_background_mcp-3.1.0/test_generate.py +23 -0
  14. webcomic_background_mcp-3.1.0/tools/__init__.py +1 -0
  15. webcomic_background_mcp-3.1.0/tools/fix_green.py +43 -0
  16. webcomic_background_mcp-3.1.0/tools/grade.py +134 -0
  17. webcomic_background_mcp-3.1.0/tools/inpaint_region.py +80 -0
  18. webcomic_background_mcp-3.1.0/tools/letter_plaque.py +94 -0
  19. webcomic_background_mcp-3.1.0/tools/make_depth.py +56 -0
  20. webcomic_background_mcp-3.1.0/tools/make_sketch.py +131 -0
  21. webcomic_background_mcp-3.1.0/tools/parallax.py +132 -0
  22. webcomic_background_mcp-3.1.0/webcomic_background_mcp.egg-info/PKG-INFO +340 -0
  23. webcomic_background_mcp-3.1.0/webcomic_background_mcp.egg-info/SOURCES.txt +36 -0
  24. webcomic_background_mcp-3.1.0/webcomic_background_mcp.egg-info/dependency_links.txt +1 -0
  25. webcomic_background_mcp-3.1.0/webcomic_background_mcp.egg-info/entry_points.txt +2 -0
  26. webcomic_background_mcp-3.1.0/webcomic_background_mcp.egg-info/requires.txt +6 -0
  27. webcomic_background_mcp-3.1.0/webcomic_background_mcp.egg-info/top_level.txt +1 -0
  28. webcomic_background_mcp-3.1.0/world.py +307 -0
@@ -0,0 +1,340 @@
1
+ Metadata-Version: 2.4
2
+ Name: webcomic-background-mcp
3
+ Version: 3.1.0
4
+ Summary: Comic-panel backgrounds and a consistent world bible, rendered with FLUX 3 Klein on a local ComfyUI, as an MCP server.
5
+ Author: Tobias Fong
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://tobiasfong.github.io/projects/mcp-background.html
8
+ Project-URL: Repository, https://github.com/tobiasfong/webcomic-toolkit/tree/master/servers/webcomic-background-mcp
9
+ Project-URL: Changelog, https://github.com/tobiasfong/webcomic-toolkit/blob/master/servers/webcomic-background-mcp/CHANGELOG.md
10
+ Keywords: mcp,comics,manga,webcomic,backgrounds,comfyui,flux
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Multimedia :: Graphics
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: mcp<2,>=1.2.0
16
+ Requires-Dist: requests>=2.31.0
17
+ Requires-Dist: pillow>=10.0.0
18
+ Requires-Dist: numpy>=1.24.0
19
+ Requires-Dist: opencv-python-headless>=4.8.0
20
+ Requires-Dist: imageio-ffmpeg>=0.4.9
21
+
22
+ # Webcomic Background Generator — MCP Server
23
+
24
+ <!-- mcp-name: io.github.tobiasfong/webcomic-background -->
25
+
26
+ A local [Model Context Protocol](https://modelcontextprotocol.io) server that generates
27
+ **background art for comic panels** — Ming-dynasty cities, gothic hive cities, medieval
28
+ dungeons, whatever your story needs — in a crisp inked manhwa style, wrapping
29
+ [FLUX 3 Image Klein](https://huggingface.co/black-forest-labs/flux-3-image-klein-comfy)
30
+ on a local ComfyUI.
31
+
32
+ It exists to solve one concrete problem in making an illustrated webcomic:
33
+ drawing detailed environment backgrounds is slow. This tool lets the artist
34
+ describe a place (and optionally lay out its composition), and get back a
35
+ finished plate to put characters onto — keeping the human in charge of
36
+ characters, story and composition while offloading the repetitive scenery work.
37
+
38
+ > **v3.0.0 — FLUX 3 Klein only. FLUX.1-dev has been removed.**
39
+ > The server now renders exclusively with Klein, the model the sibling
40
+ > character-panel server already uses, so plates and figures come from one
41
+ > model and look like one drawing. With FLUX.1 went its manhwa LoRA (FLUX.1
42
+ > LoRAs cannot load in Klein), ControlNet (composition sketches are now passed
43
+ > to Klein as a reference image) and Kontext (edits now redraw only the box you
44
+ > give). It is also **~15x faster** — about 15 s per plate on a 6 GB laptop card,
45
+ > where FLUX.1 took ~225 s. See CHANGELOG for the measurements.
46
+ > **You will need Klein**; `setup_models.py` fetches it. There is no fallback model.
47
+
48
+ ## What it does
49
+
50
+ The main tools:
51
+
52
+ - **`generate_background`** — a plate from a **prompt**, optionally with a
53
+ composition **sketch** (white lines on black: it fixes the camera and where
54
+ every object sits) and/or a registered **location** (the place's canonical
55
+ plate, so a new view stays recognizably the same place — from any angle, not
56
+ just the canon's own framing).
57
+ - **`generate_city_scene`** — a giant establishing panel from a procedural 3D
58
+ gothic city, rendered to a sketch and drawn by Klein. Same seed = same city.
59
+ - **`generate_prop_scene`** — rows of repeated objects (first prop: bicycles)
60
+ from real 3D meshes, so they don't fuse or crop the way invented rows do.
61
+ - **`edit_background`** — change one thing on an approved plate with a
62
+ plain-English instruction; with a `mask_box`, nothing outside the box changes.
63
+ - **`register_location` / `list_world`** — the World Builder bible: register the
64
+ plate you approved as a place's canon, then draw it again consistently.
65
+ - **`grade_plate`** — darken or color-grade a finished plate for mood (how you
66
+ get a night or grimdark panel — never by asking the prompt for it).
67
+ - **`extract_palette`**, **`check_status`**, city-plan tools.
68
+
69
+ > **Prompting — rules measured on FLUX.1 and kept for Klein** (the far-distance
70
+ > one has already recurred on Klein; the others are carried over as standing rules).
71
+ > 1. **Name what the place IS, as physical objects.** No mood, lighting or
72
+ > "cinematic" words; they drag the render toward semi-realistic murk. Darken
73
+ > afterwards with `grade_plate`.
74
+ > 2. **No negatives.** There is no negative-prompt parameter, on purpose: the
75
+ > model draws what a prompt names, including what it is told to avoid.
76
+ > 3. **Name what fills the far distance** — forest, hills, a rampart. Leave it
77
+ > open and the model fills it from photographs: modern skylines behind a
78
+ > Ming river port.
79
+ > 4. **Open with period and place** ("Ming dynasty … in Anhui"). It holds a
80
+ > setting's architecture where a generic "ancient East Asian" invites drift.
81
+ >
82
+ > The house style sentence is appended automatically — the same one the
83
+ > character server uses.
84
+
85
+ ### Generate a background around your character
86
+
87
+ Works with **your own hand-drawn characters**, not just generated ones:
88
+
89
+ 1. **Size the plate to your character.** Pass `match_canvas_to=<character.png>`
90
+ to `generate_background`. The plate comes back at your character's canvas
91
+ size, and the response reports the exact `height_px` / `feet_x` / `feet_y` to
92
+ composite with. (The character is not used to condition the render; it only
93
+ sets dimensions.)
94
+ 2. **Cut your character out**, if it isn't already transparent.
95
+ `character-panel-mcp`'s `tools/cutout.py` keys a figure off a flat backdrop,
96
+ including a scan or a drawing on white paper.
97
+ 3. **Composite**, with that server's `compose_panel` — it takes *any* RGBA PNG
98
+ and pastes it bottom-centered at a given feet position and height.
99
+
100
+ For a plate from `generate_city_scene`, use `anchor_x`/`anchor_z` instead of
101
+ step 1: it reports the on-screen character height and feet line for a spot in
102
+ the 3D city, with occlusion accounted for.
103
+
104
+ ## Architecture
105
+
106
+ ```
107
+ MCP client (Claude)
108
+ │ stdio
109
+ ▼
110
+ server.py ──► klein.py ──HTTP──► Klein ComfyUI (:8189) ──► GPU
111
+ (FastMCP tools) (graphs, (v0.41+, FLUX 3 Image Klein
112
+ plumbing) INT8 + Qwen3-VL encoder)
113
+ │
114
+ ├─► citygen.py / props.py 3D geometry → composition sketches (CPU)
115
+ ├─► world.py the World Builder bible (JSON + canon PNGs)
116
+ └─► tools/grade.py mood grading (CPU)
117
+ ```
118
+
119
+ Sketches and locations are both **reference images** to Klein, each introduced
120
+ by a lead sentence saying what it is for. The wording matters and is measured:
121
+ "render it as a finished scene" came back photoreal, and a sketch's black areas
122
+ were drawn as empty void until the lead said they are ground, walls and sky.
123
+ `klein.py` keeps the wording that passed.
124
+
125
+ ### Why it's a *local* server
126
+
127
+ Each call runs a diffusion model on a local GPU. That makes a hosted, multi-user
128
+ deployment fundamentally different from a typical data-wrapping MCP server: every
129
+ request burns GPU compute that somebody has to pay for. Running locally keeps it
130
+ free and private, at the cost of single-machine availability — the right trade
131
+ for a personal creative tool. A hosted version would swap the ComfyUI backend for
132
+ a paid inference API behind rate limiting; the MCP layer above would be unchanged.
133
+
134
+ ## Part of a wider webcomic/animation toolkit
135
+
136
+ This server produces still backgrounds and depth-parallax clips — it doesn't make videos.
137
+ For turning finished panels (including this tool's parallax clips) into a vertical promo
138
+ short or MV, see the companion
139
+ **[Anime Production Skill](https://github.com/tobiasfong/anime-production-skill)** — a
140
+ portable agent skill (works with Claude Code, Codex, Antigravity, and other AGENTS.md-aware
141
+ harnesses) built on Remotion. More tools in the same ecosystem — including a novel/comic
142
+ translation and lettering server — are listed on
143
+ [tobiasfong.github.io](https://tobiasfong.github.io).
144
+
145
+ ---
146
+
147
+ # Setup Guide
148
+
149
+ > **Heads-up — this is not click-and-go.** You need an NVIDIA GPU, ~11 GB of
150
+ > model downloads, a Hugging Face account, and a ComfyUI install of v0.41 or
151
+ > later. It's aimed at users comfortable with a terminal. Budget an hour for
152
+ > first-time setup.
153
+
154
+ ## Hardware: will it run on *your* machine?
155
+
156
+ | Hardware | Support | Reality |
157
+ |----------|---------|---------|
158
+ | **NVIDIA RTX 30/40-series** (≥6 GB VRAM) | ✅ **Tested** | The INT8 build this server defaults to. Developed on an RTX 3060 **Laptop** (6 GB): ~15 s per plate, 30–110 s with a sketch or location. |
159
+ | **NVIDIA RTX 50-series** | ✅ Expected | The repo's NVFP4 build is made for Blackwell; set `WEBCOMIC_BG_KLEIN_MODEL` to it. Untested here. |
160
+ | **Apple Silicon / AMD / Intel** | ⚠️ Untested | Depends on ComfyUI's Klein support for your backend. The INT8 and NVFP4 builds use NVIDIA tensor-core formats; the repo's bf16 build is the one to try. |
161
+ | **CPU only / integrated graphics** | ❌ Impractical | |
162
+
163
+ ## Step 1 — Install ComfyUI v0.41 or later
164
+
165
+ Klein's nodes are core in **ComfyUI 0.41.0+** (or the 0.41.1 backport); older builds
166
+ show missing nodes. No custom node packs are needed.
167
+
168
+ - **NVIDIA (Windows):** download the [ComfyUI portable build](https://github.com/comfyanonymous/ComfyUI/releases) and extract it.
169
+ - **Already have an older ComfyUI with add-ons you rely on?** Install Klein's as a
170
+ **separate** portable build rather than upgrading in place. This project does
171
+ exactly that: Klein lives at `C:/AI/ComfyUI_flux3` on port **8189**, beside the main
172
+ install, and the server starts it on first use. Point `WEBCOMIC_BG_KLEIN_DIR` /
173
+ `WEBCOMIC_BG_KLEIN_URL` at yours.
174
+
175
+ ## Step 2 — Download the models
176
+
177
+ The repo is **gated**: open
178
+ [black-forest-labs/flux-3-image-klein-comfy](https://huggingface.co/black-forest-labs/flux-3-image-klein-comfy),
179
+ accept the license, then make a read token at
180
+ [huggingface.co/settings/tokens](https://huggingface.co/settings/tokens). Each BFL repo
181
+ needs its own click — accepting the main Klein repo does not cover this one. Then:
182
+
183
+ ```bash
184
+ python setup_models.py --comfy "C:/AI/ComfyUI_flux3/ComfyUI"
185
+ ```
186
+
187
+ with `HF_TOKEN` set in the environment. It skips files already present. Or place them
188
+ by hand under `ComfyUI/models/`:
189
+
190
+ | Role | Saved as | → Folder | In the repo |
191
+ |------|----------|----------|-------------|
192
+ | **Diffusion model** (step-distilled, INT8) | `flux3_image_klein_sd_int8_convrot.safetensors` | `diffusion_models/` | `diffusion_models/flux3-image-klein-int8-convrot.safetensors` |
193
+ | **Text encoder** | `qwen3vl_4b_int8_convrot.safetensors` | `text_encoders/` | same name |
194
+ | **VAE** | `flux2-vae.safetensors` | `vae/` | same name |
195
+
196
+ > Use the **distilled** model, not the `-base-` file beside it: base is for
197
+ > fine-tuning and wants far more steps. The 9B **prompt upsampler** in the same repo
198
+ > is deliberately not used — it rewrites your prompt before generation, and the
199
+ > prompting rules above only hold for the prompt you wrote.
200
+
201
+ > **License: FLUX Kommunity License v1.0.** Commercial use of generated *outputs*
202
+ > is permitted for users under US$5M gross annual revenue; above that, BFL's
203
+ > self-hosted license or API applies. Outputs may not be used to train models for
204
+ > commercial use. Read it on the repo page before relying on it.
205
+
206
+ ## Step 3 — Set up this MCP server
207
+
208
+ ### From PyPI (simplest)
209
+
210
+ ComfyUI and the Klein models (Steps 1-2) are still required: the package is only this server, and it cannot
211
+ install them for you. With those in place and [uv](https://docs.astral.sh/uv/) installed, there is nothing to
212
+ clone:
213
+
214
+ ```bash
215
+ claude mcp add -s user webcomic-background -- uvx webcomic-background-mcp
216
+ ```
217
+
218
+ Add `-e WEBCOMIC_BG_KLEIN_URL=...` or `-e WEBCOMIC_BG_KLEIN_DIR=...` before the `--` if your Klein ComfyUI is
219
+ not at the defaults in the table below. Or `pip install webcomic-background-mcp` and register the
220
+ `webcomic-background-mcp` command. Installed this way, the world bible (and each project's `style.txt`) goes to
221
+ `~/webcomic-background-mcp/world` and finished plates to `~/webcomic-background-mcp/output`; `WEBCOMIC_BG_WORLD`
222
+ and `WEBCOMIC_BG_OUTPUT` move them. `setup_models.py` (the model downloader) is a script for a clone.
223
+
224
+ ### From the repo
225
+
226
+ This server lives in the `webcomic-toolkit` monorepo — clone the whole repo, but you
227
+ only need to install this one server's dependencies:
228
+
229
+ ```bash
230
+ git clone https://github.com/tobiasfong/webcomic-toolkit.git
231
+ cd webcomic-toolkit/servers/webcomic-background-mcp
232
+ python -m venv .venv
233
+ .venv/Scripts/python -m pip install -r requirements.txt # (Linux/Mac: .venv/bin/python)
234
+ ```
235
+
236
+ ## Step 4 — Wire it into your MCP client
237
+
238
+ **The config location depends on your client** — this is the step that varies most:
239
+
240
+ - **Classic Claude Desktop:** add to `claude_desktop_config.json`:
241
+ ```json
242
+ {
243
+ "mcpServers": {
244
+ "webcomic-background-generator": {
245
+ "command": "C:/path/to/.venv/Scripts/python.exe",
246
+ "args": ["C:/path/to/server.py"]
247
+ }
248
+ }
249
+ }
250
+ ```
251
+ - **Claude Code:** `claude mcp add webcomic-background-generator -- /path/to/.venv/bin/python /path/to/server.py`
252
+ - **Newer "Cowork"-style desktop builds:** these manage MCP servers through an
253
+ **Extensions/Connectors UI** or per-project config rather than the classic key —
254
+ check your client's MCP/Extensions settings.
255
+
256
+ After adding it, **fully quit and relaunch the client** (see Troubleshooting —
257
+ just closing the window often isn't enough).
258
+
259
+ ## Step 5 — Use it
260
+
261
+ 1. Run `check_status` — it reports whether the Klein ComfyUI is up, and if not,
262
+ whether it is installed with all three model files. The first render starts it.
263
+ 2. Ask for a background, e.g. *"Ming dynasty Huizhou town lane in Anhui,
264
+ whitewashed walls, black tile roofs, a stone arch bridge over a canal, green
265
+ hills behind."* Then:
266
+ - **`sketch_path`** — a composition sketch from `tools/make_sketch.py` (a photo
267
+ or a drawing → white lines on black; hand-drawn sketches are detected and
268
+ binarized rather than edge-detected).
269
+ - **`location`** — a registered place, to stay on-model from a new angle.
270
+ - Approve a keeper → `register_location` it → later panels pass `location`.
271
+
272
+ ### Helper scripts (`tools/`)
273
+
274
+ - **`make_sketch.py`** — turn a reference photo or drawing into a composition
275
+ sketch (white lines on black) for `sketch_path`. Tune `--low/--high/--blur` for
276
+ line density.
277
+ - **`grade.py`** — color-grade a finished plate for mood (`--preset grimdark`,
278
+ `night`, `dusk`…). The same thing `grade_plate` does from the MCP side.
279
+ - **`letter_plaque.py`** — set real hanzi onto a blank board or scroll. The model
280
+ writes pseudo-characters, so ask for a plain board and letter it here: traditional
281
+ forms, right to left as Ming horizontal inscriptions read (`--ltr` for modern
282
+ order), `--vertical` for a hanging scroll, `--fill` to repaint a board that came
283
+ back with marks on it. Uses SimSun, so it needs a font with traditional glyphs.
284
+
285
+ To remove a stray figure or a fake sign, use `edit_background` with a `mask_box`
286
+ and phrase it as what to leave behind ("remove the person completely, leave only
287
+ the empty paved lane").
288
+
289
+ ### Your asset library (you provide this)
290
+
291
+ The repo ships the **code and the model downloader, but no reference images** — the
292
+ `references/` folder is git-ignored because such images are typically copyrighted
293
+ (game screenshots, manhwa panels) and shouldn't be redistributed. Curate your own:
294
+ drop environment photos / concept refs in `references/`, turn them into composition
295
+ sketches with `tools/make_sketch.py`, and pass them as `sketch_path`. The model
296
+ supplies the *style*; your library supplies the *structure*.
297
+
298
+ ---
299
+
300
+ ## Configuration (env vars)
301
+
302
+ | Variable | Default | Purpose |
303
+ |----------|---------|---------|
304
+ | `WEBCOMIC_BG_KLEIN_URL` | `http://127.0.0.1:8189` | The Klein ComfyUI's address |
305
+ | `WEBCOMIC_BG_KLEIN_DIR` | `C:\AI\ComfyUI_flux3` | Its portable install, for auto-launch |
306
+ | `WEBCOMIC_BG_AUTOLAUNCH` | `1` | Set `0` to require a manually started Klein ComfyUI |
307
+ | `WEBCOMIC_BG_KLEIN_LAUNCH_TIMEOUT` | `180` | Seconds to wait for it to come up |
308
+ | `WEBCOMIC_BG_KLEIN_MODEL` / `_TE` / `_VAE` | the INT8 files above | Swap in the FP8, NVFP4 or bf16 builds |
309
+ | `WEBCOMIC_BG_OUTPUT` | `./output` | Where finished PNGs are written |
310
+ | `WEBCOMIC_BG_WORLD` | `./world` | Where the world bible is stored |
311
+ | `WEBCOMIC_BG_PROJECT` | `default` | Default project (World Builder namespace) |
312
+
313
+ ## Troubleshooting
314
+
315
+ - **`check_status` says the Klein ComfyUI isn't installed or files are missing** —
316
+ see Steps 1–2. If it is installed but won't start, read `comfy_klein.log` in the
317
+ install folder; a crash there leaves no other trace.
318
+ - **Missing node errors (`EmptyFlux2LatentImage`, `ReferenceMultiLatent`…)** — that
319
+ ComfyUI is older than v0.41.
320
+ - **A download fails as "not a valid safetensors file"** — the license on that
321
+ exact repo isn't accepted, or `HF_TOKEN` is missing.
322
+ - **Two servers, one queue** — the character-panel server shares this ComfyUI. A
323
+ render waits behind the other server's job, and its timeout counts the wait.
324
+ - **Renders look murky / semi-realistic** — check the prompt for mood words
325
+ ("grimdark", "dim lighting", "deep shadow"). Remove them; darken with `grade_plate`.
326
+ - **A modern skyline or tower appears in the distance** — the prompt left the far
327
+ distance open. Name what fills it (forest, hills, a city wall).
328
+ - **Fake characters on signs and banners** — the model writes pseudo-text. Ask for
329
+ a plain board, then letter the real characters yourself.
330
+ - **The tool never appears in your MCP client** — the client reads its config at
331
+ startup, and "close window" on many desktop apps only minimizes to the system
332
+ tray (the process keeps running). **Fully quit** and relaunch.
333
+
334
+ ## Status
335
+
336
+ Working. Klein rendering with the house style, composition sketches and World
337
+ Builder locations as references, 3D city and prop geometry, region-exact editing,
338
+ and post-hoc mood grading — each verified end to end through the server's own tool
339
+ functions in the v3.0.0 port.
340
+ Built with [Claude Code](https://claude.com/claude-code).
@@ -0,0 +1,319 @@
1
+ # Webcomic Background Generator — MCP Server
2
+
3
+ <!-- mcp-name: io.github.tobiasfong/webcomic-background -->
4
+
5
+ A local [Model Context Protocol](https://modelcontextprotocol.io) server that generates
6
+ **background art for comic panels** — Ming-dynasty cities, gothic hive cities, medieval
7
+ dungeons, whatever your story needs — in a crisp inked manhwa style, wrapping
8
+ [FLUX 3 Image Klein](https://huggingface.co/black-forest-labs/flux-3-image-klein-comfy)
9
+ on a local ComfyUI.
10
+
11
+ It exists to solve one concrete problem in making an illustrated webcomic:
12
+ drawing detailed environment backgrounds is slow. This tool lets the artist
13
+ describe a place (and optionally lay out its composition), and get back a
14
+ finished plate to put characters onto — keeping the human in charge of
15
+ characters, story and composition while offloading the repetitive scenery work.
16
+
17
+ > **v3.0.0 — FLUX 3 Klein only. FLUX.1-dev has been removed.**
18
+ > The server now renders exclusively with Klein, the model the sibling
19
+ > character-panel server already uses, so plates and figures come from one
20
+ > model and look like one drawing. With FLUX.1 went its manhwa LoRA (FLUX.1
21
+ > LoRAs cannot load in Klein), ControlNet (composition sketches are now passed
22
+ > to Klein as a reference image) and Kontext (edits now redraw only the box you
23
+ > give). It is also **~15x faster** — about 15 s per plate on a 6 GB laptop card,
24
+ > where FLUX.1 took ~225 s. See CHANGELOG for the measurements.
25
+ > **You will need Klein**; `setup_models.py` fetches it. There is no fallback model.
26
+
27
+ ## What it does
28
+
29
+ The main tools:
30
+
31
+ - **`generate_background`** — a plate from a **prompt**, optionally with a
32
+ composition **sketch** (white lines on black: it fixes the camera and where
33
+ every object sits) and/or a registered **location** (the place's canonical
34
+ plate, so a new view stays recognizably the same place — from any angle, not
35
+ just the canon's own framing).
36
+ - **`generate_city_scene`** — a giant establishing panel from a procedural 3D
37
+ gothic city, rendered to a sketch and drawn by Klein. Same seed = same city.
38
+ - **`generate_prop_scene`** — rows of repeated objects (first prop: bicycles)
39
+ from real 3D meshes, so they don't fuse or crop the way invented rows do.
40
+ - **`edit_background`** — change one thing on an approved plate with a
41
+ plain-English instruction; with a `mask_box`, nothing outside the box changes.
42
+ - **`register_location` / `list_world`** — the World Builder bible: register the
43
+ plate you approved as a place's canon, then draw it again consistently.
44
+ - **`grade_plate`** — darken or color-grade a finished plate for mood (how you
45
+ get a night or grimdark panel — never by asking the prompt for it).
46
+ - **`extract_palette`**, **`check_status`**, city-plan tools.
47
+
48
+ > **Prompting — rules measured on FLUX.1 and kept for Klein** (the far-distance
49
+ > one has already recurred on Klein; the others are carried over as standing rules).
50
+ > 1. **Name what the place IS, as physical objects.** No mood, lighting or
51
+ > "cinematic" words; they drag the render toward semi-realistic murk. Darken
52
+ > afterwards with `grade_plate`.
53
+ > 2. **No negatives.** There is no negative-prompt parameter, on purpose: the
54
+ > model draws what a prompt names, including what it is told to avoid.
55
+ > 3. **Name what fills the far distance** — forest, hills, a rampart. Leave it
56
+ > open and the model fills it from photographs: modern skylines behind a
57
+ > Ming river port.
58
+ > 4. **Open with period and place** ("Ming dynasty … in Anhui"). It holds a
59
+ > setting's architecture where a generic "ancient East Asian" invites drift.
60
+ >
61
+ > The house style sentence is appended automatically — the same one the
62
+ > character server uses.
63
+
64
+ ### Generate a background around your character
65
+
66
+ Works with **your own hand-drawn characters**, not just generated ones:
67
+
68
+ 1. **Size the plate to your character.** Pass `match_canvas_to=<character.png>`
69
+ to `generate_background`. The plate comes back at your character's canvas
70
+ size, and the response reports the exact `height_px` / `feet_x` / `feet_y` to
71
+ composite with. (The character is not used to condition the render; it only
72
+ sets dimensions.)
73
+ 2. **Cut your character out**, if it isn't already transparent.
74
+ `character-panel-mcp`'s `tools/cutout.py` keys a figure off a flat backdrop,
75
+ including a scan or a drawing on white paper.
76
+ 3. **Composite**, with that server's `compose_panel` — it takes *any* RGBA PNG
77
+ and pastes it bottom-centered at a given feet position and height.
78
+
79
+ For a plate from `generate_city_scene`, use `anchor_x`/`anchor_z` instead of
80
+ step 1: it reports the on-screen character height and feet line for a spot in
81
+ the 3D city, with occlusion accounted for.
82
+
83
+ ## Architecture
84
+
85
+ ```
86
+ MCP client (Claude)
87
+ │ stdio
88
+ ▼
89
+ server.py ──► klein.py ──HTTP──► Klein ComfyUI (:8189) ──► GPU
90
+ (FastMCP tools) (graphs, (v0.41+, FLUX 3 Image Klein
91
+ plumbing) INT8 + Qwen3-VL encoder)
92
+ │
93
+ ├─► citygen.py / props.py 3D geometry → composition sketches (CPU)
94
+ ├─► world.py the World Builder bible (JSON + canon PNGs)
95
+ └─► tools/grade.py mood grading (CPU)
96
+ ```
97
+
98
+ Sketches and locations are both **reference images** to Klein, each introduced
99
+ by a lead sentence saying what it is for. The wording matters and is measured:
100
+ "render it as a finished scene" came back photoreal, and a sketch's black areas
101
+ were drawn as empty void until the lead said they are ground, walls and sky.
102
+ `klein.py` keeps the wording that passed.
103
+
104
+ ### Why it's a *local* server
105
+
106
+ Each call runs a diffusion model on a local GPU. That makes a hosted, multi-user
107
+ deployment fundamentally different from a typical data-wrapping MCP server: every
108
+ request burns GPU compute that somebody has to pay for. Running locally keeps it
109
+ free and private, at the cost of single-machine availability — the right trade
110
+ for a personal creative tool. A hosted version would swap the ComfyUI backend for
111
+ a paid inference API behind rate limiting; the MCP layer above would be unchanged.
112
+
113
+ ## Part of a wider webcomic/animation toolkit
114
+
115
+ This server produces still backgrounds and depth-parallax clips — it doesn't make videos.
116
+ For turning finished panels (including this tool's parallax clips) into a vertical promo
117
+ short or MV, see the companion
118
+ **[Anime Production Skill](https://github.com/tobiasfong/anime-production-skill)** — a
119
+ portable agent skill (works with Claude Code, Codex, Antigravity, and other AGENTS.md-aware
120
+ harnesses) built on Remotion. More tools in the same ecosystem — including a novel/comic
121
+ translation and lettering server — are listed on
122
+ [tobiasfong.github.io](https://tobiasfong.github.io).
123
+
124
+ ---
125
+
126
+ # Setup Guide
127
+
128
+ > **Heads-up — this is not click-and-go.** You need an NVIDIA GPU, ~11 GB of
129
+ > model downloads, a Hugging Face account, and a ComfyUI install of v0.41 or
130
+ > later. It's aimed at users comfortable with a terminal. Budget an hour for
131
+ > first-time setup.
132
+
133
+ ## Hardware: will it run on *your* machine?
134
+
135
+ | Hardware | Support | Reality |
136
+ |----------|---------|---------|
137
+ | **NVIDIA RTX 30/40-series** (≥6 GB VRAM) | ✅ **Tested** | The INT8 build this server defaults to. Developed on an RTX 3060 **Laptop** (6 GB): ~15 s per plate, 30–110 s with a sketch or location. |
138
+ | **NVIDIA RTX 50-series** | ✅ Expected | The repo's NVFP4 build is made for Blackwell; set `WEBCOMIC_BG_KLEIN_MODEL` to it. Untested here. |
139
+ | **Apple Silicon / AMD / Intel** | ⚠️ Untested | Depends on ComfyUI's Klein support for your backend. The INT8 and NVFP4 builds use NVIDIA tensor-core formats; the repo's bf16 build is the one to try. |
140
+ | **CPU only / integrated graphics** | ❌ Impractical | |
141
+
142
+ ## Step 1 — Install ComfyUI v0.41 or later
143
+
144
+ Klein's nodes are core in **ComfyUI 0.41.0+** (or the 0.41.1 backport); older builds
145
+ show missing nodes. No custom node packs are needed.
146
+
147
+ - **NVIDIA (Windows):** download the [ComfyUI portable build](https://github.com/comfyanonymous/ComfyUI/releases) and extract it.
148
+ - **Already have an older ComfyUI with add-ons you rely on?** Install Klein's as a
149
+ **separate** portable build rather than upgrading in place. This project does
150
+ exactly that: Klein lives at `C:/AI/ComfyUI_flux3` on port **8189**, beside the main
151
+ install, and the server starts it on first use. Point `WEBCOMIC_BG_KLEIN_DIR` /
152
+ `WEBCOMIC_BG_KLEIN_URL` at yours.
153
+
154
+ ## Step 2 — Download the models
155
+
156
+ The repo is **gated**: open
157
+ [black-forest-labs/flux-3-image-klein-comfy](https://huggingface.co/black-forest-labs/flux-3-image-klein-comfy),
158
+ accept the license, then make a read token at
159
+ [huggingface.co/settings/tokens](https://huggingface.co/settings/tokens). Each BFL repo
160
+ needs its own click — accepting the main Klein repo does not cover this one. Then:
161
+
162
+ ```bash
163
+ python setup_models.py --comfy "C:/AI/ComfyUI_flux3/ComfyUI"
164
+ ```
165
+
166
+ with `HF_TOKEN` set in the environment. It skips files already present. Or place them
167
+ by hand under `ComfyUI/models/`:
168
+
169
+ | Role | Saved as | → Folder | In the repo |
170
+ |------|----------|----------|-------------|
171
+ | **Diffusion model** (step-distilled, INT8) | `flux3_image_klein_sd_int8_convrot.safetensors` | `diffusion_models/` | `diffusion_models/flux3-image-klein-int8-convrot.safetensors` |
172
+ | **Text encoder** | `qwen3vl_4b_int8_convrot.safetensors` | `text_encoders/` | same name |
173
+ | **VAE** | `flux2-vae.safetensors` | `vae/` | same name |
174
+
175
+ > Use the **distilled** model, not the `-base-` file beside it: base is for
176
+ > fine-tuning and wants far more steps. The 9B **prompt upsampler** in the same repo
177
+ > is deliberately not used — it rewrites your prompt before generation, and the
178
+ > prompting rules above only hold for the prompt you wrote.
179
+
180
+ > **License: FLUX Kommunity License v1.0.** Commercial use of generated *outputs*
181
+ > is permitted for users under US$5M gross annual revenue; above that, BFL's
182
+ > self-hosted license or API applies. Outputs may not be used to train models for
183
+ > commercial use. Read it on the repo page before relying on it.
184
+
185
+ ## Step 3 — Set up this MCP server
186
+
187
+ ### From PyPI (simplest)
188
+
189
+ ComfyUI and the Klein models (Steps 1-2) are still required: the package is only this server, and it cannot
190
+ install them for you. With those in place and [uv](https://docs.astral.sh/uv/) installed, there is nothing to
191
+ clone:
192
+
193
+ ```bash
194
+ claude mcp add -s user webcomic-background -- uvx webcomic-background-mcp
195
+ ```
196
+
197
+ Add `-e WEBCOMIC_BG_KLEIN_URL=...` or `-e WEBCOMIC_BG_KLEIN_DIR=...` before the `--` if your Klein ComfyUI is
198
+ not at the defaults in the table below. Or `pip install webcomic-background-mcp` and register the
199
+ `webcomic-background-mcp` command. Installed this way, the world bible (and each project's `style.txt`) goes to
200
+ `~/webcomic-background-mcp/world` and finished plates to `~/webcomic-background-mcp/output`; `WEBCOMIC_BG_WORLD`
201
+ and `WEBCOMIC_BG_OUTPUT` move them. `setup_models.py` (the model downloader) is a script for a clone.
202
+
203
+ ### From the repo
204
+
205
+ This server lives in the `webcomic-toolkit` monorepo — clone the whole repo, but you
206
+ only need to install this one server's dependencies:
207
+
208
+ ```bash
209
+ git clone https://github.com/tobiasfong/webcomic-toolkit.git
210
+ cd webcomic-toolkit/servers/webcomic-background-mcp
211
+ python -m venv .venv
212
+ .venv/Scripts/python -m pip install -r requirements.txt # (Linux/Mac: .venv/bin/python)
213
+ ```
214
+
215
+ ## Step 4 — Wire it into your MCP client
216
+
217
+ **The config location depends on your client** — this is the step that varies most:
218
+
219
+ - **Classic Claude Desktop:** add to `claude_desktop_config.json`:
220
+ ```json
221
+ {
222
+ "mcpServers": {
223
+ "webcomic-background-generator": {
224
+ "command": "C:/path/to/.venv/Scripts/python.exe",
225
+ "args": ["C:/path/to/server.py"]
226
+ }
227
+ }
228
+ }
229
+ ```
230
+ - **Claude Code:** `claude mcp add webcomic-background-generator -- /path/to/.venv/bin/python /path/to/server.py`
231
+ - **Newer "Cowork"-style desktop builds:** these manage MCP servers through an
232
+ **Extensions/Connectors UI** or per-project config rather than the classic key —
233
+ check your client's MCP/Extensions settings.
234
+
235
+ After adding it, **fully quit and relaunch the client** (see Troubleshooting —
236
+ just closing the window often isn't enough).
237
+
238
+ ## Step 5 — Use it
239
+
240
+ 1. Run `check_status` — it reports whether the Klein ComfyUI is up, and if not,
241
+ whether it is installed with all three model files. The first render starts it.
242
+ 2. Ask for a background, e.g. *"Ming dynasty Huizhou town lane in Anhui,
243
+ whitewashed walls, black tile roofs, a stone arch bridge over a canal, green
244
+ hills behind."* Then:
245
+ - **`sketch_path`** — a composition sketch from `tools/make_sketch.py` (a photo
246
+ or a drawing → white lines on black; hand-drawn sketches are detected and
247
+ binarized rather than edge-detected).
248
+ - **`location`** — a registered place, to stay on-model from a new angle.
249
+ - Approve a keeper → `register_location` it → later panels pass `location`.
250
+
251
+ ### Helper scripts (`tools/`)
252
+
253
+ - **`make_sketch.py`** — turn a reference photo or drawing into a composition
254
+ sketch (white lines on black) for `sketch_path`. Tune `--low/--high/--blur` for
255
+ line density.
256
+ - **`grade.py`** — color-grade a finished plate for mood (`--preset grimdark`,
257
+ `night`, `dusk`…). The same thing `grade_plate` does from the MCP side.
258
+ - **`letter_plaque.py`** — set real hanzi onto a blank board or scroll. The model
259
+ writes pseudo-characters, so ask for a plain board and letter it here: traditional
260
+ forms, right to left as Ming horizontal inscriptions read (`--ltr` for modern
261
+ order), `--vertical` for a hanging scroll, `--fill` to repaint a board that came
262
+ back with marks on it. Uses SimSun, so it needs a font with traditional glyphs.
263
+
264
+ To remove a stray figure or a fake sign, use `edit_background` with a `mask_box`
265
+ and phrase it as what to leave behind ("remove the person completely, leave only
266
+ the empty paved lane").
267
+
268
+ ### Your asset library (you provide this)
269
+
270
+ The repo ships the **code and the model downloader, but no reference images** — the
271
+ `references/` folder is git-ignored because such images are typically copyrighted
272
+ (game screenshots, manhwa panels) and shouldn't be redistributed. Curate your own:
273
+ drop environment photos / concept refs in `references/`, turn them into composition
274
+ sketches with `tools/make_sketch.py`, and pass them as `sketch_path`. The model
275
+ supplies the *style*; your library supplies the *structure*.
276
+
277
+ ---
278
+
279
+ ## Configuration (env vars)
280
+
281
+ | Variable | Default | Purpose |
282
+ |----------|---------|---------|
283
+ | `WEBCOMIC_BG_KLEIN_URL` | `http://127.0.0.1:8189` | The Klein ComfyUI's address |
284
+ | `WEBCOMIC_BG_KLEIN_DIR` | `C:\AI\ComfyUI_flux3` | Its portable install, for auto-launch |
285
+ | `WEBCOMIC_BG_AUTOLAUNCH` | `1` | Set `0` to require a manually started Klein ComfyUI |
286
+ | `WEBCOMIC_BG_KLEIN_LAUNCH_TIMEOUT` | `180` | Seconds to wait for it to come up |
287
+ | `WEBCOMIC_BG_KLEIN_MODEL` / `_TE` / `_VAE` | the INT8 files above | Swap in the FP8, NVFP4 or bf16 builds |
288
+ | `WEBCOMIC_BG_OUTPUT` | `./output` | Where finished PNGs are written |
289
+ | `WEBCOMIC_BG_WORLD` | `./world` | Where the world bible is stored |
290
+ | `WEBCOMIC_BG_PROJECT` | `default` | Default project (World Builder namespace) |
291
+
292
+ ## Troubleshooting
293
+
294
+ - **`check_status` says the Klein ComfyUI isn't installed or files are missing** —
295
+ see Steps 1–2. If it is installed but won't start, read `comfy_klein.log` in the
296
+ install folder; a crash there leaves no other trace.
297
+ - **Missing node errors (`EmptyFlux2LatentImage`, `ReferenceMultiLatent`…)** — that
298
+ ComfyUI is older than v0.41.
299
+ - **A download fails as "not a valid safetensors file"** — the license on that
300
+ exact repo isn't accepted, or `HF_TOKEN` is missing.
301
+ - **Two servers, one queue** — the character-panel server shares this ComfyUI. A
302
+ render waits behind the other server's job, and its timeout counts the wait.
303
+ - **Renders look murky / semi-realistic** — check the prompt for mood words
304
+ ("grimdark", "dim lighting", "deep shadow"). Remove them; darken with `grade_plate`.
305
+ - **A modern skyline or tower appears in the distance** — the prompt left the far
306
+ distance open. Name what fills it (forest, hills, a city wall).
307
+ - **Fake characters on signs and banners** — the model writes pseudo-text. Ask for
308
+ a plain board, then letter the real characters yourself.
309
+ - **The tool never appears in your MCP client** — the client reads its config at
310
+ startup, and "close window" on many desktop apps only minimizes to the system
311
+ tray (the process keeps running). **Fully quit** and relaunch.
312
+
313
+ ## Status
314
+
315
+ Working. Klein rendering with the house style, composition sketches and World
316
+ Builder locations as references, 3D city and prop geometry, region-exact editing,
317
+ and post-hoc mood grading — each verified end to end through the server's own tool
318
+ functions in the v3.0.0 port.
319
+ Built with [Claude Code](https://claude.com/claude-code).
@@ -0,0 +1,6 @@
1
+ """webcomic-background-mcp: comic-panel backgrounds on a local ComfyUI, as an MCP server.
2
+
3
+ The modules in this folder import each other by plain name, so they run
4
+ unchanged from a clone (`python server.py`). Installed from PyPI they are the
5
+ webcomic_background_mcp package, and server.py puts this folder on sys.path itself.
6
+ """