LokiMCPUniverse/jenkins-mcp-server
If you are the rightful owner of jenkins-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Jenkins MCP Server is a Model Context Protocol server designed to integrate the Jenkins automation server with GenAI applications, facilitating intelligent CI/CD pipeline management.
jenkins_list_jobs
Lists all jobs in Jenkins.
jenkins_create_job
Creates a new job in Jenkins.
jenkins_get_job_config
Retrieves the configuration of a specified job.
jenkins_build_job
Triggers a build for a specified job.
jenkins_get_build_status
Gets the status of a specified build.
Jenkins MCP Server
A Model Context Protocol (MCP) server for integrating Jenkins automation server with GenAI applications, enabling intelligent CI/CD pipeline management.
Features
-
Comprehensive Jenkins API Coverage:
- Job Management: Create, configure, build, delete jobs
- Pipeline Operations: Execute, monitor, and manage pipelines
- Build Management: Trigger builds, get status, retrieve artifacts
- Queue Management: Monitor build queue, cancel queued items
- Node/Agent Management: List nodes, get node status, manage agents
- Plugin Management: List, install, update plugins
- Credentials Management: Securely manage Jenkins credentials
- Folder/Organization: Support for folders and organization folders
- Blue Ocean API: Modern pipeline visualization and management
- Webhook Integration: GitHub, GitLab, Bitbucket webhooks
-
Authentication Methods:
- API Token authentication
- Username/Password (not recommended)
- OAuth 2.0 support
- LDAP/AD integration
-
Enterprise Features:
- Multi-master Jenkins support
- Role-based access control (RBAC)
- Audit logging
- Performance monitoring
- Batch operations for efficiency
Installation
pip install jenkins-mcp-server
Or install from source:
git clone https://github.com/asklokesh/jenkins-mcp-server.git
cd jenkins-mcp-server
pip install -e .
Configuration
Create a .env
file or set environment variables:
# Jenkins Connection
JENKINS_URL=https://jenkins.example.com
JENKINS_USERNAME=your_username
JENKINS_API_TOKEN=your_api_token
# Optional Settings
JENKINS_VERIFY_SSL=true
JENKINS_TIMEOUT=30
JENKINS_MAX_RETRIES=3
# Multi-Master Support (optional)
JENKINS_PROD_URL=https://jenkins-prod.example.com
JENKINS_PROD_USERNAME=prod_user
JENKINS_PROD_API_TOKEN=prod_token
JENKINS_DEV_URL=https://jenkins-dev.example.com
JENKINS_DEV_USERNAME=dev_user
JENKINS_DEV_API_TOKEN=dev_token
Quick Start
Basic Usage
from jenkins_mcp import JenkinsMCPServer
# Initialize the server
server = JenkinsMCPServer()
# Start the server
server.start()
Claude Desktop Configuration
Add to your Claude Desktop config:
{
"mcpServers": {
"jenkins": {
"command": "python",
"args": ["-m", "jenkins_mcp.server"],
"env": {
"JENKINS_URL": "https://jenkins.example.com",
"JENKINS_USERNAME": "your_username",
"JENKINS_API_TOKEN": "your_api_token"
}
}
}
}
Available Tools
Job Management
List Jobs
{
"tool": "jenkins_list_jobs",
"arguments": {
"folder": "optional/folder/path",
"view": "optional_view_name"
}
}
Create Job
{
"tool": "jenkins_create_job",
"arguments": {
"job_name": "my-new-job",
"config_xml": "<project>...</project>",
"folder": "optional/folder/path"
}
}
Get Job Config
{
"tool": "jenkins_get_job_config",
"arguments": {
"job_name": "my-job",
"folder": "optional/folder/path"
}
}
Build Operations
Trigger Build
{
"tool": "jenkins_build_job",
"arguments": {
"job_name": "my-job",
"parameters": {
"BRANCH": "main",
"ENVIRONMENT": "staging"
},
"folder": "optional/folder/path"
}
}
Get Build Status
{
"tool": "jenkins_get_build_status",
"arguments": {
"job_name": "my-job",
"build_number": 123
}
}
Get Build Logs
{
"tool": "jenkins_get_build_logs",
"arguments": {
"job_name": "my-job",
"build_number": 123,
"start": 0,
"max_lines": 1000
}
}
Pipeline Operations
Execute Pipeline
{
"tool": "jenkins_execute_pipeline",
"arguments": {
"job_name": "my-pipeline",
"pipeline_script": "pipeline { agent any; stages { ... } }",
"parameters": {}
}
}
Get Pipeline Status
{
"tool": "jenkins_get_pipeline_status",
"arguments": {
"job_name": "my-pipeline",
"build_number": 123
}
}
Queue Management
List Queue Items
{
"tool": "jenkins_list_queue",
"arguments": {}
}
Cancel Queue Item
{
"tool": "jenkins_cancel_queue_item",
"arguments": {
"queue_id": 456
}
}
Node Management
List Nodes
{
"tool": "jenkins_list_nodes",
"arguments": {}
}
Get Node Info
{
"tool": "jenkins_get_node_info",
"arguments": {
"node_name": "agent-01"
}
}
Plugin Management
List Plugins
{
"tool": "jenkins_list_plugins",
"arguments": {
"active_only": true
}
}
Install Plugin
{
"tool": "jenkins_install_plugin",
"arguments": {
"plugin_name": "git",
"version": "latest"
}
}
Credentials Management
Create Credentials
{
"tool": "jenkins_create_credentials",
"arguments": {
"credential_id": "github-token",
"credential_type": "secret_text",
"secret": "ghp_xxxxx",
"description": "GitHub API Token",
"domain": "global"
}
}
Advanced Configuration
Multi-Master Support
from jenkins_mcp import JenkinsMCPServer, JenkinsConfig
# Configure multiple Jenkins masters
masters = {
"production": JenkinsConfig(
url="https://jenkins-prod.example.com",
username="prod_user",
api_token="prod_token"
),
"development": JenkinsConfig(
url="https://jenkins-dev.example.com",
username="dev_user",
api_token="dev_token"
),
"staging": JenkinsConfig(
url="https://jenkins-staging.example.com",
username="staging_user",
api_token="staging_token"
)
}
server = JenkinsMCPServer(masters=masters, default_master="production")
Pipeline as Code
# Define reusable pipeline templates
pipeline_templates = {
"standard_build": """
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'make build'
}
}
stage('Test') {
steps {
sh 'make test'
}
}
stage('Deploy') {
when {
branch 'main'
}
steps {
sh 'make deploy'
}
}
}
}
"""
}
server = JenkinsMCPServer(pipeline_templates=pipeline_templates)
Webhook Configuration
from jenkins_mcp import JenkinsMCPServer, WebhookConfig
webhook_config = WebhookConfig(
enabled=True,
port=8080,
secret="webhook_secret",
ssl_cert="/path/to/cert.pem",
ssl_key="/path/to/key.pem"
)
server = JenkinsMCPServer(webhook_config=webhook_config)
Integration Examples
See the examples/
directory for complete integration examples:
basic_operations.py
- Common Jenkins operationspipeline_management.py
- Pipeline creation and managementmulti_master.py
- Managing multiple Jenkins instancesgitops_integration.py
- GitOps workflow with Jenkinsgenai_automation.py
- AI-powered pipeline generationmonitoring_dashboard.py
- Jenkins monitoring and alerting
Security Best Practices
- Use API tokens instead of passwords
- Enable HTTPS for all connections
- Implement RBAC with minimal permissions
- Rotate API tokens regularly
- Use Jenkins credentials for sensitive data
- Enable audit logging for compliance
- Restrict network access to Jenkins
Error Handling
The server provides detailed error information:
try:
result = server.execute_tool("jenkins_build_job", {
"job_name": "my-job"
})
except JenkinsError as e:
print(f"Jenkins error: {e.error_code} - {e.message}")
if e.status_code == 404:
print("Job not found")
elif e.status_code == 403:
print("Permission denied")
Performance Optimization
- Use batch operations for multiple jobs
- Enable caching for job configurations
- Implement pagination for large result sets
- Use lightweight API calls when possible
- Monitor API rate limits
Troubleshooting
Common Issues
-
Authentication failures
- Verify API token is valid
- Check user permissions
- Ensure CSRF protection is handled
-
Connection timeouts
- Increase timeout values
- Check network connectivity
- Verify Jenkins URL
-
Permission errors
- Verify user has required permissions
- Check folder-level permissions
- Review security realm settings
Contributing
Contributions are welcome! Please read our contributing guidelines and submit pull requests.
License
MIT License - see LICENSE file for details