Skip to main content

MCP Server for GIMP - AI Assistant for Image Editing

Project description

GIMP MCP Server

Python 3.9+ License: MIT Code style: black Tests Documentation

A comprehensive Model Context Protocol (MCP) server implementation for GIMP 3.0+, enabling AI assistants to perform sophisticated image editing operations through GIMP's GObject Introspection bindings.

๐ŸŒŸ Features

Core Capabilities

  • ๐ŸŽจ Document Management: Create, open, save, and export GIMP documents
  • ๐Ÿ—‚๏ธ Layer Operations: Advanced layer management with opacity, blend modes, and transformations
  • โœ๏ธ Drawing Tools: Brush strokes, shapes, and artistic drawing operations
  • ๐Ÿ”ฒ Selection Tools: Rectangular, elliptical, and advanced selection management
  • ๐ŸŽจ Color Management: Color sampling, palette operations, and color space handling
  • ๐ŸŽญ Filter Operations: Image filters and effects processing
  • ๐Ÿ”„ Hybrid Mode Support: Seamless operation in both GUI and headless environments
  • ๐Ÿ“ก Real-time Resources: Live document state and system status monitoring

Advanced Features

  • โšก High Performance: Optimized for both single operations and batch processing
  • ๐Ÿ›ก๏ธ Robust Error Handling: Comprehensive error management and recovery
  • ๐Ÿ”ง Extensible Architecture: Modular design for easy feature additions
  • ๐Ÿ“Š Resource Monitoring: Real-time document and system state tracking
  • ๐Ÿ” Comprehensive Logging: Detailed operation tracking and debugging

๐Ÿ“‹ Requirements

System Requirements

  • Operating System: Linux (Ubuntu 20.04+), Windows 10+, macOS 11+
  • Python: 3.9+ (for GIMP 3.0 compatibility)
  • GIMP: 3.0+ with Python support enabled
  • Memory: 4GB RAM minimum, 8GB recommended for large images
  • Storage: 1GB free space for installation

Dependencies

  • GTK4: GTK4 development libraries
  • GObject: GObject Introspection libraries
  • PyGObject: Python GObject bindings
  • FastMCP: MCP server framework

๐Ÿš€ Installation

Quick Install (Recommended)

# Install from PyPI (when available)
pip install gimp-mcp-server

# Or install from source
pip install git+https://github.com/gimp-mcp/gimp-mcp-server.git

Detailed Installation

For detailed installation instructions including platform-specific setup, see our Installation Guide.

Linux (Ubuntu/Debian)

# Install system dependencies
sudo apt update
sudo apt install gimp-3.0 python3-dev python3-pip
sudo apt install libgtk-4-dev libgirepository1.0-dev

# Install Python dependencies
pip3 install PyGObject
pip3 install gimp-mcp-server

macOS (Homebrew)

# Install dependencies
brew install gimp python@3.9 gtk4 gobject-introspection
pip3 install PyGObject gimp-mcp-server

Windows

See Windows Installation Guide for detailed setup instructions.

๐ŸŽฏ Quick Start

1. Start the Server

# Basic startup
gimp-mcp-server

# With custom configuration
gimp-mcp-server --port 3000 --host localhost --debug

2. Connect with Claude Desktop

Add to your Claude Desktop configuration file:

Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Linux: ~/.config/claude/claude_desktop_config.json

{
  "mcpServers": {
    "gimp": {
      "command": "gimp-mcp-server",
      "args": []
    }
  }
}

3. Test the Connection

In Claude Desktop, try:

"Create a new 1920x1080 document and add a red circle in the center"

Claude will automatically:

  1. Create the document using create_document
  2. Draw the circle using draw_ellipse
  3. Set appropriate colors and layers

๐Ÿ—๏ธ Architecture

The GIMP MCP Server follows a modern, modular architecture:

src/gimp_mcp/
โ”œโ”€โ”€ server.py              # FastMCP server implementation
โ”œโ”€โ”€ gimp_api.py            # GIMP GI bindings wrapper
โ”œโ”€โ”€ mode_manager.py        # GUI/Headless mode detection
โ”œโ”€โ”€ tools/                 # MCP tool implementations
โ”‚   โ”œโ”€โ”€ document_tools.py  # Document management
โ”‚   โ”œโ”€โ”€ layer_tools.py     # Layer operations
โ”‚   โ”œโ”€โ”€ drawing_tools.py   # Drawing operations
โ”‚   โ”œโ”€โ”€ selection_tools.py # Selection management
โ”‚   โ”œโ”€โ”€ color_tools.py     # Color operations
โ”‚   โ””โ”€โ”€ filter_tools.py    # Filter operations
โ”œโ”€โ”€ resources/             # MCP resource providers
โ”‚   โ””โ”€โ”€ providers.py       # Real-time state resources
โ””โ”€โ”€ utils/                 # Utility modules
    โ”œโ”€โ”€ logging.py         # Structured logging
    โ”œโ”€โ”€ errors.py          # Error handling
    โ”œโ”€โ”€ gi_helpers.py      # GObject helpers
    โ””โ”€โ”€ image_utils.py     # Image processing

๐Ÿ› ๏ธ Available Tools

Document Management (6 tools)

Tool Description Key Parameters
create_document Create new documents width, height, resolution, color_mode
open_document Open existing files file_path
save_document Save documents document_id, file_path
export_document Export to formats file_path, format, options
get_document_info Get document details document_id
list_documents List open documents None

Layer Operations (8 tools)

Tool Description Key Parameters
create_layer Create new layers name, layer_type, opacity, blend_mode
get_layer_info Get layer details layer_id, document_id
set_layer_opacity Adjust opacity layer_id, opacity
set_layer_blend_mode Change blend mode layer_id, blend_mode
set_layer_visibility Toggle visibility layer_id, visible
duplicate_layer Duplicate layers layer_id, new_name
delete_layer Remove layers layer_id
move_layer Reorder layers layer_id, new_position

Drawing Tools (4 tools)

Tool Description Key Parameters
apply_brush_stroke Paint with brushes points, brush_name, size, color
draw_rectangle Draw rectangles x, y, width, height, fill_color
draw_ellipse Draw ellipses center_x, center_y, radius_x, radius_y
bucket_fill Fill areas x, y, color, threshold

Selection Tools (4 tools)

Tool Description Key Parameters
create_rectangular_selection Rectangle selections x, y, width, height
create_elliptical_selection Ellipse selections center_x, center_y, radius_x, radius_y
modify_selection Modify selections operation, value
clear_selection Clear selections None

Color Management (4 tools)

Tool Description Key Parameters
set_foreground_color Set foreground color
set_background_color Set background color
sample_color Sample from image x, y, sample_merged
get_active_palette Get color palette None

Filter Operations (3 tools)

Tool Description Key Parameters
apply_blur Blur effects radius, method
apply_sharpen Sharpen effects amount, threshold
adjust_brightness_contrast Adjust levels brightness, contrast

๐Ÿ“ก Available Resources

Real-time State Monitoring

  • document://current - Current document state
  • document://list - List of open documents
  • document://metadata - Document metadata
  • system://status - System and server status
  • system://capabilities - Server capabilities
  • system://health - System health information
  • palettes://active - Active color palette
  • brushes://list - Available brush presets
  • tools://current - Current tool state

๐Ÿ’ก Example Usage

Basic Image Creation

// Create a new document
const doc = await mcp.callTool("create_document", {
  width: 1024,
  height: 768,
  name: "My Artwork"
});

// Create a layer for shapes
const layer = await mcp.callTool("create_layer", {
  name: "Shapes",
  layer_type: "RGB"
});

// Draw a blue rectangle
await mcp.callTool("draw_rectangle", {
  x: 100,
  y: 100,
  width: 300,
  height: 200,
  fill_color: "#3498DB"
});

// Add a red circle
await mcp.callTool("draw_ellipse", {
  center_x: 250,
  center_y: 200,
  radius_x: 80,
  radius_y: 80,
  fill_color: "#E74C3C"
});

// Save the document
await mcp.callTool("save_document", {
  file_path: "/path/to/my-artwork.xcf"
});

// Export as PNG
await mcp.callTool("export_document", {
  file_path: "/path/to/my-artwork.png",
  options: { optimize: true }
});

Batch Processing

// Process multiple images
const images = ["image1.jpg", "image2.jpg", "image3.jpg"];

for (const imagePath of images) {
  // Open image
  const doc = await mcp.callTool("open_document", {
    file_path: imagePath
  });
  
  // Apply blur filter
  await mcp.callTool("apply_blur", {
    radius: 2.0,
    method: "gaussian"
  });
  
  // Adjust brightness
  await mcp.callTool("adjust_brightness_contrast", {
    brightness: 10,
    contrast: 5
  });
  
  // Export processed version
  await mcp.callTool("export_document", {
    file_path: imagePath.replace(".jpg", "_processed.png")
  });
}

๐Ÿงช Testing

Run Tests

# Install test dependencies
pip install -e ".[dev]"

# Run all tests
pytest

# Run with coverage
pytest --cov=gimp_mcp --cov-report=html

# Run specific test categories
pytest -m unit          # Unit tests only
pytest -m integration   # Integration tests only
pytest -m "not slow"    # Exclude slow tests

Test Server Connection

# Quick connection test
gimp-mcp-server --test-connection

# System requirements check
gimp-mcp-server --system-check

# Run in debug mode
GIMP_MCP_DEBUG=1 gimp-mcp-server --debug

๐Ÿ”ง Configuration

Environment Variables

export GIMP_MCP_DEBUG=1          # Enable debug logging
export GIMP_MCP_HOST=localhost   # Server host
export GIMP_MCP_PORT=3000        # Server port
export GIMP_MCP_MODE=hybrid      # Mode: gui, headless, or hybrid
export GIMP_MCP_LOG_LEVEL=INFO   # Logging level

Advanced Configuration

# Custom GIMP path
export GIMP_PATH=/custom/path/to/gimp

# Memory settings
export GIMP_CACHE_SIZE=4096      # 4GB cache
export GIMP_TILE_CACHE_SIZE=2048 # 2GB tiles

# Performance tuning
export GIMP_NUM_PROCESSORS=4     # CPU cores to use
export GIMP_USE_OPENCL=yes       # GPU acceleration

๐Ÿ“– Documentation

Comprehensive Docs

Quick Reference

Developer Resources

๐Ÿšจ Troubleshooting

Common Issues

GIMP Connection Failed

# Check GIMP installation
which gimp && gimp --version

# Test GIMP Python support
gimp --batch-interpreter=python-fu-eval --batch='print("Python OK")' --batch='quit()'

# Install missing dependencies
pip install PyGObject

Module Import Errors

# Install system dependencies (Ubuntu)
sudo apt install python3-gi python3-gi-cairo gir1.2-gtk-4.0

# Install system dependencies (macOS)
brew install pygobject3 gtk+3

Permission Errors

# Linux: Add user to video group
sudo usermod -a -G video $USER

# Restart session after group changes

For detailed troubleshooting, see our Troubleshooting Guide.

๐Ÿš€ Performance

Optimization Tips

  1. Use appropriate image sizes - Larger images consume more memory and processing time
  2. Batch related operations - Group similar operations together
  3. Monitor system resources - Close unused documents to free memory
  4. Use headless mode - For batch processing without GUI overhead
  5. Enable GPU acceleration - Set GIMP_USE_OPENCL=yes for compatible operations

Benchmarks

  • Document creation: ~50ms for standard sizes (1920x1080)
  • Layer operations: ~10-30ms depending on complexity
  • Drawing operations: ~20-100ms depending on brush size and stroke length
  • Filter operations: ~100ms-5s depending on filter type and image size

๐Ÿค Contributing

We welcome contributions! Please see our Development Guide for details.

Quick Contribution Steps

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-tool
  3. Make your changes with tests
  4. Run the test suite: pytest
  5. Submit a pull request

Development Setup

# Clone and setup
git clone https://github.com/gimp-mcp/gimp-mcp-server.git
cd gimp-mcp-server

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install in development mode
pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install

# Run tests
pytest

๐Ÿ“Š Project Status

Current Status

  • โœ… Core Implementation: Complete with all major tools
  • โœ… Documentation: Comprehensive user and developer docs
  • โœ… Testing: Full test suite with unit and integration tests
  • โœ… Error Handling: Robust error management and recovery
  • โœ… Performance: Optimized for production use
  • ๐Ÿ”„ PyPI Release: Coming soon
  • ๐Ÿ”„ GUI Integration: Enhanced GUI mode features

Roadmap

  • v1.1: Enhanced filter operations and batch processing
  • v1.2: Plugin system for custom tools
  • v1.3: Advanced selection tools and path operations
  • v2.0: GIMP 3.1+ support and new features

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • GIMP Development Team - For excellent GObject Introspection bindings
  • FastMCP Framework - For robust MCP server implementation
  • Model Context Protocol - For standardized AI tool integration
  • Community Contributors - For testing, feedback, and contributions

๐Ÿ“ž Support & Community


Made with โค๏ธ for the GIMP and AI community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gimp_mcp_server-0.1.0.tar.gz (227.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gimp_mcp_server-0.1.0-py3-none-any.whl (51.3 kB view details)

Uploaded Python 3

File details

Details for the file gimp_mcp_server-0.1.0.tar.gz.

File metadata

  • Download URL: gimp_mcp_server-0.1.0.tar.gz
  • Upload date:
  • Size: 227.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for gimp_mcp_server-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1d55e4630af6104994b8c698a336f74649b9468a33b2d7d57142250d6891f270
MD5 8d052ecbf49d06bf61b04b50fe2b0146
BLAKE2b-256 20dd5bbe580bce9f29fb526d17d07dea9300227f038d8971cd2fc9db067f525f

See more details on using hashes here.

File details

Details for the file gimp_mcp_server-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gimp_mcp_server-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cab5d7aaec343d394b2b1b45302b08bf481261aa806bf59207b938764e2bbf1c
MD5 67903f32301f7e31f6956386555d92fb
BLAKE2b-256 ff3dbe4a1c3f37ad735a3ceeb3dca7a3f465ea502b282b028365d252cf39d212

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page