Automation / Image Generation

Secure MCP Gateway for Third-Party Image Models

An authenticated Model Context Protocol server, built into an existing app, that lets a team generate and edit images with a third-party image model directly inside Claude, which has no native connector for it.

Workflow

PROCESS FLOW

From “Claude calls generate_image or edit_image” to result

  1. 1. Trigger

    Add the connector

    A team member adds the connector once in Claude.

  2. 2. Action

    Discover & register

    Claude reads the server's standard OAuth discovery metadata and registers itself as a client.

  3. 3. Action

    Sign in

    PKCE is mandatory; sign-in uses the app's own Google account and access rules.

  4. 4. Action

    Short-lived access

    Claude receives short-lived, refreshable access.

  5. 5. Action

    Claude calls a tool

    generate_image or edit_image, a small batch by default.

  6. 6. Action

    Model generates

    The server calls the image model with the requested size, quality and format.

  7. 7. Output

    Images inline

    Returned inline at full resolution, so they render in chat and inside Claude artifacts.

ANALOGY

OAuth for an MCP connector, explained

OAuth 2.1 with short-lived tokens is like A hotel key card

  • Sign in with the app's Google accountis like Show ID at reception
  • Short-lived access tokenis like A key card that expires
  • Refresh without signing in againis like Renew the card at the desk
The connector gets access the way a guest gets a room key: show ID at reception, receive a key card that expires, and renew it without checking in again.

Problem

The team works in Claude, but Claude has no native connector for OpenAI's image models. Generating an image meant leaving Claude, using another tool, and bringing the result back.

Architecture

The MCP server runs inside the existing app, so it needs no extra infrastructure and reuses the app's secure origin and sign-in. Authentication follows the OAuth 2.1 model for MCP: the server publishes standard discovery metadata so Claude can find and register with it automatically, PKCE is mandatory, and sign-in goes through the same Google account and access rules as the app itself, so nobody gets the connector who couldn't already use the app. Access is granted through short-lived tokens that are refreshed without signing in again. The server exposes two tools: generate_image (a prompt plus size, quality, background and format) and edit_image (source images plus an instruction).

DIAGRAM

One image request, end to end

sequenceDiagram
  participant U as Team member
  participant C as Claude
  participant S as MCP gateway
  participant G as Google sign-in
  participant O as Image model
  U->>C: add connector
  C->>S: discover and register
  C->>G: sign in with PKCE
  G-->>S: verified account
  S-->>C: short-lived access
  U->>C: image prompt
  C->>S: generate_image
  S->>O: image request
  O-->>S: images
  S-->>C: images inline
  C-->>U: images in chat
Claude discovers the server, registers and signs the user in with PKCE. After that, each tool call carries short-lived access, and the server calls the image model and returns the images inline.

Input

A prompt, and for edits one or more source images, sent by Claude as an MCP tool call along with optional size, quality, background, output format and model.

Output

A batch of images returned inline as base64 at full resolution and lossless. Returning them inline instead of as links matters: Claude artifacts run in a sandbox that blocks external URLs, so a link would not render there.

Integrations

Model Context ProtocolImage generation APIGoogle sign-inClaude custom connectors

Limitations

It covers image generation and editing only.

Security Notes

OAuth 2.1 with mandatory PKCE, sign-in restricted to the app's own users, short-lived access, and provider credentials kept server-side and never exposed to Claude or the client. The app refuses to start without properly configured secrets.

Learnings

Building the MCP server into the existing app, rather than as a separate service, meant no new infrastructure and the same sign-in the team already used. Standard discovery metadata plus dynamic client registration is what makes "add one connector, sign in with Google" possible.