Token-optimized Jenkins MCP server with smart log handling and advanced triage
Project description
jankins
Token-optimized Jenkins MCP server with smart log handling and failure triage
jankins provides MCP-compliant access to Jenkins with features designed for AI coding assistants:
- 🎯 Token-aware formatting: Summary/full/diff output modes minimize context usage
- 📊 Smart log truncation: Progressive retrieval with byte offsets, regex filtering, and ANSI cleanup
- 🔍 Failure triage: Automated root cause analysis with hypotheses and next steps
- ⚡ Efficient by default: Returns compact summaries unless full detail is requested
- 🛡️ Better error handling: Structured errors with remediation hints and correlation IDs
- 📝 Built-in prompts: Pre-built workflows for common CI/CD tasks
Quick Start
Installation
pip install -e .
Basic Usage
# Set environment variables
export JENKINS_URL=https://jenkins.example.com
export JENKINS_USER=myuser
export JENKINS_API_TOKEN=11234567890abcdef1234567890abcdef
# Start the server
jankins
# Or use CLI flags
jankins --jenkins-url https://jenkins.example.com \
--jenkins-user myuser \
--jenkins-token $TOKEN \
--bind 0.0.0.0:8080
Generate Jenkins API Token
- Log in to Jenkins
- Click your username (top right) → Configure
- Scroll to "API Token" section
- Click "Add new Token"
- Give it a name and click "Generate"
- Copy the token (you won't see it again!)
Configuration
Configuration via environment variables or CLI flags. CLI flags take precedence.
| CLI Flag | Env Variable | Default | Description |
|---|---|---|---|
--jenkins-url |
JENKINS_URL |
required | Jenkins server URL |
--jenkins-user |
JENKINS_USER |
required | Jenkins username |
--jenkins-token |
JENKINS_API_TOKEN |
required | Jenkins API token |
--transport |
MCP_TRANSPORT |
stdio |
MCP transport (stdio, http, or sse) |
--bind |
MCP_BIND |
127.0.0.1:8080 |
Server bind address (http/sse only) |
--origin-enforce |
ORIGIN_ENFORCE |
false |
Enforce Origin header validation |
--origin-expected |
ORIGIN_EXPECTED |
null |
Expected Origin value |
--log-level |
LOG_LEVEL |
INFO |
Log level (DEBUG/INFO/WARNING/ERROR) |
--log-json |
LOG_JSON |
false |
Use JSON structured logging |
--debug-http |
DEBUG_HTTP |
false |
Log Jenkins HTTP requests |
--log-max-lines |
LOG_MAX_LINES_DEFAULT |
2000 |
Default max log lines |
--log-max-bytes |
LOG_MAX_BYTES_DEFAULT |
262144 |
Default max log bytes (256KB) |
--timeout |
JENKINS_TIMEOUT |
30 |
Jenkins request timeout (seconds) |
MCP Tools
jankins provides 25+ MCP tools organized by category:
Jobs
list_jobs: List jobs with prefix filtering and paginationget_job: Get detailed job informationtrigger_build: Trigger a new build with parametersenable_job/disable_job: Enable or disable a job
Builds
get_build: Get build information (supportsnumberor"last")get_build_changes: Get SCM changes/commits for a buildget_build_artifacts: List build artifacts
Logs
get_build_log: Get logs with smart truncation and filtering- Supports:
filter_regex,redact,startbyte offset,max_bytes - Returns summary by default with error counts and failing stages
- Supports:
search_log: Search logs for pattern with context window
SCM & Pipeline
get_job_scm: Get job SCM configurationget_build_scm: Get SCM info (commit, branch) for a build
Health & System
whoami: Get current user info and permissionsget_status: Jenkins version and queue depthsummarize_queue: Compact build queue summary
Advanced Analysis
-
triage_failure: Analyze failed builds with:- Root cause hypotheses
- Top error messages
- Failing stages
- Suspect commits
- Recommended next steps
-
compare_runs: Compare two builds for:- Duration differences
- Result changes
- Stage-level diffs (with Blue Ocean)
-
get_pipeline_graph: Get pipeline visualization with stages, parallel execution, and timing (Blue Ocean) -
analyze_build_log: Analyze logs with build tool-specific parsers (Maven, Gradle, NPM) for detailed error analysis and recommendations -
retry_flaky_build: Retry flaky builds with configurable attempts and delays
Test Results
get_test_report: Get test results summary (JUnit, pytest, etc.)get_failed_tests: List failed tests with error details and stack tracescompare_test_results: Compare test results between builds for regression detectiondetect_flaky_tests: Identify flaky tests across multiple builds
Logs (Enhanced)
tail_log_live: Poll-based live log tailing with progressive byte offsets
Output Formats
All tools support format parameter:
summary(default): Compact, token-efficient viewfull: Complete data with all fieldsdiff: Differences only (for comparisons)ids: IDs and URLs only
Example:
{
"name": "list_jobs",
"arguments": {
"format": "summary",
"page_size": 20
}
}
Built-in Prompts
jankins includes pre-built prompts for common workflows:
investigate_failure: Full failure investigation workflowtail_errors: Show only warnings and errors from a buildcompare_builds: Compare two builds to find differencescheck_job_health: Check overall job health and stabilitytrigger_with_params: Trigger parameterized build with guidancesearch_logs: Search logs for specific patterns
Client Examples
Claude Desktop (stdio mode - recommended)
Add to your MCP settings:
{
"mcpServers": {
"jankins": {
"command": "jankins",
"env": {
"JENKINS_URL": "https://jenkins.example.com",
"JENKINS_USER": "myuser",
"JENKINS_API_TOKEN": "your-token-here"
}
}
}
}
The default stdio transport communicates via stdin/stdout, which is the standard for MCP clients like Claude Desktop.
HTTP Mode (for HTTP-based MCP clients)
If your client requires HTTP transport:
{
"mcp": {
"servers": {
"jankins": {
"url": "http://localhost:8080/mcp",
"headers": {
"Content-Type": "application/json"
}
}
}
}
}
Direct HTTP Request
Start in HTTP mode:
jankins --transport http
Then make requests:
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get_build",
"arguments": {
"name": "my-job",
"number": "last",
"format": "summary"
}
}
}'
Example Workflows
Investigate a Failing Build
Use the "investigate_failure" prompt with job "backend-api"
This will:
- Get build status
- Retrieve error summary from logs
- Perform failure triage
- Show suspect commits
- Provide recommended next steps
Compare Two Builds
{
"name": "compare_runs",
"arguments": {
"name": "backend-api",
"base": "100",
"head": "101"
}
}
Search Logs for Error Pattern
{
"name": "search_log",
"arguments": {
"name": "backend-api",
"pattern": "OutOfMemoryError",
"window_lines": 10
}
}
Get Only Errors from Last Build
{
"name": "get_build_log",
"arguments": {
"name": "backend-api",
"number": "last",
"filter_regex": "ERROR|FATAL",
"redact": true,
"format": "summary"
}
}
Error Handling
jankins provides structured errors with:
- Error code: JSON-RPC compliant error codes
- Correlation ID: Track requests across logs
- Hint: Human-readable remediation hint
- Next actions: Specific steps to resolve the issue
- Docs URL: Link to troubleshooting guide
Error taxonomy:
InvalidParams(-32602): Invalid tool parametersUnauthorized(-32001): Authentication failedForbidden(-32002): Insufficient permissionsNotFound(-32003): Resource not foundTimeout(-32007): Request timed outUpstreamError(-32006): Jenkins server error
Token Optimization
jankins minimizes token usage through:
- Default summaries: Summary format by default, full on request
- Field limiting: Only essential fields in summary mode
- Smart truncation: Progressive log retrieval with byte limits
- Token estimation: Responses include estimated token count
- Structured data: Compact tables and lists over verbose text
- Metadata separation: Performance data in
_metasection
Example response structure:
{
"build_number": 42,
"result": "FAILURE",
"duration": "2m 15s",
"_meta": {
"correlation_id": "abc-123",
"took_ms": 250,
"format": "summary",
"token_estimate": 180
}
}
Security
- Explicit configuration: Uses env vars or CLI flags (ignores .env files in working directory)
- Basic auth: Uses Jenkins API tokens (never passwords)
- Optional Origin validation: Enforce allowed origins
- No secret logging: Credentials are redacted in logs
- Secret masking: Jenkins secret masks are preserved/redacted
Note: jankins ignores any .env files in your working directory and only reads the specific environment variables it needs (JENKINS_, MCP_, etc.). This prevents conflicts with project .env files.
Generate API tokens:
Jenkins → User → Configure → API Token → Add new Token
Health Checks
GET /_health: Basic health checkGET /_ready: Readiness check (verifies Jenkins connectivity)GET /_metrics: Placeholder for Prometheus metrics
Development
Run from Source
# Install with dev dependencies
pip install -e ".[dev]"
# Run server
python -m jankins --jenkins-url $URL --jenkins-user $USER --jenkins-token $TOKEN
# With debug logging
python -m jankins --log-level DEBUG --debug-http
Testing
pytest tests/
Docker
See docker-compose.yml for local Jenkins + jankins setup.
docker-compose up
This starts:
- Jenkins LTS on port 8081
- jankins MCP server on port 8080
Feature Comparison
| Feature | jankins | Official Plugin | Community Servers |
|---|---|---|---|
| MCP Protocol | ✅ 2025-06-18 | ✅ | ⚠️ Varies |
| Token optimization | ✅ | ❌ | ❌ |
| Progressive logs | ✅ | ⚠️ Limited | ❌ |
| Failure triage | ✅ | ❌ | ❌ |
| Build comparison | ✅ | ❌ | ❌ |
| Structured errors | ✅ | ⚠️ Basic | ❌ |
| Built-in prompts | ✅ | ❌ | ❌ |
| Format modes | ✅ | ❌ | ❌ |
| Origin validation | ✅ | ✅ | ⚠️ Varies |
Troubleshooting
"Unauthorized" Error
- Verify
JENKINS_USERandJENKINS_API_TOKENare correct - Regenerate API token from Jenkins user settings
- Check Jenkins server is accessible
"Timeout" Error
- Increase
--timeoutvalue - Check Jenkins server responsiveness
- Verify network connectivity
"Tool not found" Error
- Ensure server started successfully
- Check MCP client configuration
- Verify tool name spelling
Large Logs Timing Out
- Use
max_bytesparameter to limit retrieval - Use
filter_regexto reduce log size - Use
format=summaryfor overview first
License
MIT
Contributing
Contributions welcome! Please:
- Add tests for new features
- Follow existing code style
- Update documentation
- Add type hints
Acknowledgments
Built on:
- python-jenkins for Jenkins API
- Model Context Protocol spec
- Starlette for transport layer
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jankins-1.2.0.tar.gz.
File metadata
- Download URL: jankins-1.2.0.tar.gz
- Upload date:
- Size: 67.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0f800831a90b893ed6d76d177650c00031fa9e71a9a8d64eaa28c20732bca1d
|
|
| MD5 |
00a18320d21d1744003a67e2667ff3ea
|
|
| BLAKE2b-256 |
6d7a99f59854497c3c5c5f8106df974a9d72081ebbfabd149386aeb75e76cbe9
|
Provenance
The following attestation bundles were made for jankins-1.2.0.tar.gz:
Publisher:
release.yml on thecturner/jankins
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jankins-1.2.0.tar.gz -
Subject digest:
f0f800831a90b893ed6d76d177650c00031fa9e71a9a8d64eaa28c20732bca1d - Sigstore transparency entry: 665023651
- Sigstore integration time:
-
Permalink:
thecturner/jankins@74d65075bb42a5544de7e7e7bd8dfd5209bc726d -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/thecturner
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@74d65075bb42a5544de7e7e7bd8dfd5209bc726d -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file jankins-1.2.0-py3-none-any.whl.
File metadata
- Download URL: jankins-1.2.0-py3-none-any.whl
- Upload date:
- Size: 69.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
436788b1da2a16701c62903658402c8b7172c3734a24d2bb6dc991d76edba9df
|
|
| MD5 |
464fe08c46d05a3b9e95f568dfb73fef
|
|
| BLAKE2b-256 |
c5c76b282ffe1abd1bdba3f594afa9d666a905bcf66b4aed17685667ea6a7747
|
Provenance
The following attestation bundles were made for jankins-1.2.0-py3-none-any.whl:
Publisher:
release.yml on thecturner/jankins
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jankins-1.2.0-py3-none-any.whl -
Subject digest:
436788b1da2a16701c62903658402c8b7172c3734a24d2bb6dc991d76edba9df - Sigstore transparency entry: 665023667
- Sigstore integration time:
-
Permalink:
thecturner/jankins@74d65075bb42a5544de7e7e7bd8dfd5209bc726d -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/thecturner
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@74d65075bb42a5544de7e7e7bd8dfd5209bc726d -
Trigger Event:
workflow_dispatch
-
Statement type: