MCP server for remote control of napari viewers via Model Context Protocol
Project description
Napari MCP Server
MCP server for remote control of napari viewers via Model Context Protocol (MCP). Perfect for AI-assisted analysis with Claude Desktop.
🚀 Quick Start
Option 1: Install from PyPI (Recommended)
# Install the package
pip install napari-mcp
# Run the server
napari-mcp
Option 2: Install from GitHub (Latest)
# Install directly from GitHub
uv pip install git+https://github.com/royerlab/napari-mcp.git
# Run the server
napari-mcp
Option 3: Development Install
# Clone and install
git clone https://github.com/royerlab/napari-mcp.git
cd napari-mcp
uv pip install -e .
# Run the server
napari-mcp
Claude Desktop config (After Installation):
{
"mcpServers": {
"napari": {
"command": "napari-mcp"
}
}
}
Alternative config (GitHub install):
{
"mcpServers": {
"napari": {
"command": "uv",
"args": [
"run", "--with", "git+https://github.com/royerlab/napari-mcp.git",
"napari-mcp"
]
}
}
}
Why this approach?
- ✅ Zero Installation - No pip install, no virtual environments
- ✅ Single File - Easy to share, version, and deploy
- ✅ Auto Dependencies - uv handles all dependencies automatically
- ✅ Direct GitHub Execution - Run latest version directly from repo without downloading
- ✅ Always Up-to-Date - GitHub URL ensures you get the latest version
- ✅ Reproducible - Same dependencies every time
🤖 Multi-LLM Support
Works with multiple AI assistants and IDEs:
| Application | Status | Setup Method |
|---|---|---|
| Claude Desktop | ✅ Full Support | Manual config (recommended) |
| Claude Code | ✅ Full Support | fastmcp install claude-code |
| Cursor | ✅ Full Support | fastmcp install cursor |
| ChatGPT | 🟡 Limited | Remote deployment only |
→ See LLM_INTEGRATIONS.md for complete setup guides
🔧 Alternative Installation Methods
Traditional Package Installation
# Clone and install
git clone https://github.com/royerlab/napari-mcp.git
cd napari-mcp
pip install -e .
# Run
napari-mcp
Claude Desktop config for installed version:
{
"mcpServers": {
"napari": {
"command": "napari-mcp"
}
}
}
Development Installation
# With uv (recommended for development)
uv pip install -e ".[test,dev]"
# With pip
pip install -e ".[test,dev]"
Requirements:
- Python 3.10+
- napari 0.5.5+
- Qt Backend (PyQt6 installed automatically)
🛠 Available MCP Tools
Session Information
session_information()- Get comprehensive session info including viewer state, layers, system details
Layer Management
list_layers()- Get all layers and their propertiesadd_image(path, name?, colormap?, blending?, channel_axis?)- Add image layer from fileadd_labels(path, name?)- Add segmentation labels from fileadd_points(points, name?, size?)- Add point annotationsremove_layer(name)- Remove layer by nameset_layer_properties(...)- Modify layer visibility, opacity, colormap, etc.reorder_layer(name, index?|before?|after?)- Change layer orderset_active_layer(name)- Set selected layer
Viewer Controls
init_viewer(title?, width?, height?)- Create/configure viewer and start GUIclose_viewer()- Close viewer window (also stops GUI)reset_view()- Reset camera to fit all dataset_camera(center?, zoom?, angle?)- Position cameraset_ndisplay(2|3)- Switch between 2D/3D displayset_dims_current_step(axis, value)- Navigate dimensions (time, Z-stack)set_grid(enabled?)- Enable/disable grid view
Utilities
screenshot(canvas_only?)- Capture PNG image as base64execute_code(code)- Run Python with access to viewer, napari, numpyinstall_packages(packages, ...)- Install Python packages dynamically
⚠️ IMPORTANT SECURITY WARNING
This server includes powerful tools that allow arbitrary code execution:
execute_code()- Runs any Python code in the server environmentinstall_packages()- Installs any Python package via pip
Security Implications:
- ✅ Safe for local development with trusted AI assistants like Claude
- ❌ NEVER expose to untrusted networks or public internet
- ❌ Do not use in production environments without proper sandboxing
- ❌ Can access your filesystem, network, and install malware
Recommended Usage:
- Use only on
localhostconnections - Run in isolated virtual environments
- Only use with trusted AI assistants
📖 Usage Examples
Basic Layer Operations
Add and manipulate images:
Ask Claude: "Add a sample image to napari and set its colormap to 'viridis'"
Work with annotations:
Ask Claude: "Create some point annotations at coordinates [[100,100], [200,200]] and make them size 10"
Advanced Analysis
Execute custom code:
Ask Claude: "Execute this code to create a synthetic image:
import numpy as np
data = np.random.random((512, 512))
viewer.add_image(data, name='random_noise')"
Install packages on-demand:
Ask Claude: "Install scipy and create a Gaussian filtered version of the current image"
View Management
Control the camera:
Ask Claude: "Reset the view, then zoom to 2x and center on coordinates [256, 256]"
Switch display modes:
Ask Claude: "Switch to 3D display mode and take a screenshot"
🧪 Testing
# Run basic tests (fast, no GUI)
./run_tests.sh
# Run with real GUI tests (requires display)
./run_realgui_tests.sh
# Run with coverage
pytest --cov=src --cov-report=html tests/ -m "not realgui"
🤝 Contributing
- 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 your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development setup:
git clone https://github.com/royerlab/napari-mcp.git
cd napari-mcp
uv pip install -e ".[test,dev]"
pre-commit install
📋 Architecture
The server architecture consists of:
- 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
Key design decisions:
- Thread-safe: All napari operations are serialized through locks
- Non-blocking: Qt event loop runs asynchronously
- Stateful: Maintains viewer state across tool calls
- Extensible: Easy to add new tools and functionality
📚 Resources
- QUICKSTART.md - Get running in 2 minutes
- LLM_INTEGRATIONS.md - Complete guide for Claude Desktop, Claude Code, Cursor, ChatGPT
- Model Context Protocol - MCP specification
- FastMCP - Python MCP framework
- napari - Multi-dimensional image viewer
- Claude Desktop - AI assistant with MCP support
📄 License
MIT License - see LICENSE file for details.
🙏 Acknowledgments
- 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file napari_mcp-0.0.2.tar.gz.
File metadata
- Download URL: napari_mcp-0.0.2.tar.gz
- Upload date:
- Size: 315.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
027c40f31829ed98ec1393cee1ff0a6383af919aa7b7bcb6b75700465d99cf8d
|
|
| MD5 |
6a3d7b7401b093e23da5ba6c4a56e413
|
|
| BLAKE2b-256 |
12b28b1c1ee4526423efa9a2fad57651c6d5b07d63afcab48b8b8297352c3395
|
Provenance
The following attestation bundles were made for napari_mcp-0.0.2.tar.gz:
Publisher:
release.yml on royerlab/napari-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
napari_mcp-0.0.2.tar.gz -
Subject digest:
027c40f31829ed98ec1393cee1ff0a6383af919aa7b7bcb6b75700465d99cf8d - Sigstore transparency entry: 527005536
- Sigstore integration time:
-
Permalink:
royerlab/napari-mcp@66c64439497c6a8d9b7ab01755679d47788f5ab9 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/royerlab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@66c64439497c6a8d9b7ab01755679d47788f5ab9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file napari_mcp-0.0.2-py3-none-any.whl.
File metadata
- Download URL: napari_mcp-0.0.2-py3-none-any.whl
- Upload date:
- Size: 29.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2235af037bb1f7ccd25424c3886f75a801308c51153ec2e7e97b9f50765b8a58
|
|
| MD5 |
e650b28e1246abe7b2567a7a743c9fee
|
|
| BLAKE2b-256 |
917b915ef88bc5cd73434ed23765ca6d243f995e236380729e1fc7db681337a7
|
Provenance
The following attestation bundles were made for napari_mcp-0.0.2-py3-none-any.whl:
Publisher:
release.yml on royerlab/napari-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
napari_mcp-0.0.2-py3-none-any.whl -
Subject digest:
2235af037bb1f7ccd25424c3886f75a801308c51153ec2e7e97b9f50765b8a58 - Sigstore transparency entry: 527005579
- Sigstore integration time:
-
Permalink:
royerlab/napari-mcp@66c64439497c6a8d9b7ab01755679d47788f5ab9 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/royerlab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@66c64439497c6a8d9b7ab01755679d47788f5ab9 -
Trigger Event:
push
-
Statement type: