mcp-jenkins-server

mcp-jenkins-server

3.4

The MCP Jenkins server is a Model Context Protocol server that facilitates interaction between AI assistants and Jenkins CI/CD servers, providing a standardized interface for managing builds, checking statuses, and automating job management within Jenkins environments.

The MCP Jenkins server refers to a Model Context Protocol server that facilitates interaction between AI assistants and Jenkins CI/CD servers. It provides a standardized interface for managing builds, checking statuses, and automating job management within Jenkins environments.

Key Features of MCP Jenkins Server

  • Standardized Interface: The MCP Jenkins server allows AI tools to communicate with Jenkins in a uniform manner, simplifying integration and enhancing functionality.
  • AI Integration: It enables AI systems to connect securely with Jenkins, allowing for improved automation and data handling.
  • Enhanced Workflows: By utilizing MCP, teams can streamline their CI/CD processes, making deployments more efficient and reducing manual intervention.

Potential Benefits of Using MCP with Jenkins

  • Improved Communication: Facilitates better interaction between Jenkins and external AI tools, optimizing task assignments and real-time data analysis.
  • Automated Documentation: AI tools can automatically document deployment changes, ensuring that all team members have access to the latest information.
  • Dynamic Task Management: AI can intelligently reassign tasks based on workload and project progress, enhancing team productivity.

Future Implications

  • Scalability: Organizations that adopt MCP principles with Jenkins are likely to adapt more quickly to technological advancements, ensuring they remain competitive.
  • Enhanced Security Compliance: Integrating MCP can streamline compliance checks, automatically verifying deployments against the latest regulations.
  • Fostering Innovation: By allowing different tools to communicate effectively, teams may discover new solutions and approaches to challenges, driving innovation.

MCP-Powered CI/CD Pipeline Automation [2]

image

Why Claude for Desktop and not Claude.ai?

Because servers are locally run, MCP currently only supports desktop hosts. Remote hosts are in active development.

Use cases and benefits sonarqube

  • Retrieve SonarQube metrics and issues programmatically
  • Integrate SonarQube data into AI assistants or automation workflows
  • Enable AI models to query and analyze code quality data dynamically
  • Build custom dashboards or reporting tools leveraging MCP abstraction

SonarQube Jenkins MCP Server

  1. MCP Servers: Deploy MCP servers for both Jenkins and SonarQube.
  2. Jenkins Pipeline: Create a Jenkins pipeline that includes stages for:
  • Code checkout
  • SonarQube analysis (using SonarScanner)
  • Interaction with Jenkins MCP server
  • Interaction with SonarQube MCP server
  1. Python Scripts: Use Python scripts within the Jenkins pipeline to call MCP tools exposed by the Jenkins and SonarQube MCP servers.
  2. SonarQube Setup: Configure SonarQube with necessary tokens and quality gates.

Use cases for MCP server integration with Jenkins and SonarQube

  1. Automated Code Quality Enforcement in CI Pipelines
  • Use the MCP server to programmatically trigger SonarQube scans from Jenkins jobs and retrieve quality gate results.
  • Automatically fail or continue Jenkins pipelines based on SonarQube quality gate status, enforcing code quality standards without manual intervention.
  • Example: After a Jenkins build completes, an MCP client calls the SonarQube MCP server to fetch the quality gate status; if the gate fails, the Jenkins job is aborted or flagged as failed
from mcp.client import Client

sonarqube_client = Client("http://sonarqube-mcp-server:8000")

quality_gate = sonarqube_client.call_tool(
    "get_quality_gate_status",
    params={"projectKey": "my-project-key"}
)

print("Quality Gate Status:", quality_gate)

if quality_gate.get("status") != "OK":
    raise Exception("Quality gate failed - aborting pipeline")
  1. Unified Dashboard for Build and Code Quality Metrics
  • Aggregate Jenkins job statuses and SonarQube code quality metrics through MCP servers into a single AI assistant or dashboard.
  • Enable developers and managers to query build results, test coverage, code smells, and technical debt in one place using natural language or scripted queries.
  • Example: An AI assistant connected via MCP can answer questions like “Show me the latest Jenkins build status and SonarQube quality report for project X”
  1. Automated Issue Detection and Remediation Suggestions
  • Use MCP servers to extract SonarQube issues and code smells and feed them into AI models that suggest fixes or refactoring steps.
  • Integrate with Jenkins to automatically create tickets or trigger remediation jobs when critical issues are detected.
  • Example: After a SonarQube scan, the MCP server provides issue details to an AI assistant, which generates code improvement suggestions or creates Jenkins jobs to apply fixes.
  1. Dynamic Jenkins Job Management Based on SonarQube Insights
  • Use MCP to monitor SonarQube metrics and dynamically adjust Jenkins job parameters or trigger additional tests for risky code changes.
  • Example: If SonarQube reports increased code complexity or new security vulnerabilities, MCP-driven automation can trigger extended Jenkins test suites or security scans.
from mcp.client import Client

sonarqube_client = Client("http://sonarqube-mcp-server:8000")

quality_gate = sonarqube_client.call_tool(
    "get_quality_gate_status",
    params={"projectKey": "my-project-key"}
)

print("Quality Gate Status:", quality_gate)

if quality_gate.get("status") != "OK":
    raise Exception("Quality gate failed - aborting pipeline")
  1. Seamless Multi-Tool Integration in Pipelines
  • Leverage MCP to abstract Jenkins and SonarQube APIs, allowing pipeline scripts to interact with both tools uniformly via MCP clients.
  • Simplify pipeline code by offloading API integration complexities to MCP servers, making pipelines more maintainable and extensible.
  • Example: A Jenkins pipeline calls MCP tools to start builds, run SonarQube analysis, fetch results, and decide next steps based on combined data.
  1. Real-Time Notifications and Feedback Loops
  • Configure MCP servers to relay Jenkins build and SonarQube analysis results to chatops tools or notification systems.
  • Provide developers with immediate feedback on build success, code quality regressions, or quality gate failures.
  • Example: Upon build completion, MCP servers send summarized results to Slack or Microsoft Teams, enabling rapid response to issues.

Use case Gitab with Jenkins MCP Server:

  1. Emergency Hotfix Deployment Scenario: Production is down due to a critical bug. Need to quickly fix, test, and deploy. Workflow:

Create hotfix branch in GitLab from main Apply urgent code fix Trigger Jenkins build for hotfix branch Monitor build progress and deployment Create merge request back to main after validation

  1. Build Failure Investigation & Auto-Fix Scenario: Overnight builds are failing, blocking the development team. Workflow:

Analyze failed Jenkins build logs Identify root cause (missing dependency, syntax error, environment issue) Locate and update Jenkinsfile or shared library in GitLab Apply fix and trigger new build Validate fix works across multiple branches

  1. New Microservice Pipeline Setup Scenario: Development team needs CI/CD for a new microservice. Workflow:

Create new GitLab repository for microservice Set up Jenkins multibranch pipeline Configure build triggers for feature branches and main Set up shared library integration for common build steps Configure deployment stages (dev, staging, prod)

  1. Release Branch Management Scenario: Quarterly release needs coordinated branch management and builds. Workflow:

Create release branch in GitLab from main Update Jenkins job to include release branch in build triggers Cherry-pick specific commits to release branch Run regression builds on release branch Tag and deploy release when builds pass

  1. Shared Library Updates Across Multiple Projects Scenario: Security patch requires updating shared Jenkins library used by 20+ projects. Workflow:

Update shared library code in GitLab Test changes against representative projects Identify which Jenkins jobs use the shared library Trigger builds for affected projects to validate compatibility Monitor for any breaking changes across the organization

  1. Developer Onboarding Automation Scenario: New developer needs access to repositories and build systems. Workflow:

Fork template repositories in GitLab for new developer Create personal development Jenkins jobs Set up branch protection rules and merge request templates Configure notification settings for build results

  1. Compliance Audit Preparation Scenario: Need to document and validate all CI/CD processes for audit. Workflow:

Extract Jenkins job configurations and build histories Document GitLab repository structures and access controls Generate reports on build success rates and deployment frequencies Validate that all processes follow security guidelines

  1. Performance Testing Pipeline Scenario: Need automated performance testing as part of CI/CD. Workflow:

Configure Jenkins job to trigger performance tests after successful builds Store test configurations and scripts in GitLab Parse performance test results and fail builds if thresholds exceeded Generate performance trend reports over time

  1. Multi-Environment Deployment Scenario: Code needs to be deployed to dev, staging, and production environments. Workflow:

Configure Jenkins pipeline with multiple deployment stages Use GitLab variables for environment-specific configurations Implement approval gates between environments Track deployment status across all environments

  1. Dependency Update Management Scenario: Regular updates to third-party dependencies across multiple projects. Workflow:

Scan GitLab repositories for outdated dependencies Create automated pull requests with dependency updates Trigger Jenkins builds to validate compatibility Merge updates that pass all tests automatically

These use cases reflect real challenges that development and DevOps teams face daily. Each involves coordinating between GitLab (source control) and Jenkins (CI/CD) to solve practical business problems.

Note

from typing import Any
import httpx
from mcp.server.fastmcp import FastMCP

# Initialize FastMCP server
mcp = FastMCP("weather")

# Constants
NWS_API_BASE = "https://api.weather.gov"
USER_AGENT = "weather-app/1.0"

---> The FastMCP class uses Python type hints and docstrings to automatically generate tool definitions, making it easy to create and maintain MCP tools:

  • Send and receive data from MCP server
  • Manage version and authenticate
  • Fix error and response from host

Links:

[1] https://www.byteplus.com/en/topic/541523?title=mcp-ci-cd-integration-revolutionizing-automated-deployment-workflows

[2] https://blogs.cisco.com/developer/mcp-usecases

[3] https://www.piwheels.org/project/mcp-jenkins/

[4] https://github.com/hekmon8/Jenkins-server-mcp

[5] https://github.com/ProgrammerAgua/jenkins-mcp-server

[6] https://pypi.org/project/mcp-jenkins/#description

[7] https://smithery.ai/server/%40lanbaoshen%2Fmcp-jenkins/tools

[8] https://mcpmarket.com/server/sonarqube (sonarqube apis)

[9] https://github.com/lieee1995/mcp-jenkins-server