# Building a Stateful AI Comic Studio Over Streamable HTTP MCP (for Claude Code, Cursor & Antigravity)

> Source: <https://dev.to/kajian_du_5c58aead7d2bc8e/building-a-stateful-ai-comic-studio-over-streamable-http-mcp-for-claude-code-cursor-antigravity-d8h>
> Published: 2026-11-24 04:31:33+00:00

**Recommendation:** Model multi-step image generation as explicit state transitions over MCP — lock character identity, pass previousTaskId between pages, and patch edits with a 2%–3% halo buffer instead of rerolling whole images.
More in the playbook "Designing agent systems": <https://wpnews.pro/playbooks/agent-architecture>

**TL;DR**: Calling stateless text-to-image APIs from an AI coding agent breaks down as soon as you need two consecutive comic pages with the same character and legible speech bubbles. This post walks through the **4-Stage Agent Comic State Machine** we shipped over Streamable HTTP MCP (`https://starveilai.com/api/mcp`), the **3-Zone Bounding-Box** geometry that fixes typos without full rerolls, and a real Cloudflare Workers OAuth 2.1 JWKS gotcha we hit during Glama certification.

AI coding agents (Claude Code, Antigravity, Cursor, Codex, OpenClaw) are great at multi-step tool loops, yet terrible at drawing sequential comics with raw image generators. The bottleneck isn't aesthetics — it's **missing state**:

Following the open [Model Context Protocol specification](https://modelcontextprotocol.io/specification) and [IETF RFC 9728](https://datatracker.ietf.org/doc/rfc9728/) OAuth 2.0 Protected Resource Metadata, StarVeil AI 2.0 splits comic generation into four explicit state transitions across **18 agent-callable MCP tools** (plus an embedded MCP App side-pane):

| Stage | MCP Tool(s) | What State It Locks | Cost | 
|---|---|---|---|
| **1. Persistent Identity Vault** | `create_character` ,`list_my_characters` | Canonical face, hair, proportions, and default silhouette ( `characterIds` ) | **0 cr** (upload photo) / 20 cr (AI ref sheet) | 
| **2. Chained Page Render** | `create_comic_page` ,`get_comic_page` | Previous page context ( `previousTaskId` ) so Page 2+ keeps outfits & ink on fresh layouts | **25 cr** per 3:4 page (1st page free on`trial_v1` ) | 
| **3. 3-Zone Region Patch** | `edit_comic_page` | Anchor Zone (locked) + 2%–3% Halo Buffer + Active Rewrite Zone ( `0..1` bbox) | **25 cr** per edit (1st edit free on`trial_v1` ) | 
| **4. Art-Preserving Localization** | `translate_comic` ,`get_translation_status` | Downstream 6-language derivatives ( `en` ,`zh-CN` ,`zh-TW` ,`ja` ,`ko` ,`es` ) from`sourceVersionId` | **10 cr** per page (~$0.06 on`$6` pack) | 

```
# Claude Code (OAuth 2.1 — one-click browser approval, no secrets in chat)
claude mcp add --transport http starveil https://starveilai.com/api/mcp

# Antigravity / Cursor / Codex / CLI (installs plugin, starveil-cli, and SKILL.md)
curl -fsSL https://starveilai.com/install.sh | bash
```

For headless automation (`OpenClaw`, `n8n`, GitHub Actions, cron jobs), generate a revocable `sv_live_` Personal API Key at `https://starveilai.com/app/agents` and send `Authorization: Bearer sv_live_...` to the exact same endpoint.

```
{
  "tool": "create_character",
  "arguments": {
    "name": "Mochi the Tabby",
    "description": "Warm orange tabby kitten wearing an indigo developer hoodie",
    "referenceImageUrl": "https://example.com/mochi-photo.jpg"
  }
}
```

`previousTaskId`

```
{
  "tool": "create_comic_page",
  "arguments": {
    "title": "The Yarn Ball Incident - Page 2",
    "characterIds": ["chr_mochi_01"],
    "previousTaskId": "task_page1_id",
    "artStyle": "warm watercolor healing storybook comic",
    "language": "en",
    "prompt": "Direct continuation after Page 1. Panel 1: Sleepy engineer enters with coffee staring at the red yarn web. Panel 2: Mochi peeks out: \"Good news: zero merge conflicts.\" Panel 3: Warm sunrise wide shot as the engineer laughs."
  }
}
```

Informed by masked diffusion inpainting ([RePaint, arXiv:2201.09865](https://arxiv.org/abs/2201.09865)), mask geometry matters as much as the prompt. Leave a **2%–3% halo buffer** outside the black balloon stroke so old letters don't leave artifacts while everything outside the box stays anchored:

```
{
  "tool": "edit_comic_page",
  "arguments": {
    "taskId": "task_noir_page1",
    "instruction": "Text-only edit inside the boxed white speech bubble: replace text with exact words \"He left at midnight.\" Keep face, rain lighting, and surrounding panels unchanged.",
    "region": { "x": 0.54, "y": 0.06, "width": 0.40, "height": 0.16 }
  }
}
```

When we submitted StarVeil MCP to [Glama's connector directory](https://glama.ai/mcp/connectors/com.starveilai/star-veil-ai), OAuth authorization succeeded in the browser, yet hourly `tools/list` health checks returned `HTTP 500`.

The culprit: Better Auth's `mcpHandler({ jwksUrl })` fetches `https://starveilai.com/api/auth/jwks` over HTTP during token verification — which on Cloudflare Workers triggers a **same-zone self-fetch** back to the same Worker route and fails under edge proxy rules.

The fix was replacing the remote JWKS HTTP fetch with an **in-process local JWKS lookup directly against Cloudflare D1** (`jose.createLocalJWKSet` + `jwtVerify` with exact `issuer`/` audience` verification). Latency dropped, the HTTP 500 disappeared permanently, and Glama's hourly introspection now reports **Healthy** with **OAuth: Works in Glama**.

`latestDownloadUrl` (or open `open_starveil_studio`) before chaining Page 2+.
New verified accounts receive **1 free full-color 3:4 page + 1 free box-edit + 0-credit photo OC uploads** (`trial_v1`). Never-expiring credit packs start at **$6 Mini (1,000 credits, ~40 pages)** and immediately unlock 100% watermark-free commercial PNG downloads across Web, MCP, CLI, and API.

`com.starveilai/star-veil-ai@2.0.0`)
