Skip to main content
Glama
mcp-jenkins-client

mcp-jenkins-client

by mzhumakhanov
README.md
# mcp-jenkins-client

An open-source [MCP](https://modelcontextprotocol.io/) server that exposes Jenkins CI/CD operations as tools for AI assistants. Built on [python-jenkins](https://python-jenkins.readthedocs.io/) and [FastMCP](https://github.com/modelcontextprotocol/python-sdk).

## Installation

Install from source with uv, or build a Docker image. Both start from a clone.

### From source (uv)

Requires Python 3.10+ and [uv](https://docs.astral.sh/uv/).

```bash
git clone <repo-url> mcp-jenkins-client
cd mcp-jenkins-client
uv sync                       # creates .venv and installs the server
uv run mcp-jenkins-client     # starts the server on stdio (needs the variables below)
```

To work on it, install the test dependencies and run the suite:

```bash
uv sync --extra dev
uv run pytest
```

Without uv: `python -m venv .venv && .venv/bin/pip install -e ".[dev]"`.

### Docker

Requires Docker. Python and uv are not needed.

```bash
git clone <repo-url> mcp-jenkins-client
cd mcp-jenkins-client
docker build -t mcp-jenkins-client .
```

The image is not published anywhere, so build it yourself. After `git pull`, rebuild it to update.

## Configuration

Set the following environment variables:

| Variable | Required | Description |
|----------|----------|-------------|
| `JENKINS_URL` | Yes | Jenkins server URL |
| `JENKINS_USERNAME` | Yes | Jenkins username |
| `JENKINS_API_TOKEN` | Yes | Jenkins API token |
| `JENKINS_TIMEOUT` | No | Per-request HTTP timeout in seconds (default `60`) |
| `JENKINS_LOG_CACHE_MB` | No | Disk cap for the [log cache](#log-cache) in MB (default `1024`); `0` turns the cache off |
| `JENKINS_RETRIES` | No | Retries for transient failures — 502/503/504 responses and refused connections (default `3`); `0` disables |

### Claude Desktop / Claude Code

Add to your MCP client configuration. For a uv install, use the path to your checkout:

```json
{
  "mcpServers": {
    "jenkins": {
      "command": "uv",
      "args": ["--directory", "/path/to/mcp-jenkins-client", "run", "mcp-jenkins-client"],
      "env": {
        "JENKINS_URL": "https://jenkins.example.com",
        "JENKINS_USERNAME": "your-username",
        "JENKINS_API_TOKEN": "your-api-token"
      }
    }
  }
}
```

For the Docker image, the client starts a container for each session:

```json
{
  "mcpServers": {
    "jenkins": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-e", "JENKINS_URL", "-e", "JENKINS_USERNAME", "-e", "JENKINS_API_TOKEN",
        "mcp-jenkins-client"
      ],
      "env": {
        "JENKINS_URL": "https://jenkins.example.com",
        "JENKINS_USERNAME": "your-username",
        "JENKINS_API_TOKEN": "your-api-token"
      }
    }
  }
}
```

- `-i` is required: the server talks to the client over stdin and stdout.
- `-e NAME` without a value passes the variable from `env` into the container, so the token stays out of the command line. Add `"-e", "JENKINS_TIMEOUT"` or `"-e", "JENKINS_LOG_CACHE_MB"` to pass an optional setting.
- Add `"-v", "mcp-jenkins-cache:/root/.cache/mcp-jenkins-client"` to `args` to keep the [log cache](#log-cache) across sessions; without it each container starts with an empty cache.
- Inside the container, `localhost` is the container itself. For a Jenkins on your own machine, use `http://host.docker.internal:8080` (on Linux, also add `"--add-host=host.docker.internal:host-gateway"` to `args`).

## Available Tools (54)

### Jobs (14 tools)
- `list_jobs` — List jobs with server-side pagination
- `get_job_info` — Get full job details
- `get_job_config` — Get job XML configuration
- `create_job` — Create a job from XML config
- `reconfig_job` — Update job configuration
- `copy_job` — Copy a job
- `rename_job` — Rename a job
- `delete_job` — Delete a job
- `enable_job` — Enable a disabled job
- `disable_job` — Disable a job
- `job_exists` — Check if a job exists
- `create_folder` — Create a folder
- `set_next_build_number` — Set next build number
- `search_jobs` — Search jobs by regex across all folder depths

### Builds (16 tools)
Every build tool except `delete_build` accepts `lastBuild`, `lastSuccessfulBuild`, `lastFailedBuild` or `lastCompletedBuild` in place of a build number; responses to an alias include the resolved `build_number`. Right after `build_job`, `lastBuild` is still the previous build — use the build number from `wait_for_queue_item`.
- `list_builds` — List builds for a job with pagination (optionally with each build's result and parameters)
- `build_job` — Trigger a build (auto-routes parameterized jobs to `buildWithParameters`; on a multibranch project, starts a branch scan)
- `get_build_info` — Get full build details
- `get_build_status` — Get just result/building/duration — cheap, use for polling
- `wait_for_build` — Block until a build finishes (bounded, default 300s)
- `get_build_console_output` — Read a byte range of the console log
- `search_build_console` — Regex-search the console log, with context lines; page with `from_offset`
- `get_build_stages` — Get pipeline stage info
- `get_stage_log` — Read one pipeline stage's log
- `get_failed_stage_log` — Jump straight to the tail of the first failed stage
- `get_build_env_vars` — Get build environment variables
- `get_build_test_report` — Get test results
- `stop_build` — Stop a running build (escalates `/stop` → `/term` → `/kill`)
- `delete_build` — Delete a build
- `get_build_artifact` — Download a build artifact
- `get_running_builds` — List running builds

### Nodes (6 tools)
- `list_nodes` — List agent nodes with pagination
- `get_node_info` — Get node details
- `get_node_config` — Get node XML configuration
- `delete_node` — Delete a node
- `enable_node` — Enable a node
- `disable_node` — Disable a node

### Views (6 tools)
- `list_views` — List views with pagination
- `get_view_config` — Get view XML configuration
- `create_view` — Create a view
- `reconfig_view` — Update view configuration
- `delete_view` — Delete a view
- `view_exists` — Check if a view exists

### Queue (4 tools)
- `get_queue_info` — List queued items with pagination
- `get_queue_item` — Get queued item details
- `wait_for_queue_item` — Wait for a queued item to start, return its build number
- `cancel_queue_item` — Cancel a queued build

### Plugins (2 tools)
- `list_plugins` — List installed plugins with pagination
- `get_plugin_info` — Get plugin details

### System (6 tools)
- `get_server_info` — Get Jenkins server info
- `get_whoami` — Get current user info
- `get_version` — Get Jenkins version
- `quiet_down` — Prepare Jenkins for shutdown
- `run_groovy_script` — Execute Groovy script
- `check_jenkinsfile_syntax` — Validate Jenkinsfile syntax

## Typical workflow

```
build_job          → queue_id
wait_for_queue_item → build_number
wait_for_build      → result
get_failed_stage_log   (or search_build_console for a specific pattern)
```

## Pagination

List tools support server-side pagination with `offset` and `limit` parameters:

```
Use list_jobs with offset=0, limit=10 to get the first 10 jobs
```

Console output supports byte-based pagination, capped at 100 KB per call:

```
Use get_build_console_output with offset=0, limit=5000 to read the first 5KB
```

Build logs routinely reach hundreds of megabytes. Don't scan them with offsets —
search them:

```
Use search_build_console with pattern='ERROR|Traceback|FAILED' to find failures
```

Each match reports a `byte_offset`; pass it to `get_build_console_output` as
`offset` and the output starts exactly at the matched line. All offsets
(`byte_offset`, `offset`, `next_offset`, `from_offset`) are byte positions in the
text the tools return, not in Jenkins' raw log.

The search stops once it has `max_matches` matches (default 50) and their context,
so `total_matches` means "at least this many" unless `scanned_all` is true. Pass `count_all=true` to read the whole log for an exact count. For the
next batch, pass the result's `next_offset` as `from_offset`: paging that way
returns every match exactly once, with absolute line numbers (a running build's
unfinished last line may repeat).

## Log cache

The first read of a build's log downloads it from Jenkins and keeps an exact copy
on disk, so later searches and reads of that build — also in later sessions — read
the local copy instead of downloading it again. A log is downloaded only as far as
a call needs (a search stops at its matches); a later call resumes from where the
last download stopped. A running build's copy is extended with only what was added.
Parallel calls in one session share one download per build. Word searches
(`error|FAILED|traceback`) use a fast substring path. Design:
[`docs/superpowers/specs/2026-11-29-log-reading-design.md`](docs/superpowers/specs/2026-11-29-log-reading-design.md).

- Location: `$XDG_CACHE_HOME/mcp-jenkins-client/logs/`, default
  `~/.cache/mcp-jenkins-client/logs/`.
- The cache stores build log text on disk. The directory is made private to your
  user (mode `0700`), and the cache turns itself off if someone else owns it. On
  Windows there is no such check, so no privacy promise.
- `JENKINS_LOG_CACHE_MB` caps its size (default `1024`); the least recently read
  copies go first, and copies unread for 7 days are deleted. `0` turns the cache
  off: every call then streams the log from Jenkins.
- A cache error (such as a full disk) turns the cache off for the rest of the
  session; a call caught by it mid-download fails once, asking for a retry.

## License

MIT — see [LICENSE](LICENSE).