A Model Context Protocol (MCP) server for fetching and analyzing Jenkins build console logs. Supports multiple Jenkins instances (named configurations) and automatic instance detection from job URLs.
- Get Console Logs: Fetch complete console output from Jenkins builds
- Analyze Build Errors: Extract error snippets with context from large logs
- Extract Git Repositories: Identify git repositories, branches, and commits used in builds
- Get Build Information: Retrieve build metadata (status, duration, triggers, etc.)
- Clone the repository:
git clone <repository-url>
cd jenkins-mcp-server- Install dependencies:
uv sync- Create a
.envfile in the root directory (use.env.exampleas a template):
cp .env.example .env- Configure your Jenkins credentials:
For a single Jenkins server:
JENKINS_URL=https://your-jenkins-instance.com
JENKINS_USER=your_username
JENKINS_API_TOKEN=your_api_tokenIf you have multiple Jenkins servers (e.g., legacy and current), you can configure them using named instances:
# Default instance (backward compatible)
JENKINS_URL=https://jenkins.example.com
JENKINS_USER=default_user
JENKINS_API_TOKEN=default_token
# Legacy Jenkins
JENKINS_LEGACY_URL=https://jenkins-legacy.example.com
JENKINS_LEGACY_USER=legacy_user
JENKINS_LEGACY_API_TOKEN=legacy_token
# Current/Production Jenkins
JENKINS_CURRENT_URL=https://jenkins.production.example.com
JENKINS_CURRENT_USER=current_user
JENKINS_CURRENT_API_TOKEN=current_tokenWhen using multiple instances, provide the full Jenkins job URL and the server will automatically use the correct instance:
- Example:
"https://jenkins-legacy.example.com/job/MyFolder/job/MyJob/lastBuild"
The server matches the URL against configured instances and uses the appropriate credentials.
- Log in to your Jenkins instance
- Click on your username in the top-right corner
- Click "Configure"
- Under "API Token", click "Add new Token"
- Give it a name and click "Generate"
- Copy the token and add it to your
.envfile
uv run jenkins-mcp-serverOr run the Python file directly:
uv run python main.pyThe server will start on http://0.0.0.0:3000/mcp (configurable via SERVER_PORT and SERVER_PATH environment variables)
All tools require a full Jenkins job URL including the build number or alias.
URL Format:
https://jenkins.example.com/job/JobName/job/SubJob/lastBuild
Build Aliases:
lastBuild- Most recent buildlastSuccessfulBuild- Most recent successful buildlastFailedBuild- Most recent failed buildlastCompletedBuild- Most recent completed build
Fetch the complete console log for a Jenkins build.
Parameters:
job_url(required): Full Jenkins job URL
Example:
get_jenkins_console_log(
job_url="https://jenkins.example.com/job/MyProject/job/my-application/123"
)Analyze a build log and extract error snippets. For large logs, it automatically extracts relevant error sections with surrounding context.
Parameters:
job_url(required): Full Jenkins job URL
Example:
analyze_jenkins_build_errors(
job_url="https://jenkins.example.com/job/MyProject/job/my-application/lastFailedBuild"
)Extract git repository information from a build's console log. Returns deduplicated list of repositories with URLs, branches, and commit hashes.
Parameters:
job_url(required): Full Jenkins job URL
Example:
get_jenkins_git_repositories(
job_url="https://jenkins.example.com/job/MyProject/job/my-application/lastBuild"
)Get metadata about a Jenkins build (status, duration, timestamp, etc.).
Parameters:
job_url(required): Full Jenkins job URL
Example:
get_jenkins_build_info(
job_url="https://jenkins.example.com/job/MyProject/job/my-application/123"
)You can customize the behavior using environment variables:
JENKINS_URL: Your Jenkins instance URLJENKINS_USER: Your Jenkins usernameJENKINS_API_TOKEN: Your Jenkins API tokenJENKINS_VERIFY_SSL: Enable/disable SSL certificate verification (default:true). Set tofalsefor self-signed certificatesMAX_LOG_SIZE: Maximum log size (in characters) before extracting snippets (default: 250000)CONTEXT_WINDOW: Number of lines to include around errors (default: 2)HTTP_TIMEOUT: Overall HTTP request timeout in seconds (default: 30)HTTP_CONNECT_TIMEOUT: HTTP connection timeout in seconds (default: 10)HTTP_READ_TIMEOUT: HTTP read timeout in seconds (default: 120)HTTP_WRITE_TIMEOUT: HTTP write timeout in seconds (default: 10)SERVER_PORT: Port the MCP server listens on (default: 3000)SERVER_PATH: Path for the MCP endpoint (default: /mcp)DEBUG: Enable verbose debug logging (default:false). Set totrueto see detailed logs including instance detection, API calls, and response sizes
Enable verbose logging to see detailed information about instance detection, API calls, and responses:
DEBUG=trueWhen enabled, you'll see output like:
🔧 Configuration loaded (DEBUG MODE ENABLED):
Jenkins instances configured: 2
- https://jenkins.example.com (user: your_user)
- https://jenkins-legacy.example.com (user: legacy_user)
...
If you're connecting to a Jenkins instance with a self-signed certificate and encounter SSL errors, you can disable SSL verification:
JENKINS_VERIFY_SSL=falseNote: Disabling SSL verification should only be used in development/staging environments. For production, use proper SSL certificates.
uv run pytestuv run ruff check .uv run pyrightMIT