Go to file
Adolfo Delorenzo e27251b922 feat: add three new Portainer MCP servers
- Add portainer-environments server for environment/endpoint management
- Add portainer-docker server for Docker and Swarm container operations
- Add merged portainer server combining core + teams functionality
- Fix JSON schema issues and API compatibility
- Add comprehensive documentation for each server
- Add .gitignore and .env.example for security

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-18 13:00:05 -03:00
bin Simplify authentication to require URL and API key only 2025-07-18 07:48:23 -06:00
scripts Simplify authentication to require URL and API key only 2025-07-18 07:48:23 -06:00
src feat: add three new Portainer MCP servers 2025-07-18 13:00:05 -03:00
tests feat: add three new Portainer MCP servers 2025-07-18 13:00:05 -03:00
.env.example feat: add three new Portainer MCP servers 2025-07-18 13:00:05 -03:00
.gitignore feat: add three new Portainer MCP servers 2025-07-18 13:00:05 -03:00
CLAUDE.md first commit 2025-07-18 07:33:27 -06:00
merged_mcp_server.py feat: add three new Portainer MCP servers 2025-07-18 13:00:05 -03:00
package.json Simplify authentication to require URL and API key only 2025-07-18 07:48:23 -06:00
portainer_docker_server.py feat: add three new Portainer MCP servers 2025-07-18 13:00:05 -03:00
portainer_environments_server.py feat: add three new Portainer MCP servers 2025-07-18 13:00:05 -03:00
pyproject.toml Fix BaseService constructor inheritance and MCP server initialization 2025-07-18 08:15:46 -06:00
README_DOCKER.md feat: add three new Portainer MCP servers 2025-07-18 13:00:05 -03:00
README_ENVIRONMENTS.md feat: add three new Portainer MCP servers 2025-07-18 13:00:05 -03:00
README_MERGED.md feat: add three new Portainer MCP servers 2025-07-18 13:00:05 -03:00
README.md Simplify authentication to require URL and API key only 2025-07-18 07:48:23 -06:00
requirements.txt feat: add three new Portainer MCP servers 2025-07-18 13:00:05 -03:00
run_mcp.py feat: add three new Portainer MCP servers 2025-07-18 13:00:05 -03:00
run_server.py Simplify authentication to require URL and API key only 2025-07-18 07:48:23 -06:00
simple_mcp_server.py feat: add three new Portainer MCP servers 2025-07-18 13:00:05 -03:00
test_uvx.py Simplify authentication to require URL and API key only 2025-07-18 07:48:23 -06:00
USAGE.md Simplify authentication to require URL and API key only 2025-07-18 07:48:23 -06:00

Portainer Core MCP Server

A Model Context Protocol (MCP) server that provides authentication and user management functionality for Portainer Business Edition.

Features

  • Authentication: JWT token-based authentication with Portainer API
  • User Management: Complete CRUD operations for users
  • Settings Management: Portainer instance configuration
  • Health Monitoring: Server and service health checks
  • Fault Tolerance: Circuit breaker pattern with automatic recovery
  • Structured Logging: JSON-formatted logs with correlation IDs

Requirements

  • Python 3.8+
  • Portainer Business Edition instance
  • Valid Portainer API key

Installation

Using pip

pip install -e .
uv pip install -e .

Using uvx (run without installing)

# No installation needed - runs directly
uvx --from . portainer-core-mcp

Using npm/npx

npm install -g portainer-core-mcp

Configuration

Environment Variables

Create a .env file or set environment variables:

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

# Optional
HTTP_TIMEOUT=30
MAX_RETRIES=3
LOG_LEVEL=INFO
DEBUG=false

Generate API Key

  1. Log in to your Portainer instance
  2. Go to User Settings > API Tokens
  3. Click Add API Token
  4. Copy the generated token

Usage

Start the Server

Using Python

python run_server.py

Using uv

uv run python run_server.py

Using uvx

uvx --from . portainer-core-mcp

Using npm/npx

npx portainer-core-mcp

Environment Setup

# Copy example environment file
cp .env.example .env

# Edit configuration
nano .env

# Start server (choose your preferred method)
python run_server.py
# OR
uvx --from . portainer-core-mcp

Available Tools

The MCP server provides the following tools:

Authentication

  • authenticate - Login with username/password
  • generate_token - Generate API tokens
  • get_current_user - Get current user info

User Management

  • list_users - List all users
  • create_user - Create new user
  • update_user - Update user details
  • delete_user - Delete user

Settings

  • get_settings - Get Portainer settings
  • update_settings - Update configuration

Health

  • health_check - Server health status

Available Resources

  • portainer://users - User management data
  • portainer://settings - Configuration settings
  • portainer://health - Server health status

Development

Setup

# Clone the repository
git clone https://github.com/yourusername/portainer-core-mcp.git
cd portainer-core-mcp

# Install development dependencies
pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install

Testing

# Run all tests
pytest

# Run with coverage
pytest --cov=src/portainer_core --cov-report=html

# Run only unit tests
pytest -m unit

# Run only integration tests
pytest -m integration

Code Quality

# Format code
black src tests
isort src tests

# Lint code
flake8 src tests

# Type checking
mypy src

Architecture

The server follows a layered architecture:

  • MCP Server Layer: Handles MCP protocol communication
  • Service Layer: Abstracts Portainer API interactions
  • Models Layer: Defines data structures and validation
  • Utils Layer: Provides utility functions and helpers

Security

  • All API communications use HTTPS
  • JWT tokens are handled securely and never logged
  • Input validation on all parameters
  • Rate limiting to prevent abuse
  • Circuit breaker pattern for fault tolerance

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

License

MIT License - see LICENSE file for details.