mirror of
https://github.com/hanzoai/gimp-mcp.git
synced 2026-10-30 18:36:15 +00:00
3.8 KiB
3.8 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Overview
This is a GIMP MCP (Model Context Protocol) integration that enables external control of GIMP 3.0 through Claude Desktop and other MCP clients. The system consists of two main components:
- GIMP Plugin (
gimp-mcp-plugin.py): A GIMP 3.0 plugin that starts a socket server inside GIMP - MCP Server (
gimp-mcp-server.py): An MCP server that connects to the GIMP plugin and exposes GIMP functionality
Architecture
The system uses a client-server architecture:
- GIMP Plugin creates a socket server (localhost:9877) that accepts Python-Fu commands
- MCP Server connects to this socket and exposes a
call_apitool for MCP clients - Commands are executed in GIMP's Python-Fu environment with access to the full GIMP 3.0 API
Installation & Setup
GIMP Plugin Installation
# For snap installations
mkdir ~/snap/gimp/current/.config/GIMP/3.0/plug-ins/gimp-mcp-plugin
cp gimp-mcp-plugin.py ~/snap/gimp/current/.config/GIMP/3.0/plug-ins/gimp-mcp-plugin
chmod +x ~/snap/gimp/current/.config/GIMP/3.0/plug-ins/gimp-mcp-plugin/gimp-mcp-plugin.py
MCP Server Configuration
Add to Claude Desktop config (~/.config/Claude/claude_desktop_config.json):
{
"mcpServers": {
"gimp": {
"command": "uv",
"args": ["run", "--directory", "/path/to/gimp-mcp", "gimp-mcp-server.py"]
}
}
}
Development Commands
There are no build, test, or lint commands as this is a simple Python script project without dependencies or test framework.
API Usage
Core MCP Tool
The main interface is the call_api tool with parameters:
api_path: "exec" for Python-Fu executionargs: Array containing procedure name and code/expressions
Common Command Patterns
Execute Python Commands:
{
"api_path": "exec",
"args": ["exec", ["print('hello world')"]]
}
GIMP 3.0 API Key Points
- Use
Gimp.get_images()instead of deprecatedGimp.list_images() - Access layers via
image.get_layers()instead ofGimp.get_active_layer() - Colors are created with
Gegl.Color.new('color_name')or with color RGB values, e.g.Gegl.Color.new("rgb(1.0, 0.647, 0.0)"). Notice, each RGB value is in the range 0-1 - Always call
Gimp.displays_flush()after drawing operations
Essential Initialization Pattern
Most GIMP operations should start with this initialization:
images = Gimp.get_images()
image = images[0] # or image1 = images[0]
layers = image.get_layers()
layer = layers[0] # or layer1 = layers[0]
drawable = layer # or drawable1 = layer
Common Operations
Drawing a line:
Gimp.pencil(drawable, [x1, y1, x2, y2])
Gimp.displays_flush()
Setting colors:
red_color = Gegl.Color.new("red")
Gimp.context_set_foreground(red_color)
Creating shapes:
Gimp.Image.select_ellipse(image, Gimp.ChannelOps.REPLACE, x, y, width, height)
Gimp.Drawable.edit_fill(drawable, Gimp.FillType.FOREGROUND)
Gimp.Selection.none(image)
Gimp.displays_flush()
Important Notes
- Commands execute in a persistent Python context - imports and variables persist between calls
- GIMP 3.0 API differs significantly from 2.x - consult https://developer.gimp.org/api/3.0/libgimp/
- Always verify API calls work before building complex operations
- The
gimpfumodule is not available in GIMP 3.0 - Use proper error handling as socket connections can fail
File Structure
gimp-mcp-plugin.py: GIMP plugin with socket server and command executiongimp-mcp-server.py: MCP server that bridges socket to MCP protocolGIMP_MCP_PROTOCOL.md: Detailed API documentation and examplesRECIPES.md: Quick reference for common GIMP operationsREADME.md: Installation and setup instructions