gimp-agent-mcp 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. gimp_agent_mcp-0.2.0/.github/workflows/ci.yml +31 -0
  2. gimp_agent_mcp-0.2.0/.github/workflows/live-windows.yml +45 -0
  3. gimp_agent_mcp-0.2.0/.github/workflows/release.yml +37 -0
  4. gimp_agent_mcp-0.2.0/.gitignore +10 -0
  5. gimp_agent_mcp-0.2.0/.mcp.json.example +11 -0
  6. gimp_agent_mcp-0.2.0/AGENTS.md +13 -0
  7. gimp_agent_mcp-0.2.0/CHANGELOG.md +52 -0
  8. gimp_agent_mcp-0.2.0/CLAUDE.md +43 -0
  9. gimp_agent_mcp-0.2.0/CONTRIBUTING.md +9 -0
  10. gimp_agent_mcp-0.2.0/LICENSE +201 -0
  11. gimp_agent_mcp-0.2.0/PKG-INFO +167 -0
  12. gimp_agent_mcp-0.2.0/README.md +132 -0
  13. gimp_agent_mcp-0.2.0/ROADMAP.md +22 -0
  14. gimp_agent_mcp-0.2.0/SECURITY.md +25 -0
  15. gimp_agent_mcp-0.2.0/docs/ARCHITECTURE.md +75 -0
  16. gimp_agent_mcp-0.2.0/docs/RECIPES.md +37 -0
  17. gimp_agent_mcp-0.2.0/docs/hero.png +0 -0
  18. gimp_agent_mcp-0.2.0/pyproject.toml +82 -0
  19. gimp_agent_mcp-0.2.0/server.json +26 -0
  20. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/__init__.py +3 -0
  21. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/bridge_client.py +178 -0
  22. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/cli.py +126 -0
  23. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/paths.py +165 -0
  24. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/plugin/__init__.py +1 -0
  25. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/plugin/agent_bridge_core.py +194 -0
  26. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/plugin/gimp-agent-bridge.py +1478 -0
  27. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/recipes/__init__.py +63 -0
  28. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/recipes/contact_sheet.py +70 -0
  29. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/recipes/fit_and_export.py +46 -0
  30. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/recipes/icon_set.py +58 -0
  31. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/recipes/sprite_sheet_slice.py +60 -0
  32. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/recipes/telegram_sticker.py +102 -0
  33. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/recipes/watermark.py +56 -0
  34. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/recipes/web_optimise.py +71 -0
  35. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/segmentation.py +46 -0
  36. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/server.py +517 -0
  37. gimp_agent_mcp-0.2.0/src/gimp_agent_mcp/smoke.py +321 -0
  38. gimp_agent_mcp-0.2.0/tests/test_core.py +89 -0
  39. gimp_agent_mcp-0.2.0/tests/test_live.py +18 -0
  40. gimp_agent_mcp-0.2.0/tests/test_paths.py +57 -0
  41. gimp_agent_mcp-0.2.0/tests/test_recipes.py +33 -0
  42. gimp_agent_mcp-0.2.0/tests/test_server.py +38 -0
  43. gimp_agent_mcp-0.2.0/uv.lock +1738 -0
@@ -0,0 +1,31 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ name: Lint and unit tests
14
+ runs-on: ${{ matrix.os }}
15
+ timeout-minutes: 10
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ os: [ubuntu-latest, windows-latest]
20
+ python: ["3.11", "3.13"]
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+ - uses: astral-sh/setup-uv@v5
24
+ - name: Install
25
+ run: uv sync --extra dev --python ${{ matrix.python }}
26
+ - name: Lint
27
+ run: uv run ruff check .
28
+ - name: Unit tests (no GIMP required)
29
+ run: uv run pytest
30
+ - name: Build wheel
31
+ run: uv build
@@ -0,0 +1,45 @@
1
+ name: Live smoke (Windows + GIMP 3)
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ live:
14
+ name: Real GIMP 3 headless smoke test
15
+ runs-on: windows-latest
16
+ timeout-minutes: 25
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - uses: astral-sh/setup-uv@v5
20
+ - name: Install GIMP 3 (official Inno installer, silent)
21
+ shell: pwsh
22
+ run: |
23
+ $url = "https://download.gimp.org/gimp/v3.2/windows/gimp-3.2.4-setup.exe"
24
+ Invoke-WebRequest -Uri $url -OutFile "$env:RUNNER_TEMP\gimp-setup.exe"
25
+ Start-Process -FilePath "$env:RUNNER_TEMP\gimp-setup.exe" -ArgumentList "/VERYSILENT","/NORESTART","/SUPPRESSMSGBOXES","/ALLUSERS" -Wait
26
+ Get-ChildItem "C:\Program Files\GIMP 3\bin" -Filter "gimp-console-*.exe" | Select-Object -ExpandProperty FullName
27
+ - name: Install project
28
+ run: uv sync --extra dev
29
+ - name: Install bridge plug-in
30
+ shell: pwsh
31
+ run: |
32
+ New-Item -ItemType Directory -Force "$env:APPDATA\GIMP\3.2" | Out-Null
33
+ uv run gimp-agent-mcp install-plugin
34
+ uv run gimp-agent-mcp doctor
35
+ - name: Headless smoke test
36
+ env:
37
+ GIMP_AGENT_LIVE: "1"
38
+ run: uv run gimp-agent-mcp smoke --mode headless
39
+ - name: Upload launch log on failure
40
+ if: failure()
41
+ uses: actions/upload-artifact@v4
42
+ with:
43
+ name: gimp-agent-launch-log
44
+ path: ${{ env.APPDATA }}/GIMP/3.2/gimp-agent-launch.log
45
+ if-no-files-found: ignore
@@ -0,0 +1,37 @@
1
+ name: Release to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: astral-sh/setup-uv@v5
16
+ - run: uv sync --extra dev
17
+ - run: uv run ruff check .
18
+ - run: uv run pytest
19
+ - run: uv build
20
+ - uses: actions/upload-artifact@v4
21
+ with:
22
+ name: dist
23
+ path: dist/
24
+
25
+ publish:
26
+ needs: build
27
+ runs-on: ubuntu-latest
28
+ environment: pypi
29
+ permissions:
30
+ id-token: write
31
+ steps:
32
+ - uses: actions/download-artifact@v4
33
+ with:
34
+ name: dist
35
+ path: dist/
36
+ # Trusted publishing: configure the PyPI project with this repo, workflow "release.yml", environment "pypi".
37
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,10 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ .mcp.local.json
10
+ *.log
@@ -0,0 +1,11 @@
1
+ {
2
+ "mcpServers": {
3
+ "gimp": {
4
+ "command": "uv",
5
+ "args": ["run", "--directory", "/absolute/path/to/gimp-agent-mcp", "gimp-agent-mcp", "serve"],
6
+ "env": {
7
+ "GIMP_AGENT_ALLOW_PYTHON": "1"
8
+ }
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,13 @@
1
+ # Repository instructions
2
+
3
+ This repository is the public, Apache-2.0 GIMP Agent MCP server.
4
+
5
+ - Two processes, one contract: `src/gimp_agent_mcp/plugin/gimp-agent-bridge.py` runs inside GIMP; everything else runs in the MCP server. The bridge may only depend on the Python standard library, `gi`, and `agent_bridge_core.py`, because it is copied into GIMP's plug-in folder on its own.
6
+ - `agent_bridge_core.py` must never import `gi`. It is shared with the server and the unit tests.
7
+ - Every GIMP-side operation runs on the plug-in main thread through `GLib.idle_add`. Do not call libgimp from the socket thread.
8
+ - Prefer generic, introspected access (PDB and GEGL property descriptions read from GIMP at runtime) over hand-written wrappers. Add a dedicated tool only when the generic path is genuinely awkward for an agent.
9
+ - Recipes are Python source strings executed inside GIMP with `params` injected. They declare `DESCRIPTION`, `PARAMS`, `SOURCE`, and assign `result`.
10
+ - Keep the bridge on loopback with a required token. Never add a network-exposed mode.
11
+ - Keep real identities, machine paths, tokens and private material out of this repository.
12
+ - Run `uv run ruff check .` and `uv run pytest` before committing. Run `uv run gimp-agent-mcp smoke` on a machine with GIMP 3 before tagging a release.
13
+ - Update `docs/ARCHITECTURE.md`, `CHANGELOG.md` and the tool table in `README.md` when the tool surface or protocol changes.
@@ -0,0 +1,52 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.2.0] - 2026-09-05
10
+
11
+ The detailed-work release: measurement, comparison renders, selection and masks, text, paths, effect editing, AI cut-outs and a recipe library. 32 tools, 7 recipes, 22 live checks including the AI cut-out.
12
+
13
+ ### Added
14
+
15
+ - `gimp_measure`: colour at a point, bounding box of visible pixels, per-channel histogram, dominant colours.
16
+ - `gimp_snapshot` and `gimp_render_compare`: before / after / pixel-diff renders.
17
+ - `gimp_select`: rect, ellipse, by colour, by alpha, from item, all/none/invert, grow/shrink/feather/border, bounds.
18
+ - `gimp_layer_mask` (add from selection/alpha/white/black/copy, apply, remove, enable/disable, show/hide) and raw mask pixel writes via the bridge.
19
+ - `gimp_layer`: new, set, move, reorder, duplicate, merge_down, delete, resize_to_image, scale, add_alpha, crop_to_content.
20
+ - `gimp_layer_effect`: edit params, opacity, blend mode and visibility of non-destructive effects, or delete them.
21
+ - `gimp_text` and `gimp_list_fonts`: create and edit text layers with font, size, colour, justification, spacing and fixed boxes.
22
+ - `gimp_path`: create line/bezier paths, select, stroke, fill, delete.
23
+ - `gimp_remove_background`: rembg-based subject segmentation into an editable layer mask or baked alpha. Optional `segmentation` extra.
24
+ - `gimp_export` gained `options` passed to the format's export procedure (JPEG quality, WebP quality/lossless, PNG compression).
25
+ - Recipes: `web_optimise`, `icon_set`, `watermark`, `contact_sheet`, `sprite_sheet_slice`.
26
+ - `export_with` helper available to recipes and `gimp_run_python`.
27
+ - Live Windows CI: installs GIMP 3.2.4 on a runner and runs the smoke test on every push.
28
+ - Release workflow for PyPI trusted publishing on `v*` tags; `server.json` for the MCP Registry.
29
+
30
+ ### Changed
31
+
32
+ - Enum coercion resolves lazily-created and dynamically registered GEnum types (PyGObject + GEGL).
33
+ - Tool failures surface as `ToolError`; bridge tracebacks are attached only for unexpected exception types.
34
+ - Headless sessions quit GIMP through the `gimp-quit` PDB procedure after the bridge returns.
35
+
36
+ ### Fixed
37
+
38
+ - `Image.set_name`, `Gimp.display_present` and `Gimp.Selection.bounds` arity mismatches against GIMP 3.2.
39
+ - GUI-mode `gimp_shutdown(quit_gimp=True)` left GIMP running.
40
+
41
+ ## [0.1.0] - 2026-09-05
42
+
43
+ First release.
44
+
45
+ ### Added
46
+
47
+ - GIMP 3 bridge plug-in: loopback TCP, token-checked, GLib main-thread dispatch, persistent Python namespace.
48
+ - MCP server with 21 tools: session, images, render, PDB search/describe/call, GEGL filter search/describe/apply, `run_python`, recipes.
49
+ - Runtime introspection of PDB arguments and GEGL properties, with JSON coercion for images, items, item arrays, colours, files, enums and scalars.
50
+ - Recipes: `telegram_sticker`, `fit_and_export`.
51
+ - CLI: `serve`, `install-plugin`, `doctor`, `launch`, `smoke`.
52
+ - Live smoke test, GIMP-free unit tests, CI on Ubuntu and Windows.
@@ -0,0 +1,43 @@
1
+ # CLAUDE.md
2
+
3
+ Read `AGENTS.md` first; it is the contract for this repository.
4
+
5
+ ## Layout
6
+
7
+ - `src/gimp_agent_mcp/server.py`: FastMCP tools, prompts, resources. Thin; delegates to the bridge.
8
+ - `src/gimp_agent_mcp/bridge_client.py`: TCP client and GIMP process launcher.
9
+ - `src/gimp_agent_mcp/paths.py`: where GIMP and its config directory live per platform.
10
+ - `src/gimp_agent_mcp/plugin/gimp-agent-bridge.py`: the GIMP 3 plug-in. All libgimp/GEGL work is here.
11
+ - `src/gimp_agent_mcp/plugin/agent_bridge_core.py`: pure helpers shared by both sides.
12
+ - `src/gimp_agent_mcp/recipes/`: multi-step jobs as Python source executed inside GIMP.
13
+ - `src/gimp_agent_mcp/smoke.py`: the live end-to-end test.
14
+
15
+ ## Commands
16
+
17
+ ```bash
18
+ uv sync --extra dev
19
+ uv run ruff check .
20
+ uv run pytest # unit tests, no GIMP needed
21
+ uv run gimp-agent-mcp install-plugin # after editing the plug-in
22
+ uv run gimp-agent-mcp smoke # live test, needs GIMP 3
23
+ GIMP_AGENT_LIVE=1 uv run pytest tests/test_live.py
24
+ ```
25
+
26
+ After changing the plug-in you must reinstall it and restart any running bridge; GIMP loads plug-in code at start.
27
+
28
+ ## GIMP 3.2 API notes
29
+
30
+ - `Gimp.get_images()`, `image.get_layers()`, `image.get_selected_layers()`; no `gimpfu`.
31
+ - Colours are `Gegl.Color`; build with `Gegl.Color.new("black")` then `set_rgba(r, g, b, a)` in 0..1.
32
+ - Filters: `Gimp.DrawableFilter.new(drawable, "gegl:op", name)`, set properties on `get_config()`, then `drawable.merge_filter(f)` (destructive) or `drawable.append_filter(f)` (layer effect).
33
+ - PDB: `Gimp.get_pdb().lookup_procedure(name)`, `proc.create_config()`, `config.set_property(...)`, `proc.run(config)`; index 0 of the returned `ValueArray` is the status.
34
+ - Call `Gimp.displays_flush()` after edits so the GUI repaints.
35
+ - The per-user config directory is versioned (`3.0`, `3.2`, ...); plug-ins go in `<config>/plug-ins/<name>/<name>.py`.
36
+ - Windows plug-ins need the `#!/usr/bin/env python3` shebang so GIMP maps them to its bundled interpreter.
37
+ - Headless: `gimp-console -i --batch-interpreter=python-fu-eval -b "<python>"`; the batch code already has `Gimp` in scope.
38
+ - GIMP's Colors > Invert is `gegl:invert-gamma`; there is no `gegl:invert`.
39
+ - `Gimp.Path` is an `Item` but not a `Drawable`: no offsets, width or height. Guard `_item_info` accordingly.
40
+ - Enum classes are created lazily by PyGObject; resolve through the namespace, then `gi._gi.enum_add(gtype)` for GEGL's dynamic enums.
41
+ - Read pixels with `drawable.get_buffer().get(Gegl.Rectangle, scale, "R'G'B'A u8", Gegl.AbyssPolicy.CLAMP)`; write masks through `get_shadow_buffer` + `merge_shadow` + `update`.
42
+ - Export procedures are `file-<ext>-export`; JPEG quality is 0..1, WebP quality is 0..100, PNG has `compression`.
43
+ - If the plug-in process dies mid-session GIMP logs `gimp_wire_read(): unexpected EOF` and every later call fails to connect; check `gimp-agent-launch.log` in the config dir.
@@ -0,0 +1,9 @@
1
+ # Contributing
2
+
3
+ Run `uv run ruff check .` and `uv run pytest` before opening a pull request. Changes to the bridge protocol, coercion rules, or the tool surface need a unit test where one is possible, a `docs/ARCHITECTURE.md` update, and a run of `uv run gimp-agent-mcp smoke` on a machine with GIMP 3 noted in the PR.
4
+
5
+ Recipes are welcome. A recipe is a module in `src/gimp_agent_mcp/recipes/` with `DESCRIPTION`, `PARAMS` (every parameter has a description and either a default or `required: True`) and `SOURCE` that assigns `result`. Keep them deterministic and free of machine-specific paths. See `docs/RECIPES.md`.
6
+
7
+ Never add a network-exposed bind option, remove the token check, or add code copied from GPL-licensed projects. This repository is Apache-2.0 and stays clean-room.
8
+
9
+ Platform reports are valuable: if you run the smoke test on macOS or Linux, open an issue with the output even when it passes.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,167 @@
1
+ Metadata-Version: 2.5
2
+ Name: gimp-agent-mcp
3
+ Version: 0.2.0
4
+ Summary: Windows-first MCP server that gives AI agents the whole of GIMP 3: every PDB procedure, every GEGL filter, a render after each step, and repeatable recipes
5
+ Project-URL: Homepage, https://github.com/SarutobiSasuke8/gimp-agent-mcp
6
+ Project-URL: Repository, https://github.com/SarutobiSasuke8/gimp-agent-mcp
7
+ Project-URL: Issues, https://github.com/SarutobiSasuke8/gimp-agent-mcp/issues
8
+ Project-URL: Changelog, https://github.com/SarutobiSasuke8/gimp-agent-mcp/blob/main/CHANGELOG.md
9
+ Author: SarutobiSasuke8
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: ai-agents,claude,gegl,gimp,gimp-3,image-editing,mcp,model-context-protocol
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Operating System :: MacOS
18
+ Classifier: Operating System :: Microsoft :: Windows
19
+ Classifier: Operating System :: POSIX :: Linux
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Multimedia :: Graphics :: Editors :: Raster-Based
25
+ Requires-Python: >=3.11
26
+ Requires-Dist: mcp>=2.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=8; extra == 'dev'
29
+ Requires-Dist: ruff>=0.9; extra == 'dev'
30
+ Provides-Extra: segmentation
31
+ Requires-Dist: onnxruntime>=1.17; extra == 'segmentation'
32
+ Requires-Dist: pillow>=10; extra == 'segmentation'
33
+ Requires-Dist: rembg>=2.0.60; extra == 'segmentation'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # gimp-agent-mcp
37
+
38
+ An MCP server that hands AI agents the whole of GIMP 3, with the eyes and hands to do detailed work.
39
+
40
+ Claude, Codex, Cursor and any other Model Context Protocol client can open images, inspect layers, call every one of GIMP's ~1000 Procedure Database functions, apply every GEGL filter destructively or as a non-destructive layer effect, measure pixels instead of guessing, see before/after/diff renders, cut subjects out with an AI segmentation model, draw text and paths, and run tested multi-step recipes over whole folders. Windows-first; macOS and Linux paths are implemented.
41
+
42
+ ![Sticker recipe: source logo on the left, finished 512x512 Telegram sticker with stroke and shadow on the right](docs/hero.png)
43
+
44
+ ## Why this exists
45
+
46
+ GIMP 3 has a complete Python API through GObject Introspection. Earlier GIMP MCP servers wrapped a few dozen calls by hand, used Unix sockets that do not exist on Windows Python, and gave the agent no way to see or measure what it had just done. This server takes the opposite approach:
47
+
48
+ - **Generic, introspected access.** `gimp_pdb_search` -> `gimp_pdb_describe` -> `gimp_pdb_call` reaches any procedure with typed argument descriptions, enum choices and defaults pulled from GIMP at runtime. No hand-written wrapper goes stale when GIMP updates.
49
+ - **Every GEGL filter.** 200+ operations behind GIMP's Filters menu, with `mode="append"` for GIMP 3's non-destructive layer effects and `gimp_layer_effect` to edit them afterwards.
50
+ - **Sight and measurement.** `gimp_render` returns a PNG of the current state. `gimp_measure` reads the colour at a pixel, the bounding box of visible pixels, histograms and dominant colours. `gimp_snapshot` + `gimp_render_compare` show before, after and a pixel diff side by side.
51
+ - **Detailed work.** Selection in one tool (rect, ellipse, by colour, by alpha, from path, grow/shrink/feather), layer masks including raw mask pixels, text layers with fonts, vector paths that can be stroked, filled or turned into selections, and layer management.
52
+ - **AI cut-outs.** `gimp_remove_background` runs a segmentation model (rembg, optional extra) and writes the result as an editable layer mask or bakes it into alpha.
53
+ - **Recipes.** Repeatable jobs written once as Python that runs inside GIMP, with declared parameters, defaults and validation. Seven ship; `gimp_batch_recipe` runs one over a glob.
54
+ - **Windows-first transport.** TCP on `127.0.0.1` with a per-install token, because CPython on Windows has no `AF_UNIX`.
55
+ - **Escape hatch.** `gimp_run_python` executes Python inside GIMP with a persistent namespace. One environment variable disables it.
56
+
57
+ ## Requirements
58
+
59
+ - GIMP 3.0 or newer (tested on 3.2.4). GIMP 2.10 will not work: it has no Python 3 API.
60
+ - Python 3.11+ and [uv](https://docs.astral.sh/uv/) on the machine that runs the MCP client.
61
+
62
+ ## Quick start
63
+
64
+ ```bash
65
+ git clone https://github.com/SarutobiSasuke8/gimp-agent-mcp.git
66
+ cd gimp-agent-mcp
67
+ uv sync # add --extra segmentation for AI cut-outs
68
+ uv run gimp-agent-mcp install-plugin # copies the bridge plug-in into GIMP's plug-ins folder
69
+ uv run gimp-agent-mcp doctor # shows what was found
70
+ uv run gimp-agent-mcp smoke # launches headless GIMP and exercises every tool (22 checks with --segmentation)
71
+ ```
72
+
73
+ Then add the server to your MCP client. For Claude Code, from the repo directory:
74
+
75
+ ```bash
76
+ claude mcp add gimp -- uv run --directory "$(pwd)" gimp-agent-mcp serve
77
+ ```
78
+
79
+ Or in `.mcp.json` / `claude_desktop_config.json` (see `.mcp.json.example`):
80
+
81
+ ```json
82
+ {
83
+ "mcpServers": {
84
+ "gimp": {
85
+ "command": "uv",
86
+ "args": ["run", "--directory", "/absolute/path/to/gimp-agent-mcp", "gimp-agent-mcp", "serve"]
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ The agent calls `gimp_launch` to start GIMP with the bridge running (`mode="gui"` for the normal window, `mode="headless"` for batch work with no UI). If GIMP is already open, click **Filters > Development > Start Agent Bridge** instead. GIMP registers plug-ins at startup, so restart it once after `install-plugin`.
93
+
94
+ ## Tools (32)
95
+
96
+ | Area | Tools |
97
+ |---|---|
98
+ | Session | `gimp_status`, `gimp_launch`, `gimp_shutdown` |
99
+ | Images | `gimp_list_images`, `gimp_image_info`, `gimp_new_image`, `gimp_open`, `gimp_export` (with format options), `gimp_close_image` |
100
+ | Seeing | `gimp_render` (whole image, one layer, or a region), `gimp_snapshot`, `gimp_render_compare` (before / after / diff) |
101
+ | Measuring | `gimp_measure` (`color` at a point, `bbox` of visible pixels, `histogram`, `dominant` colours) |
102
+ | PDB | `gimp_pdb_search`, `gimp_pdb_describe`, `gimp_pdb_call` |
103
+ | Filters | `gimp_filter_search`, `gimp_filter_describe`, `gimp_apply_filter` (merge or append), `gimp_layer_effects`, `gimp_layer_effect` (edit or delete) |
104
+ | Detail work | `gimp_select`, `gimp_layer_mask`, `gimp_layer`, `gimp_text`, `gimp_list_fonts`, `gimp_path` |
105
+ | AI | `gimp_remove_background` (mask or apply; models u2net, isnet-general-use, u2net_human_seg, isnet-anime, silueta) |
106
+ | Code | `gimp_run_python` (disable with `GIMP_AGENT_ALLOW_PYTHON=0`) |
107
+ | Recipes | `gimp_list_recipes`, `gimp_run_recipe`, `gimp_batch_recipe` |
108
+
109
+ Argument conventions: images and items are integer ids; colours are `"#rrggbb"`, `"white"`, `"rgb(255,0,0)"` or `[r,g,b,a]`; enums are nicks like `"clip-to-image"` and unknown values return the valid list; dashes and underscores in names are interchangeable. `run-mode` defaults to non-interactive.
110
+
111
+ ## Recipes
112
+
113
+ | Recipe | Purpose |
114
+ |---|---|
115
+ | `telegram_sticker` | Fit artwork into a 512x512 transparent canvas, add a white outline and a soft shadow, export PNG. |
116
+ | `web_optimise` | Scale to a maximum edge and export WebP/JPEG/PNG, lowering quality until the file fits a KB budget. |
117
+ | `icon_set` | Export a square source at every size in a list (favicon, app icons, PWA icons). |
118
+ | `watermark` | Overlay a text or image watermark in a corner or centre with opacity. |
119
+ | `contact_sheet` | Thumbnails of every image in a folder on a labelled grid. |
120
+ | `sprite_sheet_slice` | Cut a sprite sheet into fixed-size tiles, skipping empty ones. |
121
+ | `fit_and_export` | Scale to a maximum edge length and export by extension. |
122
+
123
+ Recipes live in `src/gimp_agent_mcp/recipes/`. Each is a module with `DESCRIPTION`, `PARAMS` and `SOURCE`; see `docs/RECIPES.md` to add one.
124
+
125
+ ## A detailed-work session, end to end
126
+
127
+ ```text
128
+ gimp_open("photo.jpg") -> image 1, layer 2
129
+ gimp_snapshot(1) -> snapshot 3
130
+ gimp_remove_background(layer_id=2, mode="mask") -> editable mask, subject bbox
131
+ gimp_select(1, mode="alpha", layer_id=2); gimp_select(1, mode="shrink", amount=2)
132
+ gimp_layer(action="new", image_id=1, fill="#f4f1ea", position=1)
133
+ gimp_apply_filter(2, "gegl:dropshadow", {"x": 0, "y": 6, "radius": 12, "opacity": 0.35}, mode="append")
134
+ gimp_text(image_id=1, text="SUMMER SALE", size=96, font="Montserrat Bold", color="#111111", x=40, y=40)
135
+ gimp_measure("bbox", layer_id=2); gimp_measure("dominant", image_id=1)
136
+ gimp_render_compare(1, 3) -> before | after | diff
137
+ gimp_export(1, "out/hero.webp", {"quality": 82})
138
+ ```
139
+
140
+ ## How it works
141
+
142
+ ```text
143
+ MCP client --stdio--> gimp-agent-mcp (server.py) --TCP 127.0.0.1:9877 + token--> bridge plug-in inside GIMP 3
144
+ | |
145
+ rembg (optional) GLib main loop runs each request on the plug-in
146
+ main thread against libgimp / GEGL / the PDB
147
+ ```
148
+
149
+ The plug-in writes `agent-bridge.json` (port, token, pid) into GIMP's per-user config directory. The server reads it to connect. Details in `docs/ARCHITECTURE.md`.
150
+
151
+ ## Testing
152
+
153
+ - `uv run pytest`: unit tests, no GIMP needed.
154
+ - `uv run gimp-agent-mcp smoke`: 21 live checks against a headless GIMP. Add `--segmentation` to include the AI cut-out (downloads a small model on first use).
155
+ - CI runs lint and unit tests on Ubuntu and Windows, and a second workflow installs real GIMP 3 on a Windows runner and runs the live smoke test on every push.
156
+
157
+ ## Security
158
+
159
+ The bridge listens on loopback only and requires the token on every request. `gimp_run_python` and `gimp_pdb_call` are, by design, arbitrary code execution inside GIMP with the permissions of the user running it: give this server only to clients you trust with your files. Segmentation runs server-side and never sends pixels anywhere; the only network access in the project is rembg fetching its model once. See `SECURITY.md`.
160
+
161
+ ## Provenance
162
+
163
+ Clean-room implementation under Apache-2.0. The author read the existing GPL and MIT GIMP MCP projects for lessons about the GIMP 3.2 API and copied no code from them.
164
+
165
+ ## Status
166
+
167
+ `0.2.0`, beta. Verified end to end on Windows 11 with GIMP 3.2.4. macOS and Linux paths are implemented but not yet exercised on real machines; reports welcome. See `ROADMAP.md`.