Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Adobe Firefly Python Client Library & CLI
# Adobe Firefly Python Client Library, CLI, and MCP Server

[![CI](https://github.com/msabramo/python-firefly/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/msabramo/python-firefly/actions/workflows/ci.yml)

A Python client for the Adobe Firefly API,
created using the [Adobe Firefly API Documentation].
Pythonic, CLItastic, MCPerific image generation with the [Adobe Firefly API][Adobe Firefly API Documentation]

## Features

- Authenticate with Adobe Firefly using client ID and secret
- Automatically handles access token retrieval and refresh
- Generate images from text prompts
- Simple, extensible interface
- CLI for generating images from the command line
- MCP server for use in editors like Cursor

## Requirements

Expand Down Expand Up @@ -43,6 +44,11 @@ print("Content class:", response.contentClass)
- Generate an image from a text prompt. Returns a response object with attributes matching the API response (including outputs, size, contentClass, etc).
- Additional keyword arguments are passed as parameters to the API.

## Error Handling

- `FireflyAuthError`: Raised for authentication/token errors
- `FireflyAPIError`: Raised for general API errors or unexpected responses

## Command Line Interface (CLI)

The `firefly` CLI allows you to generate images from the command line using the Adobe Firefly API.
Expand Down Expand Up @@ -91,13 +97,35 @@ firefly image generate \

The CLI will print the generated image URL.

## Error Handling
## MCP Server Integration

You can use this package as an [MCP] server, for example in editors like Cursor that support MCP servers.

To add the Adobe Firefly MCP server, add the following to the `mcpServers` or such section of an `mcp.json` file for your tool of choice:

```json
"adobe_firefly": {
"type": "stdio",
"env": {
"FIREFLY_CLIENT_ID": "13cc...",
"FIREFLY_CLIENT_SECRET": "p8e-CB..."
},
"command": "uvx",
"args": [
"--from",
"git+https://github.com/msabramo/python-firefly[mcp-server]",
"mcp-server"
]
},
```

- `FireflyAuthError`: Raised for authentication/token errors
- `FireflyAPIError`: Raised for general API errors or unexpected responses
Replace the `FIREFLY_CLIENT_ID` and `FIREFLY_CLIENT_SECRET` values with your own credentials.

This will allow your editor to communicate with the Adobe Firefly API via the MCP server provided by this package.

## More Information

- [Adobe Firefly API Documentation]

[Adobe Firefly API Documentation]: https://developer.adobe.com/firefly-services/docs/firefly-api/guides/#generate-an-image
[MCP]: https://modelcontextprotocol.io/introduction
73 changes: 73 additions & 0 deletions firefly/mcp/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Firefly MCP server using FastMCP

# Standard library imports
import os
from typing import Optional

# Third-party imports
from fastmcp import FastMCP

# Local imports
from firefly.client import FireflyClient

mcp = FastMCP("Adobe Firefly Image Generation MCP Server")


@mcp.tool()
def generate_image(
prompt: str,
client_id: Optional[str] = None,
client_secret: Optional[str] = None,
num_variations: int = 1,
style: Optional[dict] = None,
structure: Optional[dict] = None,
prompt_biasing_locale_code: Optional[str] = None,
negative_prompt: Optional[str] = None,
seed: Optional[int] = None,
aspect_ratio: Optional[str] = None,
output_format: Optional[str] = None,
content_class: Optional[str] = None,
) -> dict:
"""
Generate an image using Adobe Firefly API.
Args:
prompt (str): The text prompt for image generation.
client_id (str, optional): Firefly client ID. If not provided, uses FIREFLY_CLIENT_ID env var.
client_secret (str, optional): Firefly client secret. If not provided, uses FIREFLY_CLIENT_SECRET env var.
num_variations, style, structure, prompt_biasing_locale_code, negative_prompt, seed, aspect_ratio, output_format, content_class: FireflyClient.generate_image params.
Returns:
dict: The Firefly image response as a dict.
"""

client_id = client_id or os.environ.get("FIREFLY_CLIENT_ID")
client_secret = client_secret or os.environ.get("FIREFLY_CLIENT_SECRET")
if not client_id or not client_secret:
raise ValueError(
"client_id and client_secret must be provided as arguments or environment variables."
)
style_arg = style or None
structure_arg = structure or None
client = FireflyClient(client_id=client_id, client_secret=client_secret)
response = client.generate_image(
prompt=prompt,
num_variations=num_variations,
style=style_arg,
structure=structure_arg,
prompt_biasing_locale_code=prompt_biasing_locale_code,
negative_prompt=negative_prompt,
seed=seed,
aspect_ratio=aspect_ratio,
output_format=output_format,
content_class=content_class,
)
return response.json() or {
"size": {"width": response.size.width, "height": response.size.height},
"outputs": [
{"seed": o.seed, "image": {"url": o.image.url}} for o in response.outputs
],
"contentClass": response.contentClass,
}


if __name__ == "__main__":
mcp.run()
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ dev = [
cli = [
"typer>=0.12.3",
]
mcp-server = [
"fastmcp>=0.7.0"
]

[project.scripts]
firefly = "firefly.cli:app"
mcp-server = "firefly.mcp.server:mcp.run"

[build-system]
requires = ["setuptools>=61.0"]
Expand Down
Loading