midjourney-mcp

midjourney-mcp

Enables Midjourney image generation via PiAPI with daily cost caps, audit logs, and SSRF-safe image URL inputs.

Category
访问服务器

README

midjourney-mcp

FastMCP server for Midjourney image generation via PiAPI, with a daily-USD cost cap, per-call audit log, and SSRF-safe image URL inputs.

Midjourney has no broadly available official API as of May 2026 (Enterprise application-only). This MCP wraps PiAPI's PAYG Midjourney surface — the most stable third-party wrapper at the time of build — behind one consistent tool surface that fits the same audit + safety patterns as the rest of the family (cloudflare-dns-mcp, godaddy-mcp, parse-mcp, etc.).

Why a peer MCP

Other Midjourney MCPs exist (AceDataCloud, z23cc, PiAPI's own TypeScript MCP). This one ships:

  1. Daily USD cap. A single env var (MIDJOURNEY_MCP_DAILY_USD_CAP) sets a hard ceiling on per-day image-gen spend. Cost-incurring tools refuse with a stable error_class="rate_cap" once the projected day total exceeds cap.
  2. Per-call 4-field audit log (execution_time_ms / io / token_usage / error_class) at ~/.claude/midjourney-mcp/audit.log.jsonl, with actual PiAPI credit consume rolled in on completion.
  3. SSRF-safe image URL inputs on describe + blend via mycelium-security sanitize_or_raise + assert_public_ip. Defense in depth — refuses private / link-local / cloud metadata service hosts before forwarding.
  4. sanitize_error() strip patterns on every error payload — X-API-Key, Bearer tokens, api_key / secret / password / token patterns get redacted before crossing into model context.
  5. admin.env auto-load. Secrets live at ~/.claude/midjourney-mcp/admin.env (chmod 600, gitignored), never inline in .mcp.json.

Install

cd ~/.claude/midjourney-mcp
python3 -m pip install --break-system-packages -r requirements.txt

Then drop the API key into admin.env:

printf 'PIAPI_API_KEY=your-piapi-key-here\n' > ~/.claude/midjourney-mcp/admin.env
chmod 600 ~/.claude/midjourney-mcp/admin.env

Sign up at https://piapi.ai/ if you need a key. PAYG starts at ~$0.01 per imagine task. Host-Your-Account ($8/seat/mo) is also supported — set the daily cap to 0 (MIDJOURNEY_MCP_DAILY_USD_CAP=0) to disable cost tracking in HYA mode.

Register in your project .mcp.json:

{
  "mcpServers": {
    "midjourney": {
      "command": "python3",
      "args": ["/Users/YOU/.claude/midjourney-mcp/server.py"],
      "env": {}
    }
  }
}

Then restart Claude Code.

Tools (11 total)

Read (no cost, no cap)

Tool What it does
healthcheck Verify the PiAPI key is set + return today's cap snapshot
account_info Today's USD cap + per-tool cost estimates + default process_mode
get_task(task_id) Single poll for task status + output URLs
wait_for_task(task_id, timeout_seconds, poll_interval_seconds) Block until terminal state
list_recent_tasks(limit) Scan the local audit log for recent task_ids

Cost-incurring (cap-gated)

Tool Estimated USD (fast mode) What it does
imagine(prompt, aspect_ratio, ...) $0.040 4-up grid from a text prompt
variation(origin_task_id, index, prompt, ...) $0.040 Regenerate variations off a grid (index 1-4 / high_variation / low_variation)
upscale(origin_task_id, index, ...) $0.010 Isolate + upscale one grid image (index 1-4 / light / beta / 2x / 4x / subtle / creative)
describe(image_url, ...) $0.005 4 prompts from an input image (image-to-prompt)
blend(image_urls, dimension, ...) $0.040 Merge 2-5 images into a new 4-up grid

Lifecycle

Tool What it does
cancel_task(task_id) Cancel a non-terminal task

Daily USD cap

Image generation is creative iteration. Draft+confirm on every call breaks the loop. Instead, every cost-incurring tool runs a cap check BEFORE the API call:

projected = spent_today_usd + estimated_call_usd
if projected > MIDJOURNEY_MCP_DAILY_USD_CAP:
    refuse with error_class="rate_cap"

Spent-today tracks the calendar day at a configurable UTC offset (default -5; override via MIDJOURNEY_MCP_TZ_OFFSET_HOURS=-8 for US Pacific Standard, 1 for Central European, etc.). Cap resets at midnight in that offset. Estimates drive the cap (conservative pre-flight); actual PiAPI credit consume is backfilled from meta.usage.consume on task completion and lands in the audit log.

Default cap: $5.00/day. Override via env: MIDJOURNEY_MCP_DAILY_USD_CAP=20.00. Set to 0 to disable (e.g. HYA mode with flat $8/mo billing).

Typical flow

# 1. Submit an imagine
imagine(prompt="a quiet kitchen at dawn, soft window light, film grain --ar 3:2", aspect_ratio="3:2")
# -> {"task_id": "tk_abc...", "status": "pending", ...}

# 2. Wait for it
wait_for_task(task_id="tk_abc...", timeout_seconds=180)
# -> {"status": "completed", "task": {"output": {"image_url": "...", "image_urls": [...]}}}

# 3. Upscale the best one (say grid position 2)
upscale(origin_task_id="tk_abc...", index="2")
# -> {"task_id": "tk_xyz...", ...}
wait_for_task(task_id="tk_xyz...")

# Or vary instead of upscale:
variation(origin_task_id="tk_abc...", index="3", prompt="<same prompt, tweak>")

Audit log

Every tool call writes one JSONL line at ~/.claude/midjourney-mcp/audit.log.jsonl:

{
  "ts": 1737842400,
  "tool": "imagine",
  "execution_time_ms": 1230,
  "io": {"input": {"prompt_chars": 47, "aspect_ratio": "3:2"}, "output": {"task_id": "tk_abc...", "status": "pending"}},
  "token_usage": {},
  "error_class": "none",
  "extra": {"task_id": "tk_abc...", "usd_estimate": 0.04}
}

Search by tool, date, error_class, task_id. Useful for cost attribution + bug triage. Override the path via MIDJOURNEY_MCP_AUDIT_LOG.

Process modes

PiAPI translates process_mode to Midjourney's plan-level modes:

  • relax — slowest, cheapest, no GPU minutes consumed on official MJ plans
  • fast — default, normal-quality GPU time
  • turbo — fastest, premium GPU time, ~2× cost

Override default via env: MIDJOURNEY_MCP_PROCESS_MODE=fast (default). Override per-call via the process_mode argument on any tool.

Aspect ratios

Pass aspect_ratio to imagine / variation. Common values:

  • 1:1 (square, default)
  • 3:2, 2:3 (classic photo)
  • 16:9, 9:16 (cinema / portrait phone)
  • 4:3, 3:4 (older monitor / portrait)
  • 21:9 (ultra-wide)

PiAPI also accepts Midjourney's --ar W:H flag in the prompt itself; either works, but aspect_ratio is cleaner.

Configuration reference

Env var Default Purpose
PIAPI_API_KEY (required) PiAPI API key. Auto-loaded from admin.env.
PIAPI_API_BASE https://api.piapi.ai/api/v1 Override for mocking / testing.
MIDJOURNEY_MCP_DAILY_USD_CAP 5.00 Daily USD spend cap. 0 disables.
MIDJOURNEY_MCP_PROCESS_MODE fast Default mode if not specified per-call.
MIDJOURNEY_MCP_AUDIT_LOG ~/.claude/midjourney-mcp/audit.log.jsonl Audit log path.
MIDJOURNEY_MCP_SPEND_FILE ~/.claude/midjourney-mcp/spend.json Daily spend tracker path.

Related MCPs

Same author, same install path (~/.claude/<name>-mcp), same safety patterns:

License

MIT.


Built by Adelaida Diaz-Roa. Full install or team version at diazroa.com.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选