Labsco
2001adarsh logo

Jenkins MCP server

โ˜… 4

from 2001adarsh

Read-first Jenkins MCP server in Go for agent-driven build debugging. 20 tools including compare_builds, flaky-test detection, JUnit/Ginkgo failure parsing, and disk-cached console logs with on-disk path handoff. Write tools (trigger/stop/cancel) gated by JENKINS_MCP_READONLY env var.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedAccount requiredNeeds API keys

jenkins-mcp-go

A focused, fast Model Context Protocol (MCP) server for Jenkins, written in Go.

Connect Jenkins to Claude Desktop, Claude Code, Cursor, or any MCP-compatible AI agent: fetch console logs, inspect pipeline stages, parse JUnit and Ginkgo test reports, diff two builds, rank flaky tests, trigger and abort builds, and manage the build queue โ€” all over a single MCP stdio transport, from one static Go binary.

Go Reference Go Report Card


Why jenkins-mcp-go?

Most Jenkins integrations expect a human at a keyboard. LLM agents need something different: small, structured responses; a clear path from "build failed" to "here is the failing line"; and the ability to grep a multi-gigabyte console log without re-downloading it on every question.

jenkins-mcp-go is built for that workflow:

  • Read-first, opt-out writes. Read tools are always on. Write tools (trigger_build, stop_build, cancel_queue_item) are gated by JENKINS_MCP_READONLY: set the env var and the server registers only the read surface.
  • Single-host, single-credential. It talks to one Jenkins URL with one API token, configured by environment variables. No multi-tenant surface, no credential vault to misuse.
  • Triage-shaped, not API-shaped. Tools answer the questions agents actually ask โ€” "what changed between build A and B?" (compare_builds), "which tests in this job are flaky?" (get_flaky_candidates), "what commits and files touched this build?" (get_scm_context) โ€” instead of mirroring Jenkins endpoints one-for-one.
  • Built for context windows. Every listing tool takes an RE2 filter and a cap. get_console_log_path returns the on-disk path of a finished build's log so the agent can Read/Grep/Bash it natively instead of streaming gigabytes through MCP.
  • Disk-cached console logs. Finished builds are saved once and reused. The cache is keyed by job path + build number, capped by total size, and evicted by LRU mtime.
  • Pipeline- and Ginkgo-aware. Beyond the raw console, dedicated tools parse /wfapi/describe, /testReport/api/json, and Ginkgo's Summarizing N Failure block so the agent gets pre-digested failure information.
  • One static binary. Pure Go. No Python runtime, no Docker required.

Tools

ToolPurpose
health_checkValidate the server's setup: Jenkins reachability and version, authenticated user, CSRF crumb issuer, Pipeline/JUnit plugin presence, online/offline node counts, clock skew, and the effective config the process is running with.
get_plugin_versionsList installed Jenkins plugins with versions, pinned flag, and pending-update flag. Optional name_filter (RE2) and include_inactive. 403 degrades to a clear hint.
whoami_canProbe a job for the configured token's effective Read / Build / Cancel / Configure permissions via read-only GET requests. Useful up-front to avoid a 403 on a trigger or cancel. Stays read-only even when JENKINS_MCP_READONLY=false.
list_jobsEnumerate jobs and folders under a path (or root). Optional recursion and case-insensitive RE2 name filter; capped at 500 entries.
list_branchesEnumerate the branches of a WorkflowMultiBranchProject with per-branch last-build number, result, duration, and timestamp. Optional name_filter (RE2) and healthy_only.
get_console_logTail the build's /consoleText. Defaults to last 500 lines; pass tail_lines: -1 for the full log.
get_console_log_pathForce-cache the full log for a completed build and return its on-disk path so the agent can Read/Grep/Bash it natively.
search_console_logRE2 regex search over the console log with line-number-aware context windows.
tail_running_buildCapped, offset-tracked tail of an in-flight build's console via Jenkins' progressiveText. Echo Next since_byte back to paginate. Never writes to the on-disk cache.
get_build_infoPretty-printed build summary: result, duration, parameters, change set.
get_build_environmentThree sections for a build: Cause (trigger reason verbatim), Parameters (masked secrets surfaced as (masked)), and Injected Env Vars via EnvInject. Optional RE2 name_filter narrows the env-var section. Degrades on EnvInject 404.
get_scm_contextPer-commit history for one build: commit id, author, timestamp, message subject, and each commit's touched paths with A/M/D edit codes. Pipeline change sets are flattened with per-set headers. Optional RE2 path_filter.
last_green_buildReport the most recent successful build of a job. Returns number, finish time (UTC), and URL โ€” the start point for bisect-from-green.
changes_since_last_greenUnion the commits across every completed build since the job's last green. Walks previousCompletedBuild, dedupes by commitId, supports path_filter and max_commits. Surfaces 'all green' and wide-window footers.
compare_buildsDiff two builds of the same job across result, duration, parameters, SCM commits, pipeline stages, and JUnit tests. The agent answers "what changed between A and B?" in one call.
get_pipeline_stagesList Declarative/Scripted Pipeline stages via /wfapi/describe with status and duration.
get_stage_logFetch a single pipeline stage's log via /execution/node/<id>/wfapi/log.
get_pipeline_scriptReturn the Jenkinsfile a specific build actually ran. Tries the Replay plugin first (build-pinned), falls back to config.xml (job-level โ€” provenance surfaced). Returns SCM coords as a hint for Pipeline-from-SCM jobs.
get_test_reportStructured JUnit results from /testReport/api/json, with failed cases and head+tail of stack traces.
get_flaky_candidatesRank flaky tests across the latest N completed builds of one job by counting passโ†”fail flips. Returns a sorted table of test name, flip count, pass/fail tallies, and last-seen build.
get_test_historyPer-build trend of a single test across the last N completed builds โ€” the follow-up to get_flaky_candidates once a suspect is known. Timeline (build #, result, status, duration, error head) plus a summary of counts and flips.
find_test_by_nameLocate which job runs a test whose full name contains a substring. Walks list_jobs(recursive) under folder_path, fans out per-job probes against lastCompletedBuild/testReport with a 5s per-job timeout, renders a sorted table of hits.
find_recent_failuresSurvey failed builds across the jobs under folder_path within a lookback window. Per-job probe of the last 5 builds; filters by since (24h default; supports Nd) and result_filter (FAILURE/UNSTABLE/ABORTED/ANY_NON_SUCCESS).
list_pr_buildsList all builds for a PR on a WorkflowMultiBranchProject. Probes the common PR branch naming conventions in parallel (PR-N, pull/N/head, change-N, pr/N) and renders the build history for the first match.
get_ginkgo_failure_summaryParse Ginkgo's Summarizing N Failure block and surface the first [ERROR] tagged with each spec name.
list_nodesList Jenkins agents/nodes with status, executor counts, labels, and monitor summaries.
get_nodePer-node detail: status, per-executor idle state, labels, full monitor data.
list_queueList pending Jenkins queue items with the block reason for each.
cancel_queue_itemDrop a pending queue item by id. Mutating; suppressed when JENKINS_MCP_READONLY is set.
trigger_buildQueue a build, optionally with parameters; can block until the build is assigned a number. Mutating.
stop_buildAbort a running build. Mutating.

Build-targeted tools take a job_path (slash-separated, e.g. Builds/team/job-name) and an optional build_number (0 or omitted = lastBuild). A URL like https://jenkins.example.com/job/Builds/job/team/job/job-name/86/ becomes job_path="Builds/team/job-name", build_number=86. list_jobs takes a folder_path in the same slash-separated form (empty = root).

See docs/TOOLS.md for the full parameter reference.

Example session

Once the server is registered, ask your agent things like:

  • "What integration-test jobs do we have under Builds/team?" โ†’ calls list_jobs with folder_path: "Builds/team", recursive: true, name_filter: "integration".
  • "What was the result of build 86 of Builds/team/integration-tests?" โ†’ calls get_build_info.
  • "Show me the last 200 lines of the most recent run of nightly." โ†’ calls get_console_log with tail_lines: 200.
  • "Find every line matching panic|fatal in build 4521 with five lines of context." โ†’ calls search_console_log with pattern: "panic|fatal", context_lines: 5.
  • "Build 91 passed but 92 failed โ€” what changed?" โ†’ calls compare_builds with build_a: 91, build_b: 92.
  • "Which tests in Builds/team/integration-tests have been flipping between pass and fail recently?" โ†’ calls get_flaky_candidates.
  • "Which commits in build 86 touched anything under internal/auth/?" โ†’ calls get_scm_context with path_filter: "^internal/auth/".
  • "Which Ginkgo specs failed in build 92 and what was the first error each emitted?" โ†’ calls get_ginkgo_failure_summary.
  • "Cache the full log for build 4521 so I can grep it locally." โ†’ calls get_console_log_path; the agent then uses its own Read/Grep/Bash tools on the returned path.

Caching

Only finished builds are cached (the writer requires Jenkins' Finished: marker), and the cache is evicted by LRU mtime once it exceeds JENKINS_MCP_CACHE_MAX. Files live in JENKINS_MCP_CACHE_DIR.

Security notes

  • No credential echo. The server never includes credentials in tool output, error messages, or cached files.
  • Filesystem boundary. Cache filenames are sanitized; the cache directory is the only path the server writes to.

If you find a security issue, please follow SECURITY.md rather than opening a public issue.

Development

make build / test / lint / fmt. See CONTRIBUTING.md for the full contributor guide and docs/DEBUGGING.md for how to exercise the server locally with MCP Inspector.

Compatibility

  • Go: 1.23+
  • Jenkins: any version that exposes the standard /api/json, /consoleText, /wfapi/describe, /testReport/api/json endpoints. Pipeline-specific tools require the Pipeline plugin.
  • MCP: uses github.com/modelcontextprotocol/go-sdk v1.6+.

Alternatives

How jenkins-mcp-go compares to other ways of exposing Jenkins to an LLM:

OptionRuntimeRead-only modeConsole-log cachePipeline / JUnit / Ginkgo tools
jenkins-mcp-go (this repo)Single static Go binaryYes, gated by JENKINS_MCP_READONLYLRU disk cache for finished buildsFirst-class, pre-digested responses
Python-based Jenkins MCP serversPython interpreter + depsVaries by projectTypically none โ€” re-fetches each callUsually raw /api/json pass-through
Generic HTTP-to-MCP gatewaysNode / Python runtimeWhatever the gateway enforcesNoneNone โ€” agent has to parse raw JSON
Direct curl / shell tools from the agentShellManualNoneNone โ€” agent reasons over raw text

If you want a small, predictable surface tailored to "the agent is debugging a Jenkins build", this project is for you. If you need a generic JSON proxy or multi-tenant credential routing, a generic HTTP-MCP gateway is a better fit.