Skip to main content
Glama

pivision โ€” MCP Vision & Image Generation Server

One service, two ways to use it: an MCP server for AI assistants (CodeBuddy / Claude Desktop / any MCP client), and a FastAPI HTTP API (port 7002) for your own programs, scripts, and browser.

pivision is a plug-and-play "see images + draw images" toolbox. It recognizes what's inside a local image or video link, and generates images from a text description โ€” with no coding required to use it.

๐Ÿ’ก Free to use โ€” both the vision and image-generation APIs backed into pivision are currently free, with generous quotas that are enough for personal use and large projects. You only need to register and get your own API keys (see Getting API Keys).

Think of r-pic / r-vid as giving your LLM "eyes" โ€” your AI assistant can finally see the images and videos you hand it, describe them, and answer questions about them.

  • Vision (see): describe a local picture, parse a video URL โ€” the model's "eyes"

  • Generation (draw): text-to-image, infographic-to-image, image-to-image (reference + instruction)

  • Batch: run hundreds of tasks from a simple text file with resume support


โœจ Features

6 MCP tools

r-pic ยท r-vid ยท g-pic ยท i-pic ยท p-pic ยท b-gen โ€” one tool per pipeline, fully decoupled config

Dual interface

MCP (stdio) for AI clients + FastAPI HTTP server (8 endpoints, port 7002) for any program

Adapter architecture

Two-layer adapters (vendor-specific + OpenAI-compatible generic). Add a new model = fill in .env, zero code changes

5 isolated pipelines

VISION_ / VISION_VIDEO_ / GEN_IMAGE_ / GEN_INFOGRAPH_ / EDIT_IMAGE_ env prefixes, each with an ENABLED switch

Multi-key pool

Generation keys support comma-separated pools; auto-rotate on 401/403/429

Named instances

Multiple config instances per pipeline, selectable at call time via instance=

Smart fallback

Video config auto-falls-back to image config; named instances fall back to main instance field-by-field

Batch engine

b-gen runs tasks line-by-line with resume (skip completed rows after interruption)

Secure by design

Zero hardcoded keys, _safe_error() redaction, config preflight that never prints real keys


Related MCP server: Gemini Image MCP

๐Ÿ— Architecture

                 pivision.py (entry, FastMCP "pivision")
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  r-pic   r-vid   g-pic/i-pic   p-pic      b-gen
   โ”‚        โ”‚        โ”‚           โ”‚          โ”‚
   โ–ผ        โ–ผ        โ–ผ           โ–ผ          โ–ผ
get_vision_adapter      get_pipeline_adapter(pipeline, provider, instance)
(prefix VISION_ /      (prefix GEN_IMAGE_ / GEN_INFOGRAPH_ / EDIT_IMAGE_,
 VISION_VIDEO_ fallback)   main instance + named instances)
   โ”‚        โ”‚        โ”‚           โ”‚
   โ–ผ        โ–ผ        โ–ผ           โ–ผ
 /v1/chat/completions   /v1/images/generations (url) ยท /v1/images/edits (JSON+base64)
 (image / video_url)   ยท openai_compat multipart (image-to-image)

                 api_server.py (FastAPI, :7002 โ€” same business layer)
   /health ยท /tools ยท /r-pic ยท /r-vid ยท /g-pic ยท /i-pic ยท /p-pic ยท /b-gen

   utils.py (save/naming/size/base64/batch/history)
   adapters/__init__.py (adapter registry + factory + get_config_summary())
   On disk: art/*.png ยท pivision_batch_results.txt ยท .bgen_progress.json ยท history.json

Core design:

  • Pipeline prefix isolation โ€” the three generation pipelines read independent env vars (GEN_IMAGE_* / GEN_INFOGRAPH_* / EDIT_IMAGE_*); switch backend per pipeline without touching code.

  • Vision dual-branch fallback โ€” r-vid reuses VISION_* when VISION_VIDEO_* is not configured: one key set, two use cases.

  • Enable switches โ€” each pipeline has {PREFIX}_ENABLED (default true; set to false to fully disable it, no API calls are made).

  • Named instances โ€” declare multiple config instances per generation pipeline ({PREFIX}_INSTANCES), select at runtime with the instance tool parameter.

  • Multi-key pool โ€” comma-separated keys in *_API_KEYS; automatic key rotation on 401/403/429.


๐Ÿš€ Quick Start

Prerequisite: Python โ‰ฅ 3.11.

1. Install

cd pivision            # wherever you cloned/unpacked the project
python -m venv .venv
.venv/bin/pip install -e .

2. Configure .env

cp .env.example .env

Fill in your keys: vision โ†’ VISION_API_KEY (video falls back to it automatically when empty); generation โ†’ each section's *_API_KEYS (comma-separated for multiple keys). Pipelines without keys return โŒ ๆœช้…็ฝฎ {xxx_API_KEYS} instead of making wrong requests.

2.5 Get API Keys (free)

Both backed APIs are currently free with generous quotas โ€” you only register once and grab your keys:

Pipeline

Provider

Where to register

Key to fill in .env

Vision (r-pic / r-vid)

dots (Xiaohongshu Dots Studio)

https://dots.ai/platform โ€” sign in with phone number, then create a key on the API Keys page

VISION_API_KEY

Generation (g-pic / i-pic / p-pic)

SenseNova (SenseTime)

https://platform.sensenova.cn โ€” register + phone verify, then Console โ†’ API Keys โ†’ create an sk- key

GEN_IMAGE_API_KEYS / GEN_INFOGRAPH_API_KEYS / EDIT_IMAGE_API_KEYS

Both providers are OpenAI-compatible. If you already have another OpenAI-compatible key (OpenAI / DeepSeek / Moonshot / local gatewayโ€ฆ), point VISION_BASE_URL / *_BASE_URL to your own endpoint and reuse your existing key โ€” no extra registration needed.

3a. Use as MCP (for AI assistants)

Register the server in your MCP client (e.g. CodeBuddy โ†’ Settings โ†’ MCP Servers). The pic-config.json / mcp-register.json in the project are ready-to-merge templates:

{
  "mcpServers": {
    "pivision": {
      "command": "<your-project-path>/.venv/bin/python",
      "args": ["<your-project-path>/pivision.py"]
    }
  }
}

Replace <your-project-path> with the actual path on the target machine. The Python code itself uses relative paths โ€” only the registration JSON needs per-machine paths.

Start / verify:

cd pivision
.venv/bin/python pivision.py

The service waits silently for the AI client to connect. Once registered, just chat with your assistant โ€” it will call the tools for you.

3b. Use as HTTP API (for programs & scripts)

cd pivision
.venv/bin/python api_server.py

Expected output:

INFO:     Uvicorn running on http://127.0.0.1:7002
INFO:     pivision API ๆœๅŠกๅ™จๅฐฑ็ปช๏ผˆHTTP ็ซฏๅฃ 7002๏ผ‰

The server listens on 127.0.0.1:7002 (local machine only). Run it in the background if you want it to survive closing the terminal:

nohup python api_server.py > pivision_server.log 2>&1 &
# check:  curl http://127.0.0.1:7002/health
# stop:   pkill -f api_server.py

๐Ÿ›  MCP Tools

Every tool returns a string: success starts with โœ…, failure with โŒ (with reason) โ€” MCP clients can judge by prefix.

r-pic โ€” Image recognition

r-pic(image_path, question="่ฏท่ฏฆ็ป†ๆ่ฟฐ่ฟ™ๅผ ๅ›พ็‰‡็š„ๅ†…ๅฎนใ€‚", provider=None, model=None, max_tokens=1024)
  • image_path: local image (PNG/JPG/WEBP/GIF), required

  • question: what you want to know about the image

  • max_tokens: response length cap, default 1024

r-vid โ€” Video recognition

r-vid(video_url, question="่ฏท่ฏฆ็ป†ๆ่ฟฐ่ฟ™ๆฎต่ง†้ข‘็š„ๅ†…ๅฎนใ€‚", provider=None, model=None, max_tokens=8192)
  • video_url: must be a publicly accessible http/https link (local paths / LAN addresses won't work)

  • max_tokens: default 8192 โ€” video parsing output is long, keep it high

g-pic / i-pic โ€” Text-to-image

g-pic(prompt, size="2752x1536", n=1, provider=None, instance=None)
i-pic(prompt, size="2752x1536", n=1, provider=None, instance=None)
  • g-pic: general text-to-image (GEN_IMAGE pipeline)

  • i-pic: infographics / posters / charts (GEN_INFOGRAPH pipeline, default sensenova-u1-fast)

  • n: 1โ€“20; n>1 is generated one-by-one (the official API supports one per call)

  • instance: named instance, e.g. "a"; unknown instance โ†’ explicit error (no silent fallback)

p-pic โ€” Image-to-image (reference + instruction)

p-pic(prompt, image_path, size="2752x1536", provider=None, instance=None)
  • image_path: reference image path (local), required โ€” sent as data:image/*;base64, Data-URI

  • Only n=1 is allowed

b-gen โ€” Batch engine

b-gen(task, file_path, interval=0, resume=False, size="2752x1536", n=1)
  • task: g-pic / i-pic / p-pic / r-pic / r-vid

  • Reads tasks line-by-line from a .txt / .md file (see format below)

  • resume=True: progress saved to .bgen_progress.json; re-run skips completed rows. Progress auto-invalidates if the task type or input file changes.

  • interval: seconds between tasks (set 1โ€“2 to avoid rate limits)

  • Results are written to pivision_batch_results.txt

Task file format (one task per line):

task

Line format

Example line

g-pic / i-pic

1 prompt

ไธ€ๅช็Œซๅ’ชๅ’–ๅ•กๅŽ…ๆ’ๅ›พ

r-pic

1 image path

/data/photo.png

r-vid

1 video URL

https://example.com/clip.mp4

p-pic

prompt | reference path

ๆŠŠ่ƒŒๆ™ฏๆ”นๆˆ้›ชๅฑฑ | /data/sketch.png


๐ŸŒ HTTP API (FastAPI, port 7002)

Same business layer as MCP โ€” no duplicated logic. All endpoints return a unified response structure:

{"code": 0, "msg": "ok", "data": "..."}

code

Meaning

How to judge

0

success

msg is "ok", real result in data

1

business failure (missing key, file not found)

read msg

2

internal exception (bug)

read msg

8 endpoints:

Method

Endpoint

Purpose

Required fields

GET

/health

health check

โ€”

GET

/tools

list available tools

โ€”

POST

/r-pic

image recognition

image_path; optional question, max_tokens

POST

/r-vid

video recognition

video_url; optional question, max_tokens

POST

/g-pic

text-to-image

prompt; optional size, n, instance

POST

/i-pic

infographic generation

prompt; optional size, n, instance

POST

/p-pic

image-to-image

prompt, image_path; optional size, instance

POST

/b-gen

batch engine

task, file_path; optional interval, resume, size, n

Quick test:

curl http://127.0.0.1:7002/health
curl -X POST http://127.0.0.1:7002/g-pic -H "Content-Type: application/json" \
  -d '{"prompt": "a cat by a coffee shop window, illustration style"}'

โš™๏ธ Environment Variables Reference

5 sections โ€” all new v6 variables (code defaults shown in parentheses; env vars override).

VISION_ โ€” r-pic image recognition

Variable

Meaning

Default

VISION_ENABLED

enable switch: true/false (empty = on)

true

VISION_PROVIDER

vision backend: openai / dots

dots

VISION_MODEL

vision model

dots3-note-prev

VISION_BASE_URL

OpenAI-compatible base URL

https://note3-prev-api.askdiandian.com/v1

VISION_API_KEY

vision API key

empty

VISION_VIDEO_ โ€” r-vid video recognition (all empty โ†’ falls back to VISION_*)

Variable

Meaning

Default

VISION_VIDEO_ENABLED

video switch; empty falls back to VISION_ENABLED; explicit false = video line disabled

true

VISION_VIDEO_PROVIDER / _MODEL / _BASE_URL / _API_KEY

video backend; empty โ†’ fall back to VISION_*

same as vision

GEN_IMAGE_ โ€” g-pic text-to-image

Variable

Meaning

Default

GEN_IMAGE_ENABLED

enable switch

true

GEN_IMAGE_ADAPTER

sensenova / openai_compat

sensenova

GEN_IMAGE_MODEL

text-to-image model (main instance)

sensenova-u1.5-lite

GEN_IMAGE_BASE_URL

OpenAI-compatible base URL (main instance)

https://token.sensenova.cn/v1

GEN_IMAGE_API_KEYS

comma-separated key pool (main instance)

empty

GEN_IMAGE_INSTANCES

named instance list, e.g. a,b; empty = main only

empty

GEN_INFOGRAPH_ โ€” i-pic infographics

Same shape as GEN_IMAGE_*; default model sensenova-u1-fast.

EDIT_IMAGE_ โ€” p-pic image-to-image

Same shape as GEN_IMAGE_*; default model sensenova-u1.5-lite (decoupled from text-to-image).

openai_compat optional extras: {PREFIX}_RESPONSE_FORMAT (url/b64_json, default url), {PREFIX}_EDIT_URL (image-edit endpoint override, default ${BASE_URL}/images/edits).

Fallback chain (priority order)

named-instance vars ({PREFIX}_{X}_FIELD) โ†’ main-instance vars ({PREFIX}_FIELD) โ†’ code defaults

Only two fallback types exist, no legacy-variable fallback:

  1. Video โ†’ image: VISION_VIDEO_* all empty โ†’ VISION_* (switch follows the same chain).

  2. Named instance โ†’ main instance: instance field empty โ†’ main instance field (no _ADAPTER per instance; {PREFIX}_ADAPTER is pipeline-level).


๐Ÿ”Œ Adapter Mechanism

Two-layer: common differences are absorbed by generic adapters, special differences by vendor-specific adapters. The tools only see capability interfaces.

Adapter

Type

Purpose

Special differences handled

openai_compat

generation ยท generic

OpenAI-compatible protocol (/images/generations, multipart edits)

none โ€” differences handled by config (change MODEL/BASE_URL = switch vendor)

sensenova

generation ยท vendor

SenseNova image generation

multi-key pool, watermark/prompt_extend, image-edit JSON + base64 Data-URI

openai

vision ยท generic

OpenAI-compatible vision

none (Bearer auth, detail=auto)

dots

vision ยท vendor

dots vision

api-key header auth, detail=medium, enable_thinking=false, video stream=false

Add a new OpenAI-compatible model โ€” zero code:

GEN_IMAGE_ADAPTER=openai_compat
GEN_IMAGE_MODEL=foo-image-x1
GEN_IMAGE_BASE_URL=https://foo.example.com/v1
GEN_IMAGE_API_KEYS=sk-foo-xxxx

Tools work immediately. Only write a custom adapter when the API is not OpenAI-compatible (private protocols, two-stage polling, special auth headers, JSON+base64 edits, multi-key pools, non-configurable differences) โ€” register it in adapters/__init__.py in one line, pipeline code untouched.

Multi-key pool constraints: keys in one *_API_KEYS must be same vendor + same BASE_URL + same MODEL (they rotate for one endpoint). Don't mix vendors/URLs/models in one pool (โ†’ 400/404, no key rotation, cascading errors). Use different config sections or named instances for multiple endpoints.


๐Ÿ” Config Preflight

adapters.get_config_summary() returns the readiness of all 5 pipelines (+ named instances) โ€” N of M available โ€” so agents/clients can check before calling. It only reports "configured / not configured", never prints actual keys.

import json
from adapters import get_config_summary

for r in get_config_summary():
    print(f"{r['tool']:6s} {r['prefix']:16s} instance={str(r['instance'] or '(main)'):6s} "
          f"adapter={r['adapter']:12s} model={r['model']:20s} keys={r['api_keys']:3s} โ†’ {r['status']}")

Example output (fully configured case):

g-pic  GEN_IMAGE        ๅฎžไพ‹=(ไธป)   adapter=sensenova    model=sensenova-u1.5-lite keys=ๅทฒ้…็ฝฎ โ†’ AVAILABLE
i-pic  GEN_INFOGRAPH    ๅฎžไพ‹=(ไธป)   adapter=sensenova    model=sensenova-u1-fast   keys=ๅทฒ้…็ฝฎ โ†’ AVAILABLE
p-pic  EDIT_IMAGE       ๅฎžไพ‹=(ไธป)   adapter=sensenova    model=sensenova-u1.5-lite keys=ๅทฒ้…็ฝฎ โ†’ AVAILABLE
r-pic  VISION           ๅฎžไพ‹=(ไธป)   adapter=dots         model=dots3-note-prev     keys=ๅทฒ้…็ฝฎ โ†’ AVAILABLE
r-vid  VISION_VIDEO     ๅฎžไพ‹=(ไธป)   adapter=dots         model=dots3-note-prev     keys=ๅทฒ้…็ฝฎ โ†’ AVAILABLE

ๆฑ‡ๆ€ป๏ผš5 of 5 available

๐Ÿ”’ Security

  • Keys live only in .env (excluded by .gitignore, never committed) โ€” zero hardcoded keys in code.

  • All adapters redact key fragments in errors and logs via _safe_error() โ†’ [redacted].

  • get_config_summary() prints only "configured / not configured" โ€” never the keys themselves.

  • Never put full keys in frontend code, logs, or public repos.

  • HTTP server binds to 127.0.0.1 by default โ€” local machine only, not exposed to LAN/Internet unless you change host.


๐Ÿ“ Notes & FAQ

Q1: Generated image URLs expire? u1.5-lite URLs expire in 24h, u1-fast in 1h (per official docs). pivision downloads every generated image to local art/ automatically โ€” always use the local file path, ignore the temp URL.

Q2: Video recognition fails / can't parse? The video URL must be a publicly reachable http/https link โ€” LAN addresses, localhost, and local file paths won't work. Parsing can be slow, that's normal; if it times out, use a shorter/smaller video. Default timeout is 180s (TIMEOUT_SECONDS in adapters/vision_base.py).

Q3: "Not configured {xxx}_API_KEYS"? That pipeline has no key. Fill *_API_KEYS in .env, then restart the service.

Q4: "Pipeline disabled ({PREFIX}_ENABLED=false)"? The switch is off. Set {PREFIX}_ENABLED to true (or delete the line โ€” empty counts as on), then restart.

Q5: Key rotation still hits 400/404? Almost certainly a mixed pool โ€” keys pointing to different models/endpoints in one pool. Split by endpoint using different config sections or named instances.

Q6: Env vars changed but no effect? .env is loaded once at startup. Restart the service. Note named-instance vars are case-sensitive (GEN_IMAGE_A_MODEL โ€” instance suffix uppercase).

Q7: Size errors or wrong orientation? Generation auto-matches the nearest aspect ratio + LANCZOS downscale for unsupported sizes (output notes โšก ่‡ชๅŠจ็ผฉๆ”พ). If still failing, make sure size is WxH format (e.g. 1024x1024).

Limits: single image โ‰ค 20MB for r-pic; video timeout 180s (adjustable constant); b-gen per-line failure doesn't stop the batch.


๐Ÿ“ฆ Project Layout

pivision/
โ”œโ”€โ”€ pivision.py           # MCP entry (FastMCP "pivision")
โ”œโ”€โ”€ api_server.py         # FastAPI HTTP server (:7002)
โ”œโ”€โ”€ utils.py              # save/naming/size/base64/batch/history
โ”œโ”€โ”€ adapters/             # adapter registry + factory
โ”‚   โ”œโ”€โ”€ __init__.py       #   registry + get_config_summary()
โ”‚   โ”œโ”€โ”€ vision_base.py    #   vision base (timeout, max image size)
โ”‚   โ”œโ”€โ”€ vision_openai.py  #   vision ยท generic OpenAI-compatible
โ”‚   โ”œโ”€โ”€ vision_dots.py    #   vision ยท dots vendor
โ”‚   โ”œโ”€โ”€ openai_compat.py  #   generation ยท generic OpenAI-compatible
โ”‚   โ””โ”€โ”€ sensenova.py      #   generation ยท SenseNova vendor
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ .env.example          # config template (fill your keys โ†’ .env)
โ”œโ”€โ”€ pic-config.json       # MCP registration template (generic)
โ”œโ”€โ”€ mcp-register.json     # MCP registration template (CodeBuddy tagged)
โ””โ”€โ”€ README-zh.md          # ไธญๆ–‡็‰ˆ่ฏดๆ˜Ž

๐Ÿ“„ License

To be determined by the project owner โ€” see repository listing. (Internal / local deployment tool; not published to npm/PyPI.)

A
license - permissive license
A
quality
C
maintenance

Maintenance

โ€“Maintainers
โ€“Response time
โ€“Release cycle
โ€“Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

  • OCR, transcription, file extraction, and image generation for AI agents via MCP.

  • Generate images with any major model โ€” one API key, one prepaid balance, one MCP.

  • Generate on-brand images from your AI agent: design, edit, and render templates over MCP.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bliubliuing/pivision'

If you have feedback or need assistance with the MCP directory API, please join our Discord server