- Implement portainer-kubernetes server with 30 tools for comprehensive K8s management - Namespace, pod, deployment, and service operations - ConfigMap and Secret management with base64 encoding - Storage operations (PV/PVC) - Ingress configuration - Node information and pod logs - Implement portainer-stacks server with 13 tools for stack management - Docker Compose and Kubernetes manifest support - Git repository integration for stack deployments - Stack lifecycle management (create, update, start, stop, delete) - Environment variable management - Stack migration between environments - Add comprehensive README documentation for both servers - Make server files executable |
||
---|---|---|
bin | ||
scripts | ||
src | ||
tests | ||
.env.example | ||
.gitignore | ||
CLAUDE.md | ||
merged_mcp_server.py | ||
package.json | ||
portainer_docker_server.py | ||
portainer_environments_server.py | ||
portainer_kubernetes_server.py | ||
portainer_stacks_server.py | ||
pyproject.toml | ||
README_DOCKER.md | ||
README_ENVIRONMENTS.md | ||
README_KUBERNETES.md | ||
README_MERGED.md | ||
README_STACKS.md | ||
README.md | ||
requirements.txt | ||
run_mcp.py | ||
run_server.py | ||
simple_mcp_server.py | ||
test_uvx.py | ||
USAGE.md |
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 .
Using uv (recommended)
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
- Log in to your Portainer instance
- Go to User Settings > API Tokens
- Click Add API Token
- 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/passwordgenerate_token
- Generate API tokensget_current_user
- Get current user info
User Management
list_users
- List all userscreate_user
- Create new userupdate_user
- Update user detailsdelete_user
- Delete user
Settings
get_settings
- Get Portainer settingsupdate_settings
- Update configuration
Health
health_check
- Server health status
Available Resources
portainer://users
- User management dataportainer://settings
- Configuration settingsportainer://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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
MIT License - see LICENSE file for details.