Working examples demonstrating how to use napari MCP server in custom Python scripts for workflow automation.
Description: Use OpenAI GPT-4 with napari MCP server for AI-controlled image analysis.
Use case: Automated workflows where GPT-4 decides which napari operations to perform.
Run:
# Set your API key
export OPENAI_API_KEY="your-key-here"
# Run with installed packages
python openai_integration.py
# Or with uv (zero-install)
uv run --with napari-mcp --with openai --with mcp python openai_integration.pyWhat it does:
- Connects OpenAI GPT-4 to napari MCP server
- Lists available napari tools
- Uses GPT-4 to generate code for creating test images
- Executes the code in napari environment
Description: Use Anthropic Claude with napari MCP server for intelligent microscopy analysis.
Use case: Automated workflows with Claude's advanced reasoning capabilities.
Run:
# Set your API key
export ANTHROPIC_API_KEY="your-key-here"
# Run with installed packages
python anthropic_integration.py
# Or with uv (zero-install)
uv run --with napari-mcp --with anthropic --with mcp python anthropic_integration.pyWhat it does:
- Connects Claude 3.5 Sonnet to napari MCP server
- Converts napari tools to Claude format
- Asks Claude to take a screenshot
- Executes napari tools based on Claude's decisions
Description: Direct napari MCP automation without external LLMs.
Use case: Scripted workflows, batch processing, automated testing.
Run:
# No API key needed!
python direct_mcp_client.py
# Or with uv
uv run --with napari-mcp --with mcp python direct_mcp_client.pyWhat it does:
- Creates synthetic test data in napari
- Lists all layers
- Takes a screenshot
- Gets session information
- All without any external AI - pure automation
Use these examples to build:
- Batch processing - Process hundreds of images automatically
- Quality control - Automated checks with AI assistance
- Data augmentation - Generate training data with napari
- Reporting - Automated analysis reports with screenshots
Apply to:
- Reproducible analysis - Script entire analysis pipelines
- Multi-modal AI - Combine vision models with napari control
- Interactive notebooks - Jupyter integration with AI assistance
- Custom tools - Build specialized analysis applications
Embed into:
- Web applications - Flask/FastAPI backends with napari
- Desktop applications - Qt apps with napari + AI
- Cloud pipelines - Serverless image processing
- CI/CD workflows - Automated testing with napari
- Choose your example based on your use case
- Install dependencies:
pip install napari-mcp openai anthropic mcp
- Set API keys (for OpenAI/Anthropic examples)
- Run the script and modify for your needs
- Python Integration Guide - Detailed explanation and advanced patterns
- API Reference - All available napari MCP tools
- Troubleshooting - Common issues
These examples are starting points - customize them for your specific workflows! 🔬✨