Skip to main content

Model Context Protocol (MCP) server for Fiji/ImageJ: macros, discovery, screenshots, and workflows via PyImageJ

Project description

Fiji MCP Server

Python 3.10+ PyPI License: BSD-3-Clause CI

What is this? A small MCP server so assistants in Cursor, Claude Desktop, Claude Code, Gemini CLI, Windsurf, and similar apps can drive Fiji / ImageJ in plain language: open your images, run ImageJ macros, search commands, grab screenshots for proof, and chain steps into workflows—without you hand-writing boilerplate or clicking the same menus every time.

Under the hood it uses Model Context Protocol, PyImageJ, and FastMCP over stdio, so the same install works across MCP hosts.


See it running

Below are three reproducible demos on images shipped in this repo. Each row is one headless Fiji run: open a sample → process or measure → save a screenshot to demo_output/.

# In plain words What Fiji is doing
1 Soften a noisy image Gaussian blur (gentle denoising–style filter).
2 Find bright “blobs” and size them Threshold, separate touching objects, outline each object, then a tiny Area / circularity table (numbers only—no giant screenshot).
3 Turn shapes into stick figures and count branches Mask → SkeletonizeAnalyze Skeleton (2D/3D) metrics per tree.

Screenshots use paths relative to the repo (./demo_output/…). If images look missing locally, run:

FIJI_PATH=<your Fiji app folder> FIJI_MODE=headless python scripts/generate_readme_demo_assets.py

Where do names like img07.png come from?

They are just short filenames under demo_images/ used by the maintainer scripts—you do not need to memorize them. In chat you can say “open the sample fluorescence image in demo_images/ and point at any file there; the table above maps what you seewhich pipeline for this README only.

Gallery (same three ideas as the table)

1 · Softening filter
Before / after blur on a bundled 2D sample
Original sample image before filtering

Original

Same image after Gaussian blur

After Gaussian blur

2 · Objects and outlines
Threshold + particle overlay (headless-safe Java analyzer)
Fluorescence-style input

Input

Detected objects with outlines

Outlined objects

3 · Skeleton summary
Binary mask → skeleton → branch / junction style metrics
Input for skeleton demo

Input

Skeletonized mask

Skeleton (midline of shapes)

Numbers for demos 2 and 3

Small markdown tables (not images). Regenerate from Fiji with
FIJI_PATH=… FIJI_MODE=headless python scripts/generate_readme_demo_assets.py
(add UPDATE_README_TABLES=0 if you do not want this file edited).

Demo 2 — first few objects (area & roundness)

# Area Circ.
1 1052 0.89
2 2840 0.72
3 641 0.91
4 1902 0.68

Sample of the full table; numbers refresh when you run the asset script.

Demo 3 — skeleton trees (excerpt)

Tree # Branches # Junctions
1 14 6
2 9 7

First trees only; more rows exist in a full Fiji run.


Get started

Step What to do
1 · Install From PyPI: pip install fiji-mcp-server — or clone and run python3 scripts/install_fiji_mcp.py / ./install.sh for an editable dev tree. Needs Python 3.10+, a local Fiji folder (jars/ + plugins/), and Java for PyImageJ.
2 · Wire your app source .venv/bin/activate then fiji-mcp-install install cursor --fiji-path /path/to/Fiji (or claude-desktop, gemini, …). Restart the host app.
3 · Check In chat: “Run the Fiji MCP health_check tool.” Optional: FIJI_PATH=… FIJI_MODE=headless python scripts/demo_fiji_mcp_session.py

Full detail: docs/quickstart.md

Optional — terminal smoke + optional Fiji.app (macOS): python scripts/mcp_and_gui_fiji.py from the repo root (auto-picks Fiji and a demo image when it can). Flags and behavior: docs/quickstart.md — MCP + GUI.

Regenerate the gallery JPEGs and the two small tables:
FIJI_PATH=… FIJI_MODE=headless python scripts/generate_readme_demo_assets.py

Related projects: installer pattern inspired by napari-mcp · sibling cellpose_mcp · ssahu2@ucmerced.edu.

Configure your AI app

After install, run fiji-mcp-install install <target> --fiji-path <ABS> so the host launches python -m fiji_mcp with your Fiji path (same pattern as cellpose_mcp).

Application Command Notes
Cursor fiji-mcp-install install cursor --fiji-path <ABS> Writes ~/.cursor/mcp.json
Claude Desktop fiji-mcp-install install claude-desktop --fiji-path <ABS> Claude Desktop mcpServers
Claude Code (user) fiji-mcp-install install claude-code --fiji-path <ABS> Merges into ~/.claude.json
Claude Code (project) fiji-mcp-install install claude-code --fiji-path <ABS> --project <DIR> Creates or updates <DIR>/.mcp.json
Gemini CLI fiji-mcp-install install gemini --fiji-path <ABS> Merges into ~/.gemini/settings.json
Windsurf fiji-mcp-install install windsurf --fiji-path <ABS> ~/.codeium/windsurf/mcp_config.json

Options: --mode gui|headless|auto|smart (default headless for IDE/CLI stability); --command /path/to/fiji-mcp-server if the host app does not see your venv on PATH.

Manual configuration (any MCP host)

Use the Python that has fiji-mcp-server / fiji_mcp installed:

{
  "mcpServers": {
    "fiji": {
      "command": "/path/to/venv-or-conda/bin/python",
      "args": ["-m", "fiji_mcp"],
      "env": {
        "FIJI_PATH": "/Applications/Fiji",
        "FIJI_MODE": "headless",
        "PYTHONUNBUFFERED": "1"
      }
    }
  }
}

For Cursor, use the same object in ~/.cursor/mcp.json or project .cursor/mcp.json. Under stdio, do not use ImageJ print() in macros (stdout must stay JSON-clean).

After you configure, restart the host app, then try prompts like these (same spirit as cellpose_mcp):

"Run the Fiji MCP health_check tool."
"Search ImageJ commands matching 'Gaussian blur'."
"Open a PNG from ./demo_images/, apply Gaussian blur with sigma 4, and show me an active_image screenshot."

🎯 What Can You Do?

Basic macros and I/O

"Open ./demo_images/sample_gradient.pgm and report width and height."
"Run a macro that applies Gaussian blur then runs Measure."
"Save the active image to ./out/result.tif."

Discovery and screenshots

"List extensions loaded in this Fiji session."
"Search commands matching 'FFT'."
"Capture results_table after Measure on the current image."

Multi-step workflows

"Use run_workflow so each step runs a macro and optionally screenshots the active image after Gaussian blur."
"Open a sample from ./demo_images/, build a mask, skeletonize it, and summarize branch-style metrics."

Batch and reporting

"Run generate_image_analysis_report-style steps on all PNGs under ./demo_images/."

Use scripts/generate_image_analysis_report.py for a long stdio-MCP batch run; it writes research_output/ and a report under docs/ (both gitignored so your clone stays light). See Batch report workflow.

For a short stdio check (and optional Fiji.app on macOS), use scripts/mcp_and_gui_fiji.pyquickstart.

🛠 Available MCP Tools

The server exposes 19 tools for Fiji/ImageJ automation:

Macros and images

  • health_check — Verify Fiji / PyImageJ readiness
  • run_macro — Execute ImageJ macro text (with retries)
  • run_batch_macros — Run several macros with optional MCP progress
  • open_image / save_image — Path-aware I/O with optional FIJI_DATA_ROOTS allowlist

Screenshots

  • screenshot_fijifull_screen, active_image, or results_table

Discovery

  • list_all_commands / search_commands / describe_plugin
  • list_extensions / list_open_images / get_image_info

Workflows and session helpers

  • run_workflow — Async multi-step pipelines
  • parse_macro_output, compare_screenshots, list_macro_templates, get_macro_template
  • get_session_trace / clear_session_trace

📖 Documentation

Resource Description
Install & quick start Clone, venv, pip install, auto/manual MCP setup, verify
MCP Tools Full tool tables and parameters
Configuration Env vars, troubleshooting, Cursor plugin
Architecture Package layout and data flow
Batch report Stdio MCP batch report script

Local doc site: npx docsify serve docs then open the URL shown (same Docsify pattern as cellpose_mcp/docs).

Changelog & releases: CHANGELOG.md · RELEASING.md (PyPI / GitHub Releases) · RELEASE_NOTES_v0.1.1.md · CLAUDE.md · Pre-commit: .pre-commit-config.yaml (pip install -e ".[dev]" && pre-commit install)

📋 Architecture

  • FastMCP — stdio JSON-RPC to your AI client
  • PyImageJ / JPype — JVM bridge into Fiji/ImageJ2
  • Tool modulesmacro_runner, discovery, screenshot, workflow, structured_tools
  • Design — Headless-first for MCP; optional GUI + Robot for full_screen; stdio-safe macros (no print() to stdout)

Project status: Phases 1–4 complete; phase 5 (integration polish) in progress — see plan.md. CI: pytest -m "not integration" on Python 3.10–3.12.


Author: Suraj Sahu
Affiliation: Department of Physics, University of California Merced, CA, USA
Email: ssahu2@ucmerced.edu

📄 License

BSD-3-Clause — see LICENSE.

🙏 Acknowledgments


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

fiji_mcp_server-0.1.1.tar.gz (66.6 kB view details)

Uploaded Source

Built Distribution

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

fiji_mcp_server-0.1.1-py3-none-any.whl (47.5 kB view details)

Uploaded Python 3

File details

Details for the file fiji_mcp_server-0.1.1.tar.gz.

File metadata

  • Download URL: fiji_mcp_server-0.1.1.tar.gz
  • Upload date:
  • Size: 66.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fiji_mcp_server-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9484746919108951c06244612eaad9dfcdd5063a5f5b8eb6243037d207e6e846
MD5 c0feb5ace542c97220caaf48e3068398
BLAKE2b-256 62b9f05e7c296e15f79764b57e37e2902f782b17e18ab69395769a44dc37f8d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for fiji_mcp_server-0.1.1.tar.gz:

Publisher: publish-pypi.yml on surajinacademia/Fiji_imageJ_mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fiji_mcp_server-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fiji_mcp_server-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 47.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fiji_mcp_server-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cd3f63e68fdae777b1eab498ad9a48f903a9cdc4d147023c7046f9510cdfc6b4
MD5 a5bd3d3ddb98bb0a0b325d08afd8b22d
BLAKE2b-256 db1ea00e0b98bc099bb86e4f770cf9239d495627c5a3a300509f63a7febd1613

See more details on using hashes here.

Provenance

The following attestation bundles were made for fiji_mcp_server-0.1.1-py3-none-any.whl:

Publisher: publish-pypi.yml on surajinacademia/Fiji_imageJ_mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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