cd /news/artificial-intelligence/teaching-claude-code-to-paint-a-stat… Β· home β€Ί topics β€Ί artificial-intelligence β€Ί article
[ARTICLE Β· art-69335] src=dev.to β†— pub= topic=artificial-intelligence verified=true sentiment=↑ positive

Teaching Claude Code to Paint: A Stateful Image-Editing Skill Built on Gemini's Interactions API and MCP

A developer built a stateful image-editing skill for Claude Code by wrapping Google's gemini-3.1-flash-lite-image model in a FastMCP server. The tool, called nb2lite-skill-claude, uses Gemini's Interactions API to allow iterative edits without re-prompting the entire scene. The developer said, 'You type "generate an image of a cyberpunk kitchen" into Claude Code, and it just... does it. Then you say "add a neon RAMEN sign" and it edits the same image without re-prompting the whole scene.'

read8 min views1 publishedJul 22, 2026

TL;DR:[nb2lite-skill-claude]wraps Google'sgemini-3.1-flash-lite-image

model in a tiny FastMCP server and packages it as a Claude Code skill. You type "generate an image of a cyberpunk kitchen" into Claude Code, and it just... does it. Then you say "add a neon RAMEN sign" and it editsthe same imagewithout re-prompting the whole scene. Oh, and the cover image of this article? Generated by the thing the article is about β€” dogfooding all the way down. More on that at the end.

Most image-generation workflows are stateless. You send a prompt, you get pixels back, and the model immediately forgets everything. Want to tweak the result? You re-describe the entire scene and pray the character, lighting, and composition survive the round trip. (Narrator: they don't.)

Google's Nano Banana 2 Lite β€” the friendly nickname for gemini-3.1-flash-lite-image

β€” takes a different approach. It's a high-efficiency image model with sub-2-second generations, solid text rendering in 25+ languages, and β€” the headline feature β€” support for the stateful Interactions API, which lets you iterate on an image across multiple turns while the model keeps the visual context server-side.

This repo glues that capability into Claude Code, so your coding agent can generate and iteratively refine images as a natural part of a session. It ships as two things in one repo:

nb2lite-agent

, a single-file FastMCP app in server.py

) exposing exactly four tools.nb2lite-image

) that teaches Claude The Interactions API is Gemini's stateful endpoint. The core loop looks like this:

client.interactions.create(...)

with a prompt and store=True

.interaction_id

previous_interaction_id

, and the model edits the So instead of this (stateless suffering):

"A watercolor fox in a forest at dawn, mist, soft light, wearing a red scarf, three birch trees on the left,

and now alsoholding a lantern"

...you write this:

"Add a lantern in its paw."

That's it. The stored context holds the rest.

A few practical details the server handles for you:

1:1

, 16:9

, 9:16

, 4:3

, 3:4

) and low

(default, fast drafts) or high

(complex rendering, accurate text layout, character composition). The generic API spec also lists minimal

and medium

, but the live API rejects them for this model with an HTTP 400 β€” the server saves you from discovering that the hard way.The Model Context Protocol is an open standard for connecting AI assistants to tools and data. Before it, giving a model access to some service meant writing a bespoke integration for each assistant β€” N assistants Γ— M services, everyone reinventing the same plumbing. MCP collapses that: a tool author writes one MCP server that exposes typed tools, and any MCP-capable client (Claude Code, Claude Desktop, and a growing list of others) can discover and call them with no per-client glue code.

An MCP server is usually a small local process that speaks JSON-RPC over stdio. The client launches it, asks "what tools do you have?", and from then on the model can call them like functions.

The nb2lite-agent

server exposes exactly four:

Tool What it does
generate_image
Text β†’ 1k image. Saves locally, returns the path + an interaction ID.
edit_image
Stateful edit: takes the previous interaction ID + a description of only the change.
edit_local_image
Uploads any local image file inline (base64) and applies an edit β€” your entry point for existing files.
get_help
Reports live config: API key status, active model, output directory, full tool reference.

Images land on disk as gen_<timestamp>_<uuid8>.jpg

(or edit_

/edit_local_

prefixed) β€” the UUID suffix keeps concurrent generations from clobbering each other. Errors come back as πŸ”΄ ...

text strings rather than protocol errors, so the agent can read and react to them.

If MCP is the hands (the tools Claude can physically call), a skill is the muscle memory β€” a markdown file (SKILL.md

) plus bundled resources that load into Claude's context and teach it the workflow: which tool to reach for, in what order, with which constraints.

For nb2lite-image

, the skill encodes things like:

get_help

first when diagnosing setup issues β€” if the API key is missing, nothing else will work.thinking_level: low

for drafts.The skill also bundles the MCP server itself (mcp/server.py

), its requirements, an installer script, and a vendored copy of the Interactions API developer guide β€” so it's self-contained: install the skill, and you have everything needed to also stand up the server.

You need three things: Python 3.10+, Claude Code, and a Gemini API key (free from Google AI Studio). Pick one of the paths below.

Inside Claude Code, type:

/plugin marketplace add xbill9/nb2lite-skill-claude
/plugin install nb2lite-image@nb2lite-skill-claude

This installs the skill and auto-registers the MCP server. The plugin manifest carries no API key (as it should!) β€” the server reads GEMINI_API_KEY

from your environment, so make sure it's exported before launching Claude Code.

git clone https://github.com/xbill9/nb2lite-skill-claude.git
cd nb2lite-skill-claude

./init.sh

/mcp        # should list nb2lite-agent

That's genuinely it. init.sh

is safe to rerun if anything looks off.

From a clone of the repo:

make init TARGET=/path/to/your/project ARGS='--output-dir ./images'

This copies the skill into <project>/.claude/skills/nb2lite-image/

and writes the nb2lite-agent

entry into that project's .mcp.json

. It reuses ~/gemini.key

if you've set one up. Restart Claude Code in the target project, approve the server, done.

The server is published as xbill9/nb2lite-agent:

claude mcp add nb2lite-agent --env GEMINI_API_KEY="$(cat ~/gemini.key)" -- \
  docker run --rm -i -e GEMINI_API_KEY -v "$PWD:$PWD" -w "$PWD" xbill9/nb2lite-agent

The -v "$PWD:$PWD" -w "$PWD"

mount matters: the server saves images to disk and reads local files for edit_local_image

, so the container must see your project at the same absolute path as the host.

/mcp

doesn't list the server β†’ restart Claude Code in the project directory.πŸ”΄ GEMINI_API_KEY is not set

β†’ run source set_env.sh

(or export the key) and restart.get_help

; it reports the live config.Once installed, you talk to it in plain English. A real flow looks like:

You: "Generate a cozy cabin in a snowy forest at dusk, 16:9."

Claude calls:

generate_image(
    prompt="A cozy log cabin in a snowy forest at dusk, warm light in the windows",
    aspect_ratio="16:9",
    thinking_level="low",
)

You: "Nice. Add smoke curling from the chimney."

edit_image(
    previous_interaction_id="v1_ChdpRU5...",
    edit_prompt="add gentle smoke curling from the chimney",
)

You: "Now make it night, with aurora in the sky."

Same tool, newest ID, and the cabin, trees, and chimney smoke all stay put β€” only the sky changes. No re-prompting, no continuity roulette.

And for images that didn't come from the model at all:

You: "Take ./whiteboard-sketch.png and render it as a clean 3D product mockup."

edit_local_image(
    image_path="./whiteboard-sketch.png",
    edit_prompt="render this hand-drawn sketch as a high-fidelity 3D product mockup",
    aspect_ratio="4:3",
)

It returns an interaction ID too β€” so follow-up refinements switch to edit_image

and go stateful from there.

If the term is new to you: "eating your own dog food" means using your own product for real work, not just demoing it. It's the difference between "this should work" and "I ship with this every day." If a tool is good enough for your users, it should be good enough for you β€” and if it isn't, you'll be the first to feel the pain and fix it.

This repo dogfoods itself at every layer:

nb2lite-image

skill and nb2lite-agent

server are already wired up, so every development session doubles as an integration test.make test

) drive the same four MCP tools an end user would, against the live API.

generate_image(
    prompt="A wide tech blog cover illustration: a friendly robot artist "
           "painting a glowing galaxy on an easel, while a chain of connected "
           "frames behind it shows the same picture evolving step by step "
           "(day sky, then sunset, then storm with lightning). Flat vector "
           "style, deep indigo background, neon cyan and orange accents. "
           "Title text 'NB2Lite + MCP', subtitle 'Stateful image editing "
           "as a Claude Code skill'. Crisp, accurate lettering.",
    aspect_ratio="16:9",
    thinking_level="high",
)

(That exact output is committed to the repo as devto-cover.jpg, receipts and all.)

Worth noticing:

thinking_level: "high"

buys you on text-heavy layouts.edit_image

with that interaction ID and say "make the orange accents magenta." That's the whole point.Dogfooding is the cheapest credibility there is: no cherry-picked gallery, no "results may vary" fine print β€” the tool's real output is literally the first thing you saw when you opened this article. If the skill had flubbed the lettering or mangled the layout, you'd be looking at the evidence right now. Instead, the article ships with its own proof baked into the header.

This is a third-party community project, not affiliated with or endorsed by Anthropic or Google. Bring your own Gemini API key β€” and remember generations are billable, so draft on low and save high for the money shot.

── more in #artificial-intelligence 4 stories Β· sorted by recency
── more on @google 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/teaching-claude-code…] indexed:0 read:8min 2026-07-22 Β· β€”