mcp-media-toolkit

mcp-media-toolkit

Generates AI images using Google Gemini and uploads them to S3-compatible storage via a single MCP tool call.

Category
访问服务器

README

mcp-media-toolkit

npm version downloads CI License: MIT

Generate AI images with Google Gemini (Nano Banana) and upload them to any S3-compatible storage — in a single MCP tool call.

A batteries-included MCP (Model Context Protocol) server that works in any MCP client (Claude Code, Cursor, Codex, Cline, Continue, Windsurf, …) and doubles as a Claude Code plugin with guided skills and automatic prompt optimization.

Features

  • Image generation — full Nano Banana family: gemini-2.5-flash-image (fast, 1K), gemini-3.1-flash-image-preview (Nano Banana 2, 2K), and gemini-3-pro-image-preview (Nano Banana Pro, 4K).
  • S3-compatible upload — works with Cloudflare R2, AWS S3, MinIO, DigitalOcean Spaces, and any other S3-protocol service.
  • One-shot workflow — a dedicated generate_and_upload tool goes from prompt to public URL in a single call.
  • Automatic prompt optimization — the Claude Code skills rewrite casual descriptions into rich, detailed prompts so short requests still produce great images.
  • Partial-failure recovery — if generation succeeds but upload fails, the local file is preserved and reported.
  • Clear error messages — configuration and runtime errors are designed to be acted on without reading source code.
  • Dual distribution — use it as an npm package via npx in any MCP client, or install it as a Claude Code plugin for the extra skills.

Quick Start

# 1. Set environment variables (see Configuration below)
export GEMINI_API_KEY="your-key"
export S3_ENDPOINT="https://..."
export S3_ACCESS_KEY_ID="..."
export S3_SECRET_ACCESS_KEY="..."
export S3_BUCKET="media"
export S3_PUBLIC_URL="https://media.example.com"

# 2. Add to your MCP client config (Claude Code, Cursor, etc.)
#    See Installation section for exact snippets.

# 3. Ask your agent to generate an image — you get back a public URL.

Installation

As an MCP server (any MCP client)

Add to your MCP client configuration. The server is distributed as an npm package, so npx handles installation on the fly.

Claude Code — add to ~/.claude/.mcp.json:

{
  "mcpServers": {
    "mcp-media-toolkit": {
      "command": "npx",
      "args": ["-y", "mcp-media-toolkit"],
      "env": {
        "GEMINI_API_KEY": "your-gemini-key",
        "S3_ENDPOINT": "https://<account>.r2.cloudflarestorage.com",
        "S3_ACCESS_KEY_ID": "your-access-key",
        "S3_SECRET_ACCESS_KEY": "your-secret-key",
        "S3_BUCKET": "media",
        "S3_PUBLIC_URL": "https://media.example.com",
        "S3_REGION": "auto"
      }
    }
  }
}

Cursor — add to ~/.cursor/mcp.json with the same shape as above.

Codex / Cline / Continue / Windsurf — consult your client's MCP config docs. The command is npx -y mcp-media-toolkit with environment variables passed in the env block.

As a Claude Code plugin (with skills)

The Claude Code plugin adds three slash-command skills on top of the MCP tools — the skills optimize prompts automatically and guide the workflow.

# Via the Claude Code marketplace (once published)
claude plugin add tadeukaiba/mcp-media-toolkit

Or clone the repository and point Claude Code at it manually.

Global npm install

If you prefer a global install over npx:

npm install -g mcp-media-toolkit

Then reference mcp-media-toolkit directly as the command in your MCP config instead of npx.

Configuration

All configuration is done via environment variables. The server validates everything at startup and reports any issue with a clear, actionable message.

Environment variables

Variable Required Description Example
GEMINI_API_KEY Yes Google AI Studio API key. Get one free at aistudio.google.com/apikey. AIza...
S3_ENDPOINT For upload Endpoint URL of your S3-compatible storage. https://abc123.r2.cloudflarestorage.com
S3_ACCESS_KEY_ID For upload S3 access key ID. AKIA...
S3_SECRET_ACCESS_KEY For upload S3 secret access key. abc123...
S3_BUCKET For upload Bucket name. media
S3_PUBLIC_URL For upload Public base URL where uploads are accessible. No trailing slash. https://media.example.com
S3_REGION Optional Region name. Defaults to auto. auto, us-east-1
IMAGE_OUTPUT_DIR Optional Directory for generated images. Defaults to ~/Pictures/mcp-media/. /tmp/images

All S3_* variables are all-or-nothing: set them all to enable upload, or leave them all unset to run generation only. A partial configuration is treated as an error so misconfigurations can't silently fail.

Provider-specific examples

Cloudflare R2

S3_ENDPOINT="https://<account-id>.r2.cloudflarestorage.com"
S3_ACCESS_KEY_ID="<r2-access-key>"
S3_SECRET_ACCESS_KEY="<r2-secret-key>"
S3_BUCKET="media"
S3_PUBLIC_URL="https://media.example.com"   # or https://pub-<hash>.r2.dev
S3_REGION="auto"

Enable public access either by turning on the bucket's public access setting or by binding a custom domain to the bucket in the Cloudflare dashboard.

AWS S3

S3_ENDPOINT="https://s3.us-east-1.amazonaws.com"
S3_ACCESS_KEY_ID="AKIA..."
S3_SECRET_ACCESS_KEY="..."
S3_BUCKET="my-bucket"
S3_PUBLIC_URL="https://my-bucket.s3.us-east-1.amazonaws.com"
S3_REGION="us-east-1"

Bucket must have public-read ACL or a bucket policy allowing s3:GetObject for public access.

MinIO

S3_ENDPOINT="https://minio.example.com"
S3_ACCESS_KEY_ID="minioadmin"
S3_SECRET_ACCESS_KEY="minioadmin"
S3_BUCKET="media"
S3_PUBLIC_URL="https://minio.example.com/media"
S3_REGION="us-east-1"

DigitalOcean Spaces

S3_ENDPOINT="https://nyc3.digitaloceanspaces.com"
S3_ACCESS_KEY_ID="DO..."
S3_SECRET_ACCESS_KEY="..."
S3_BUCKET="my-space"
S3_PUBLIC_URL="https://my-space.nyc3.digitaloceanspaces.com"
S3_REGION="nyc3"

Tools Reference

generate_image_gemini

Generate an AI image with Gemini and save it to disk.

Inputs

Name Type Default Description
prompt string (required) — Description of the image.
quality fast | balanced | quality fast fast → Nano Banana (1K). balanced → Nano Banana 2 (2K). quality → Nano Banana Pro (4K, much slower).
aspect_ratio 1:1 | 16:9 | 9:16 | 4:3 | 3:4 1:1 Aspect ratio.
format png | jpeg | webp png Output format.
output_dir string ~/Pictures/mcp-media/ Directory to save the image.

Returns — file path of the saved image plus a 256px thumbnail as an MCP image content block.

upload_image_s3

Upload any local image to S3-compatible storage and return the public URL.

Inputs

Name Type Default Description
file_path string (required) — Absolute path to the local file.
key string images/<timestamp>-<filename> Destination key in the bucket.
bucket string S3_BUCKET env var Override the configured bucket.

Returns — bucket, key, and public URL.

generate_and_upload_gemini_s3

One-shot generation + upload. Accepts all parameters from the two tools above.

Returns — local file path, public URL, and thumbnail. On partial failure (generation succeeded but upload failed) the response preserves the local path and thumbnail so no work is lost.

Skills Reference (Claude Code)

When installed as a Claude Code plugin, three slash-command skills are available:

  • /generate-image-gemini — guided image generation with automatic prompt optimization.
  • /upload-image-s3 — upload an existing local image and get a public URL.
  • /image-gemini-s3 — the most common workflow: prompt → optimized prompt → generation → upload → public URL.

The skills rewrite casual prompts into detailed, well-structured image descriptions before calling the underlying tools, so short requests like "a cat on a book" still produce high-quality images.

Prompt Optimization

The skills apply a Subject-Context-Style framework to user prompts before generation:

User: "a cat on a book"

Optimized: "A fluffy orange tabby cat curled up on top of an open vintage hardcover book, soft natural window light falling from the left, warm cozy tones, shallow depth of field, photorealistic, high detail."

The optimization happens on the Claude side (no extra API calls, no extra latency) and covers subject, composition, lighting, color palette, style, and technical quality.

Troubleshooting

GEMINI_API_KEY is required

Get a free key at aistudio.google.com/apikey and set it as an environment variable in your MCP client config.

S3 storage is not configured

You're calling an upload tool without any S3_* environment variables set. Either configure all of them (see Configuration) or use generate_image_gemini alone for local-only generation.

S3 upload requires all of: ... Missing: ...

You set some but not all of the S3_* variables. Partial config is rejected — set them all or unset them all.

S3_ENDPOINT must be a valid URL

The value isn't parseable as a URL. Include the protocol (https://) and check for typos.

S3 upload failed: Access Denied

Credentials are valid but the API token doesn't have permission to write to this bucket and key. On R2, check the API token's bucket permissions. On AWS S3, verify the IAM policy includes s3:PutObject.

S3 upload failed: NoSuchBucket

The bucket doesn't exist at S3_ENDPOINT. Create it or fix S3_BUCKET.

Public URL returns 403

Upload succeeded but the bucket isn't publicly readable. The fix depends on the provider:

  • R2: enable public access on the bucket in the Cloudflare dashboard, or bind a custom domain.
  • S3: add a bucket policy granting s3:GetObject to Principal: *, or enable ACLs.
  • MinIO: set the bucket policy to public read.

Gemini returned no image data

The model refused the prompt (usually content policy). Rephrase or simplify the prompt.

File not found

You passed a relative path or the file was deleted. Always use absolute paths for file_path.

Development

git clone https://github.com/tadeukaiba/mcp-media-toolkit.git
cd mcp-media-toolkit
npm install
npm run build
npm test

Run the server locally:

node dist/index.js

Contributing

Issues and PRs welcome. Please run npm test before opening a PR.

License

MIT © tadeukaiba

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选