napari-mcp

royerlab/napari-mcp

3.4

If you are the rightful owner of napari-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The Napari MCP Server enables remote control of napari viewers using the Model Context Protocol (MCP), facilitating AI-assisted microscopy analysis.

Tools
4
Resources
0
Prompts
0

Napari MCP Server

Tests codecov PyPI version Python 3.10+ License: BSD-3-Clause

MCP server for remote control of napari viewers via Model Context Protocol (MCP). Perfect for AI-assisted microscopy analysis with Claude Desktop and other LLM applications.

https://github.com/user-attachments/assets/d261674c-9875-4671-8c60-a7f49d6f1b84

๐Ÿš€ Quick Start (3 Steps)

1. Install the Package

pip install napari-mcp

2. Auto-Configure Your AI Application

# For Claude Desktop
napari-mcp-install claude-desktop

# For other applications (Claude Code, Cursor, Cline, etc.)
napari-mcp-install --help  # See all options

3. Restart Your Application & Start Using

Restart your AI app and you're ready! Try asking:

"Can you call session_information() to show my napari session details?"

โ†’ See Full Documentation for detailed guides

๐Ÿ”Œ Using as a napari Plugin

napari-mcp can also be used as a napari plugin for direct integration with a running napari session:

  1. Start napari normally: napari
  2. Open the widget: Plugins โ†’ napari-mcp: MCP Server Control
  3. Click "Start Server" to expose your current session to AI assistants
  4. Connect your AI app using the standard installer: napari-mcp-install <app>

This mode enables AI assistants to control your current napari session rather than starting a new viewer. Perfect for integrating with existing workflows!

โ†’ See Plugin Guide for detailed instructions

๐ŸŽฏ What Can You Do?

Basic Image Analysis

"Load the image from ./data/sample.tif and apply a viridis colormap"
"Create point annotations at coordinates [[100,100], [200,200]]"
"Take a screenshot and save it"

Advanced Workflows

"Execute this code to create a filtered version:
from scipy import ndimage
filtered = ndimage.gaussian_filter(viewer.layers[0].data, sigma=2)
viewer.add_image(filtered, name='filtered')"

"Install scikit-image and segment the cells in this microscopy image"

3D/4D Navigation

"Switch to 3D display mode"
"Navigate to time point 5, Z-slice 10"
"Create a rotating animation of this volume"

Automated Workflows

Want to automate image processing with Python scripts? Use any LLM (OpenAI, Anthropic, etc.) with napari MCP:

โ†’ See for batch processing and workflow automation

๐Ÿค– Supported AI Applications

ApplicationCommandStatus
Claude Desktopnapari-mcp-install claude-desktopโœ… Full Support
Claude Codenapari-mcp-install claude-codeโœ… Full Support
Cursor IDEnapari-mcp-install cursorโœ… Full Support
Cline (VS Code)napari-mcp-install cline-vscodeโœ… Full Support
Cline (Cursor)napari-mcp-install cline-cursorโœ… Full Support
Gemini CLInapari-mcp-install geminiโœ… Full Support
Codex CLInapari-mcp-install codexโœ… Full Support

โ†’ See for application-specific instructions

๐Ÿ›  Available MCP Tools

The server exposes 20+ tools for complete napari control:

Core Functions

  • Session Management: detect_viewers, init_viewer, close_viewer, session_information
  • Layer Operations: add_image, add_labels, add_points, list_layers, remove_layer
  • Viewer Controls: set_camera, reset_view, set_ndisplay, set_dims_current_step
  • Utilities: screenshot, execute_code, install_packages

โ†’ See for complete documentation

โš ๏ธ Security Notice

!!! warning "Code Execution Capabilities" This server includes powerful tools that allow arbitrary code execution:

- **`execute_code()`** - Runs Python code in the server environment
- **`install_packages()`** - Installs packages via pip

**Use only with trusted AI assistants on local networks.**
Never expose to public internet without proper sandboxing.

๐Ÿ“– Documentation

  • - Get running in 3 minutes
  • - Advanced installation methods
  • - Setup for specific AI applications
  • - Automate workflows with custom scripts
  • - Common issues and solutions
  • - Complete tool documentation

๐Ÿงช Development Setup


# Clone repository
git clone https://github.com/royerlab/napari-mcp.git
cd napari-mcp

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

# Run tests
pytest -m "not realgui"  # Skip GUI tests
pytest --cov=src --cov-report=html  # With coverage

๐Ÿค Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes with tests
  4. Run pre-commit hooks: pre-commit run --all-files
  5. Commit changes (git commit -m 'Add amazing feature')
  6. Push to branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

๐Ÿ“‹ Architecture

  • FastMCP Server: Handles MCP protocol communication
  • Napari Integration: Manages viewer lifecycle and operations
  • Qt Event Loop: Asynchronous GUI event processing
  • Tool Layer: Exposes napari functionality as MCP tools
  • External Bridge: Optional connection to existing napari viewers

Key features:

  • Thread-safe: All napari operations are serialized
  • Non-blocking: Qt event loop runs asynchronously
  • Stateful: Maintains viewer state across tool calls
  • Extensible: Easy to add new tools

๐Ÿ“š Resources

๐Ÿ“„ License

BSD-3-Clause License - see file for details.

๐Ÿ™ Acknowledgments


Built with โค๏ธ for the microscopy and AI communities