MCP server for AI image generation via Microsoft Copilot
Project description
Copilot Image Generation MCP
An MCP server that connects GitHub Copilot CLI to Microsoft Copilot's image generation backend.
Generate images from text prompts and iteratively refine them — all from the terminal. Images are saved locally and organized by session.
Requirements
- Python 3.10+
- GitHub Copilot CLI
- Microsoft 365 Copilot license with image generation enabled
- A Chromium-based browser (Edge, Chrome, or Chromium) for first-time sign-in
Quick Start
-
Install
pip install git+https://github.com/msartem/copilot_image_gen_mcp.git
Or install from source:
git clone https://github.com/msartem/copilot_image_gen_mcp.git cd copilot_image_gen_mcp pip install .
-
Add to your MCP config (
~/.copilot/mcp-config.json){ "mcpServers": { "copilot-image-gen": { "type": "stdio", "command": "copilot-image-gen" } } }
-
Launch Copilot CLI
copilot
-
Sign in (first time only)
Copilot will automatically call
sign_inwhen needed. An Edge browser window opens — sign in with your Microsoft 365 account. The auth code is captured automatically via Playwright (no manual copy-paste). -
Try it out
Generate an image of an elephant in Times Square Make the elephant golden Change the background to a sunset over mountains
After first sign-in, auth is silent via cached refresh tokens (~90 day lifetime, auto-renewing). No browser window on subsequent uses.
How It Works
- You ask Copilot CLI to generate or modify an image
- Copilot routes it to the
generate_imageorrefine_imagetool - The MCP server opens a WebSocket to Microsoft Copilot's backend
- The backend generates the image (DALL-E) and returns it as base64 PNG
- The image is saved to
~/.copilot-images/and the file path is returned
Multi-turn refinement works automatically — the server maintains a conversation
so each refine_image call builds on the previous image.
You → Copilot CLI → image gen MCP → M365 Copilot (Sydney) → DALL-E → PNG saved locally
Tools
| Tool | Description |
|---|---|
generate_image(prompt, orientation) |
Generate a new image from text. Blocks ~15-30s, returns file path. |
refine_image(prompt) |
Modify the last generated image. Same conversation context. |
sign_in() |
Sign in to Microsoft 365 (opens browser, one-time). |
new_session() |
Start a fresh conversation (discard previous image context). |
Orientation Options
landscape(default)portraitsquare
Image Storage
Images are saved to ~/.copilot-images/ organized by session. Each session
groups an initial image with its refinements:
~/.copilot-images/
├── 20250115_143022_elephant_in_times_square/
│ ├── session.json ← metadata (prompts, timestamps)
│ ├── 001_elephant_in_times_square.png ← initial image
│ ├── 002_make_the_elephant_golden.png ← first refinement
│ └── 003_change_the_background_to_a_sunset.png ← second refinement
└── 20250116_091200_sunset_over_mountains/
├── session.json
└── 001_sunset_over_mountains.png
Session directories are created lazily on first image save — no side effects until you actually generate something.
Authentication
Authentication uses Playwright to automate browser sign-in via Microsoft Edge. This works identically on macOS and Windows — no platform-specific code.
First sign-in
- Copilot calls
sign_in(or you trigger it manually) - An Edge window opens to the Microsoft sign-in page
- Sign in with your M365 account (SSO may auto-complete this)
- The auth code is captured automatically — the browser closes
- Tokens are cached locally
Subsequent runs
Cached refresh tokens are used — no browser window, no interaction needed.
Browser selection
Playwright uses Microsoft Edge by default. To use a different Chromium-based browser:
export COPILOT_BROWSER=chrome # or: msedge (default), chromium
Note:
chromiumrequiresplaywright install chromium. Edge and Chrome use your installed browser directly — no extra install needed.
Manual auth
python auth.py # Interactive sign-in
python auth.py logout # Clear cached tokens
Token storage
| Platform | Cache location |
|---|---|
| macOS / Linux | ~/.copilot-image-gen-mcp/token_cache.json |
| Windows | %LOCALAPPDATA%\copilot-image-gen-mcp\token_cache.json |
Environment Variables
| Variable | Default | Description |
|---|---|---|
COPILOT_IMAGES_DIR |
~/.copilot-images |
Image output directory |
COPILOT_BROWSER |
msedge |
Browser for sign-in: msedge, chrome, chromium |
COPILOT_TENANT |
common |
Azure AD tenant ID |
COPILOT_TIMEOUT |
90 |
Image generation timeout in seconds |
COPILOT_VARIANTS |
(built-in) | Feature flag overrides (advanced) |
Technical Details
See TECHNICAL.md for details on the SignalR WebSocket protocol, authentication flow, image delivery format, and multi-turn refinement architecture.
Disclaimer
This is an independent community project — not affiliated with or supported by Microsoft.
It works by communicating with the same undocumented web APIs that power the M365 Copilot web/desktop app image generation. These APIs may change or break without notice. Use at your own risk.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file copilot_image_gen_mcp-0.1.0.tar.gz.
File metadata
- Download URL: copilot_image_gen_mcp-0.1.0.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d670ace59415f20297b681c02202cea6144c344cb8241ebfecbbac8f57307a79
|
|
| MD5 |
317599b03377afcfbc26e8dbde9124c2
|
|
| BLAKE2b-256 |
d638e299f63ede1d79edefdb8a850f90cd7d4439a1e44aa09eda8c9776422eac
|
Provenance
The following attestation bundles were made for copilot_image_gen_mcp-0.1.0.tar.gz:
Publisher:
publish.yml on msartem/copilot_image_gen_mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
copilot_image_gen_mcp-0.1.0.tar.gz -
Subject digest:
d670ace59415f20297b681c02202cea6144c344cb8241ebfecbbac8f57307a79 - Sigstore transparency entry: 1299854758
- Sigstore integration time:
-
Permalink:
msartem/copilot_image_gen_mcp@cc293e940ffbc9df652729805306d296a2ae7966 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/msartem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cc293e940ffbc9df652729805306d296a2ae7966 -
Trigger Event:
release
-
Statement type:
File details
Details for the file copilot_image_gen_mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: copilot_image_gen_mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af231d619bef9072d6a574c7f85578f8c1574e55694e0935987383d26afbe194
|
|
| MD5 |
e3101f518c6b53294bb47287af99153a
|
|
| BLAKE2b-256 |
0e1453c269258f658d07e634f1c6decfc1d59ec54bc4a0650e821588212a2567
|
Provenance
The following attestation bundles were made for copilot_image_gen_mcp-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on msartem/copilot_image_gen_mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
copilot_image_gen_mcp-0.1.0-py3-none-any.whl -
Subject digest:
af231d619bef9072d6a574c7f85578f8c1574e55694e0935987383d26afbe194 - Sigstore transparency entry: 1299854830
- Sigstore integration time:
-
Permalink:
msartem/copilot_image_gen_mcp@cc293e940ffbc9df652729805306d296a2ae7966 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/msartem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cc293e940ffbc9df652729805306d296a2ae7966 -
Trigger Event:
release
-
Statement type: