jenkins_get_build_log
Fetch the console log text for a specific Jenkins build, truncated to a configurable maximum byte size.
Instructions
Get consoleText for a build, truncated by JENKINS_MCP_MAX_LOG_BYTES.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| job | Yes | ||
| build | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/jenkins_mcp_server/tools.py:141-152 (handler)The tool handler function that fetches a build's consoleText with a size limit. It is decorated with @mcp.tool() and registered via register_tools().
@mcp.tool() def jenkins_get_build_log(job: str | list[str], build: int | str) -> dict[str, Any]: """Get consoleText for a build, truncated by JENKINS_MCP_MAX_LOG_BYTES.""" def op() -> dict[str, Any]: with _client() as client: return client.get_text_limited( f"{_build_path(job, build)}/consoleText", limit=client.config.max_log_bytes, ) return _run(op) - Helper method on JenkinsClient that streams the consoleText response, truncating at the configured byte limit and returning metadata about truncation.
def get_text_limited(self, path: str, *, limit: int) -> dict[str, Any]: url, relative = self._url(path) collected = bytearray() truncated = False with self.http.stream("GET", url) as response: self._raise_for_status(response, "GET", relative) for chunk in response.iter_bytes(): remaining = limit - len(collected) if remaining <= 0: truncated = True break if len(chunk) > remaining: collected.extend(chunk[:remaining]) truncated = True break collected.extend(chunk) return { "text": collected.decode("utf-8", errors="replace"), "bytes_returned": len(collected), "truncated": truncated, "limit": limit, } - Schema/config field for max_log_bytes (default 200,000), configurable via JENKINS_MCP_MAX_LOG_BYTES environment variable.
max_log_bytes: int = 200_000 - src/jenkins_mcp_server/tools.py:350-370 (registration)Registration of jenkins_get_build_log as a read-only tool in the READ_ONLY_TOOLS list.
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", ]