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.
napari-mcp-simple-demo.mp4
pip install napari-mcp
# For Claude Desktop
napari-mcp-install claude-desktop
# For other applications (Claude Code, Cursor, Cline, etc.)
napari-mcp-install --help # See all options
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
napari-mcp can also be used as a napari plugin for direct integration with a running napari session:
- Start napari normally:
napari
- Open the widget: Plugins β napari-mcp: MCP Server Control
- Click "Start Server" to expose your current session to AI assistants
- 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
"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"
"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"
"Switch to 3D display mode"
"Navigate to time point 5, Z-slice 10"
"Create a rotating animation of this volume"
Want to automate image processing with Python scripts? Use any LLM (OpenAI, Anthropic, etc.) with napari MCP:
β See Python Integration Examples for batch processing and workflow automation
Application | Command | Status |
---|---|---|
Claude Desktop | napari-mcp-install claude-desktop |
β Full Support |
Claude Code | napari-mcp-install claude-code |
β Full Support |
Cursor IDE | napari-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 CLI | napari-mcp-install gemini |
β Full Support |
Codex CLI | napari-mcp-install codex |
β Full Support |
β See Integration Guides for application-specific instructions
The server exposes 20+ tools for complete napari control:
- 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 API Reference for complete documentation
!!! 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.
- Quick Start Guide - Get running in 3 minutes
- Installation Options - Advanced installation methods
- Integration Guides - Setup for specific AI applications
- Python Examples - Automate workflows with custom scripts
- Troubleshooting - Common issues and solutions
- API Reference - Complete tool documentation
# 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
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes with tests
- Run pre-commit hooks:
pre-commit run --all-files
- Commit changes (
git commit -m 'Add amazing feature'
) - Push to branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- 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
- napari - Multi-dimensional image viewer
- Model Context Protocol - MCP specification
- FastMCP - Python MCP framework
- Claude Desktop - AI assistant with MCP support
BSD-3-Clause License - see LICENSE file for details.
- napari team for the excellent imaging platform
- FastMCP for the MCP framework
- Anthropic for Claude and MCP development
- astral-sh for uv dependency management
Built with β€οΈ for the microscopy and AI communities