Metadata-Version: 2.4
Name: napari-mcp
Version: 0.0.4
Summary: MCP server for remote control of napari viewers via Model Context Protocol
Author-email: Ilan Theodoro <ilan.silva@czbiohub.org>
Maintainer-email: Ilan Theodoro <ilan.silva@czbiohub.org>
License: MIT
Project-URL: Homepage, https://github.com/royerlab/napari-mcp
Project-URL: Repository, https://github.com/royerlab/napari-mcp
Project-URL: Documentation, https://github.com/royerlab/napari-mcp#readme
Project-URL: Bug Tracker, https://github.com/royerlab/napari-mcp/issues
Project-URL: Changelog, https://github.com/royerlab/napari-mcp/blob/main/CHANGELOG.md
Keywords: napari,mcp,microscopy,image-analysis,ai,claude
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: napari
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Image Processing
Classifier: Topic :: Scientific/Engineering :: Visualization
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastmcp>=2.10.3
Requires-Dist: napari>=0.5.5
Requires-Dist: pyqt6>=6.5.0
Requires-Dist: qtpy>=2.4.1
Requires-Dist: Pillow>=10.3.0
Requires-Dist: imageio>=2.34.0
Requires-Dist: numpy>=1.26.0
Requires-Dist: typer>=0.9.0
Requires-Dist: rich>=13.0.0
Requires-Dist: toml>=0.10.2
Provides-Extra: test
Requires-Dist: pytest>=8.4.0; extra == "test"
Requires-Dist: pytest-asyncio>=0.23.0; extra == "test"
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
Requires-Dist: pytest-qt>=4.0.0; extra == "test"
Requires-Dist: pytest-xdist>=3.5.0; extra == "test"
Requires-Dist: pytest-timeout>=2.2.0; extra == "test"
Requires-Dist: pytest-benchmark>=4.0.0; extra == "test"
Requires-Dist: pytest-mock>=3.12.0; extra == "test"
Requires-Dist: pytest-random-order>=1.1.0; extra == "test"
Requires-Dist: pytest-forked>=1.6.0; extra == "test"
Requires-Dist: hypothesis>=6.100.0; extra == "test"
Requires-Dist: napari[pyqt6,testing]; extra == "test"
Requires-Dist: tox; extra == "test"
Provides-Extra: dev
Requires-Dist: ruff>=0.12.10; extra == "dev"
Requires-Dist: mypy>=1.17.0; extra == "dev"
Requires-Dist: types-toml>=0.10.8.20240310; extra == "dev"
Requires-Dist: types-Pillow>=10.0.0; extra == "dev"
Requires-Dist: pre-commit>=4.3.0; extra == "dev"
Requires-Dist: bandit>=1.8.6; extra == "dev"
Requires-Dist: black>=24.0.0; extra == "dev"
Provides-Extra: all
Requires-Dist: napari-mcp[dev,test]; extra == "all"
Dynamic: license-file

# Napari MCP Server

[![Tests](https://github.com/royerlab/napari-mcp/workflows/Tests/badge.svg)](https://github.com/royerlab/napari-mcp/actions)
[![codecov](https://codecov.io/gh/royerlab/napari-mcp/graph/badge.svg?token=E1WY58V877)](https://codecov.io/gh/royerlab/napari-mcp)
[![PyPI version](https://badge.fury.io/py/napari-mcp.svg)](https://badge.fury.io/py/napari-mcp)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

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.

## 🚀 Quick Start (3 Steps)

### 1. Install the Package

```bash
pip install napari-mcp
```

### 2. Auto-Configure Your AI Application

```bash
# 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](https://napari-mcp.readthedocs.io) for detailed guides**

## 🎯 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 [Python Integration Examples](docs/examples/README.md)** for batch processing and workflow automation

## 🤖 Supported AI Applications

| 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](docs/integrations/index.md) 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 [API Reference](docs/api/index.md) 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

- **[Quick Start Guide](docs/getting-started/quickstart.md)** - Get running in 3 minutes
- **[Installation Options](docs/getting-started/installation.md)** - Advanced installation methods
- **[Integration Guides](docs/integrations/index.md)** - Setup for specific AI applications
- **[Python Examples](docs/examples/README.md)** - Automate workflows with custom scripts
- **[Troubleshooting](docs/guides/troubleshooting.md)** - Common issues and solutions
- **[API Reference](docs/api/index.md)** - Complete tool documentation

## 🧪 Development Setup

```bash
# 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

- **[napari](https://napari.org/)** - Multi-dimensional image viewer
- **[Model Context Protocol](https://modelcontextprotocol.io/)** - MCP specification
- **[FastMCP](https://github.com/jlowin/fastmcp)** - Python MCP framework
- **[Claude Desktop](https://claude.ai/download)** - AI assistant with MCP support

## 📄 License

MIT License - see [LICENSE](LICENSE) file for details.

## 🙏 Acknowledgments

- [napari team](https://napari.org/) for the excellent imaging platform
- [FastMCP](https://github.com/jlowin/fastmcp) for the MCP framework
- [Anthropic](https://www.anthropic.com/) for Claude and MCP development
- [astral-sh](https://astral.sh/) for uv dependency management

---

**Built with ❤️ for the microscopy and AI communities**
