jenkins_list_builds
Retrieve recent builds for a Jenkins job to monitor build status, duration, and outcome.
Instructions
List recent builds for a job.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| job | Yes | ||
| tree | No | builds[number,url,result,building,timestamp,duration] |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/jenkins_mcp_server/tools.py:124-130 (handler)The `jenkins_list_builds` tool handler function, decorated with `@mcp.tool()` inside `register_tools()`. It accepts a `job` path and optional `tree` parameter (defaulting to builds fields), calls `job_path()` to build the Jenkins API path, then fetches JSON from the job's API endpoint with the `tree` query parameter.
@mcp.tool() def jenkins_list_builds( job: str | list[str], tree: str = "builds[number,url,result,building,timestamp,duration]", ) -> dict[str, Any]: """List recent builds for a job.""" return _run(lambda: _get_json(job_path(job), params={"tree": tree})) - src/jenkins_mcp_server/tools.py:55-55 (registration)The `register_tools(mcp: FastMCP)` function that registers all tools including `jenkins_list_builds` via the `@mcp.tool()` decorator.
def register_tools(mcp: FastMCP) -> None: - The `job_path()` helper function used by `jenkins_list_builds` to convert a job name (string or list) into a Jenkins API path.
def job_path(job: str | list[str]) -> str: pieces = [piece for piece in job.split("/") if piece] if isinstance(job, str) else job if not pieces: raise PathValidationError("job must include at least one path segment") encoded: list[str] = [] for piece in pieces: if not piece or piece in {".", ".."} or "/" in piece: raise PathValidationError("job path segments must be non-empty names") encoded.extend(["job", quote(piece, safe="")]) return "/".join(encoded) - The `_get_json()` helper function used by `jenkins_list_builds` to execute the actual HTTP GET request to Jenkins.
def _get_json(path: str, params: dict[str, Any] | None = None) -> Any: with _client() as client: return client.get_json(path, params=params) - src/jenkins_mcp_server/tools.py:350-370 (registration)The `READ_ONLY_TOOLS` list that includes `jenkins_list_builds`, marking it as a read-only tool.
READ_ONLY_TOOLS = [ "jenkins_whoami", "jenkins_version", "jenkins_health", "jenkins_get_json", "jenkins_list_jobs", "jenkins_get_job", "jenkins_get_job_config", "jenkins_list_builds", "jenkins_get_build", "jenkins_get_build_log", "jenkins_get_build_artifacts", "jenkins_get_test_report", "jenkins_list_queue", "jenkins_get_queue_item", "jenkins_list_views", "jenkins_get_view", "jenkins_list_nodes", "jenkins_get_node", "jenkins_list_plugins", ]