Go to file
Adolfo Delorenzo 10dfd606c0 feat: streamline Docker deployment with registry images and unified env configuration
- Update docker-compose.yml to use pre-built images from GitLab registry
- Replace individual environment variables with unified env_file directive
- Create comprehensive .env.example with detailed instructions and troubleshooting
- Add push-to-registry.sh script for building and pushing images to registry
- Add docker-compose.prod.yml as reference for production deployments
- Update documentation to reflect simplified deployment process

Users can now deploy with just:
  cp .env.example .env
  docker-compose pull
  docker-compose up -d

All 7 MCP server images are available at:
  git.oe74.net/adelorenzo/portainer-mcp/portainer-*:latest

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-21 15:16:15 -03:00
bin Simplify authentication to require URL and API key only 2025-07-18 07:48:23 -06:00
docker feat: add Docker support for all MCP servers 2025-07-21 00:12:39 -03:00
scripts Simplify authentication to require URL and API key only 2025-07-18 07:48:23 -06:00
src/portainer_core refactor: clean up codebase and rename core server 2025-07-19 00:43:23 -03:00
tests feat: add three new Portainer MCP servers 2025-07-18 13:00:05 -03:00
.env.example feat: streamline Docker deployment with registry images and unified env configuration 2025-07-21 15:16:15 -03:00
.gitignore feat: add three new Portainer MCP servers 2025-07-18 13:00:05 -03:00
build-docker.sh feat: add Docker support for all MCP servers 2025-07-21 00:12:39 -03:00
CLAUDE.md first commit 2025-07-18 07:33:27 -06:00
docker-compose.prod.yml feat: streamline Docker deployment with registry images and unified env configuration 2025-07-21 15:16:15 -03:00
docker-compose.yml feat: streamline Docker deployment with registry images and unified env configuration 2025-07-21 15:16:15 -03:00
DOCKER.md feat: streamline Docker deployment with registry images and unified env configuration 2025-07-21 15:16:15 -03:00
Dockerfile.base feat: add Docker support for all MCP servers 2025-07-21 00:12:39 -03:00
package.json Simplify authentication to require URL and API key only 2025-07-18 07:48:23 -06:00
portainer_core_server.py refactor: clean up codebase and rename core server 2025-07-19 00:43:23 -03:00
portainer_docker_server.py refactor: clean up codebase and rename core server 2025-07-19 00:43:23 -03:00
portainer_edge_server.py refactor: clean up codebase and rename core server 2025-07-19 00:43:23 -03:00
portainer_environments_server.py refactor: clean up codebase and rename core server 2025-07-19 00:43:23 -03:00
portainer_gitops_server.py refactor: clean up codebase and rename core server 2025-07-19 00:43:23 -03:00
portainer_kubernetes_server.py refactor: clean up codebase and rename core server 2025-07-19 00:43:23 -03:00
portainer_stacks_server.py refactor: clean up codebase and rename core server 2025-07-19 00:43:23 -03:00
push-to-registry.sh feat: streamline Docker deployment with registry images and unified env configuration 2025-07-21 15:16:15 -03:00
pyproject.toml Fix BaseService constructor inheritance and MCP server initialization 2025-07-18 08:15:46 -06:00
README_CORE.md docs: add references to individual server documentation files 2025-07-19 01:05:33 -03:00
README_DOCKER.md docs: add references to individual server documentation files 2025-07-19 01:05:33 -03:00
README_EDGE.md docs: add references to individual server documentation files 2025-07-19 01:05:33 -03:00
README_ENVIRONMENTS.md docs: add references to individual server documentation files 2025-07-19 01:05:33 -03:00
README_GITOPS.md docs: add references to individual server documentation files 2025-07-19 01:05:33 -03:00
README_KUBERNETES.md docs: add references to individual server documentation files 2025-07-19 01:05:33 -03:00
README_STACKS.md docs: add references to individual server documentation files 2025-07-19 01:05:33 -03:00
README.md feat: streamline Docker deployment with registry images and unified env configuration 2025-07-21 15:16:15 -03:00
requirements.txt Fix: Add aiohttp to requirements.txt for stacks server 2025-07-18 19:50:47 -03:00
run_server.py refactor: clean up codebase and rename core server 2025-07-19 00:43:23 -03:00
USAGE.md Simplify authentication to require URL and API key only 2025-07-18 07:48:23 -06:00

Portainer MCP Server Suite

A comprehensive collection of Model Context Protocol (MCP) servers for managing Portainer Business Edition through natural language interfaces. This suite provides modular servers for different aspects of Portainer management, from user authentication to container orchestration.

Quick Start

# Clone and setup
git clone https://github.com/yourusername/portainer-mcp.git
cd portainer-mcp

# Docker deployment (recommended)
cp .env.example .env
# Edit .env with your Portainer URL and API key
docker-compose pull
docker-compose up -d

# Or Python local installation
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python portainer_core_server.py

Overview

The Portainer MCP Server Suite consists of specialized servers that work together to provide complete Portainer management capabilities:

Features

Core Server (User & Access Management)

  • User authentication and session management
  • User CRUD operations with role assignments
  • Teams creation and membership management
  • Role-based access control (RBAC) configuration
  • Resource access controls for fine-grained permissions
  • System settings management

Environments Server

  • List and manage Docker/Kubernetes environments
  • Create and configure endpoints
  • Environment-specific settings
  • Connection status monitoring

Docker Server

  • Container lifecycle management (26 tools)
  • Image management and registry operations
  • Volume and network management
  • Docker Compose deployments
  • Container logs and stats

Kubernetes Server

  • Cluster and namespace management (28 tools)
  • Deployment and service operations
  • ConfigMap and Secret management
  • Pod operations and troubleshooting
  • Ingress configuration

Stacks Server

  • Deploy stacks from templates or custom compose files
  • Manage stack lifecycle
  • Update stack configurations
  • Environment variable management
  • Stack migration between environments

Edge Server

  • Edge device registration and management
  • Edge group operations
  • Edge stack deployments
  • Device monitoring and status
  • Edge compute job scheduling

GitOps Server

  • Automated deployments from Git repositories
  • Webhook and polling-based updates
  • Multi-environment deployments
  • Stack synchronization
  • GitOps configuration management

Requirements

  • Python 3.8+
  • Portainer Business Edition 2.19.0+
  • Valid Portainer API key
  • MCP-compatible client (e.g., Claude Desktop)

Installation

Option 1: Local Python Installation

  1. Clone the repository:
git clone https://github.com/yourusername/portainer-mcp.git
cd portainer-mcp
  1. Create a virtual environment:
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
# or manually: pip install mcp httpx aiohttp
  1. Clone the repository:
git clone https://github.com/yourusername/portainer-mcp.git
cd portainer-mcp
  1. Configure environment and run:
cp .env.example .env
# Edit .env with your Portainer credentials
nano .env  # or use your preferred editor

# Pull pre-built images from registry
docker-compose pull
docker-compose up -d

See the Docker Deployment Guide for detailed instructions.

Configuration

Environment Variables

Set these environment variables or create a .env file:

# Required
PORTAINER_URL=https://your-portainer-instance.com
PORTAINER_API_KEY=your-api-key-here

# Optional
PORTAINER_INSECURE=false  # Set to true for self-signed certificates
HTTP_TIMEOUT=30
MAX_RETRIES=3

Generate API Key

  1. Log in to your Portainer instance
  2. Navigate to My AccountAccess Tokens
  3. Click Add access token
  4. Copy the generated token

Claude Desktop Configuration

Add the servers to your Claude Desktop configuration (claude_desktop_config.json):

{
  "mcpServers": {
    "portainer-core": {
      "command": "/path/to/.venv/bin/python",
      "args": ["/path/to/portainer_core_server.py"],
      "env": {
        "PORTAINER_URL": "https://your-portainer-instance.com",
        "PORTAINER_API_KEY": "your-api-key"
      }
    },
    "portainer-docker": {
      "command": "/path/to/.venv/bin/python",
      "args": ["/path/to/portainer_docker_server.py"],
      "env": {
        "PORTAINER_URL": "https://your-portainer-instance.com",
        "PORTAINER_API_KEY": "your-api-key"
      }
    },
    "portainer-kubernetes": {
      "command": "/path/to/.venv/bin/python",
      "args": ["/path/to/portainer_kubernetes_server.py"],
      "env": {
        "PORTAINER_URL": "https://your-portainer-instance.com",
        "PORTAINER_API_KEY": "your-api-key"
      }
    },
    "portainer-gitops": {
      "command": "/path/to/.venv/bin/python",
      "args": ["/path/to/portainer_gitops_server.py"],
      "env": {
        "PORTAINER_URL": "https://your-portainer-instance.com",
        "PORTAINER_API_KEY": "your-api-key"
      }
    }
  }
}

Usage Examples

User Management (Core Server)

"Create a new user named 'developer' with StandardUser role"
"List all teams and their members"
"Add user ID 5 to the DevOps team"
"Update security settings to allow volume browsing"

Docker Operations (Docker Server)

"List all running containers in the production environment"
"Start the nginx container"
"Show logs for the app container from the last hour"
"Create a volume named 'data-volume' with local driver"

Kubernetes Management (Kubernetes Server)

"List all deployments in the default namespace"
"Scale the web-app deployment to 3 replicas"
"Create a ConfigMap named 'app-config' with the provided data"
"Get pods in the production namespace"

GitOps Automation (GitOps Server)

"Create a GitOps config for the nginx stack from my GitHub repo"
"Update all stacks from their Git repositories"
"Show GitOps configurations for environment ID 2"
"Force update the production stack from Git"

Architecture

Each server follows a similar architecture:

  • Async HTTP client for Portainer API communication
  • MCP protocol implementation for tool exposure
  • Error handling with descriptive messages
  • Environment-based configuration
  • Modular tool organization

Security Considerations

  • Always use HTTPS in production environments
  • Rotate API tokens regularly
  • Use environment-specific API keys with minimal required permissions
  • Enable RBAC to restrict user access appropriately
  • Monitor API usage and audit logs

Troubleshooting

Connection Issues

  • Verify Portainer URL is accessible
  • Check API key validity
  • Ensure proper network connectivity
  • For self-signed certificates, set PORTAINER_INSECURE=true

Permission Errors

  • Verify API key has required permissions
  • Check RBAC settings for the user
  • Ensure resource access controls allow the operation

Server Errors

  • Check Portainer logs for detailed error messages
  • Verify Portainer version compatibility
  • Enable debug logging with DEBUG=true

Development

Adding New Tools

  1. Add tool definition in handle_list_tools()
  2. Implement tool logic in handle_call_tool()
  3. Test with various inputs and edge cases
  4. Update documentation

Testing

Currently, manual testing is recommended:

  1. Start the server
  2. Use an MCP client to invoke tools
  3. Verify responses match expected behavior
  4. Test error conditions

Documentation

Each server has its own detailed documentation:

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-tool)
  3. Commit your changes (git commit -am 'Add new tool')
  4. Push to the branch (git push origin feature/new-tool)
  5. Create a Pull Request

License

MIT License - see LICENSE file for details.

Support