gitlab-ci-mcp 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gitlab_ci_mcp-0.5.0/.env.example +12 -0
- gitlab_ci_mcp-0.5.0/.gitignore +15 -0
- gitlab_ci_mcp-0.5.0/CHANGELOG.md +161 -0
- gitlab_ci_mcp-0.5.0/LICENSE +21 -0
- gitlab_ci_mcp-0.5.0/PKG-INFO +221 -0
- gitlab_ci_mcp-0.5.0/README.md +192 -0
- gitlab_ci_mcp-0.5.0/docs/claude-code.md +216 -0
- gitlab_ci_mcp-0.5.0/evaluations/README.md +40 -0
- gitlab_ci_mcp-0.5.0/evaluations/questions.xml +167 -0
- gitlab_ci_mcp-0.5.0/pyproject.toml +55 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/__init__.py +3 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/_mcp.py +110 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/ci_manager.py +236 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/errors.py +81 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/formatters.py +345 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/models.py +327 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/output.py +41 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/pagination.py +55 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/pipeline_health.py +114 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/resources.py +54 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/server.py +52 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/tools/__init__.py +16 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/tools/branches_tags.py +200 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/tools/mrs.py +296 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/tools/pipelines.py +482 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/tools/repo.py +156 -0
- gitlab_ci_mcp-0.5.0/src/gitlab_ci_mcp/tools/schedules.py +218 -0
- gitlab_ci_mcp-0.5.0/tests/test_smoke.py +273 -0
- gitlab_ci_mcp-0.5.0/tests/test_tools_mocked.py +252 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Copy to .env and fill in your values. Never commit the real file.
|
|
2
|
+
|
|
3
|
+
GITLAB_URL=https://gitlab.example.com
|
|
4
|
+
GITLAB_TOKEN=glpat-xxxxxxxxxxxxxxxxxxxx
|
|
5
|
+
GITLAB_PROJECT_PATH=my-org/my-repo
|
|
6
|
+
|
|
7
|
+
# Optional — defaults are fine for public GitLab instances
|
|
8
|
+
GITLAB_SSL_VERIFY=true
|
|
9
|
+
|
|
10
|
+
# Only needed when GitLab is on an intranet reached through a local HTTP proxy
|
|
11
|
+
# that would otherwise intercept internal traffic.
|
|
12
|
+
GITLAB_NO_PROXY_DOMAINS=
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `gitlab-ci-mcp` are documented here. Format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions use [SemVer](https://semver.org/).
|
|
5
|
+
|
|
6
|
+
## [0.5.0] — 2026-04-17
|
|
7
|
+
|
|
8
|
+
**Big one.** Every tool is now a fully typed MCP citizen: ``outputSchema``,
|
|
9
|
+
``structuredContent``, and the markdown text block you liked are now all
|
|
10
|
+
present on every response.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- **TypedDict output schemas** for all 23 tools (new ``models.py``) —
|
|
14
|
+
FastMCP auto-generates an ``outputSchema`` from the return annotation
|
|
15
|
+
and exposes the typed payload as ``structuredContent`` on every tool
|
|
16
|
+
result.
|
|
17
|
+
- **Dual-channel responses via ``CallToolResult``** — the ``content``
|
|
18
|
+
block still carries the compact markdown rendering (context-efficient
|
|
19
|
+
for agents), while ``structuredContent`` carries the full validated
|
|
20
|
+
payload (for clients that can render / process structured data).
|
|
21
|
+
- New ``output.py`` with ``ok()`` (builds the ``CallToolResult``) and
|
|
22
|
+
``fail()`` (raises ``ToolError`` wrapping the actionable error
|
|
23
|
+
message). All 23 tools share this pattern.
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
- **Server split into domain modules**: the 1500-line ``server.py`` is
|
|
27
|
+
now a thin composition point; tools live under ``tools/``
|
|
28
|
+
(``pipelines.py``, ``schedules.py``, ``branches_tags.py``, ``mrs.py``,
|
|
29
|
+
``repo.py``), MCP resources in ``resources.py``, and shared FastMCP
|
|
30
|
+
instance + lifespan + helpers in ``_mcp.py``.
|
|
31
|
+
- Shared helpers ``_get_ci`` / ``_ts`` / ``_is_secret_key`` /
|
|
32
|
+
``_mask_variables`` renamed without the leading underscore and moved
|
|
33
|
+
to ``_mcp`` (they are no longer single-module private).
|
|
34
|
+
- Error path is now uniform: tools raise ``ToolError(errors.handle(…))``
|
|
35
|
+
and FastMCP reports the result as ``isError=True`` — no more
|
|
36
|
+
string-based error returns.
|
|
37
|
+
|
|
38
|
+
### Removed
|
|
39
|
+
- **``response_format`` parameter** (breaking): no longer needed because
|
|
40
|
+
every tool now returns *both* markdown and structured data. Existing
|
|
41
|
+
callers that passed ``response_format='markdown'`` or ``'json'`` must
|
|
42
|
+
drop the argument — markdown remains the text content by default,
|
|
43
|
+
structured data is on ``result.structuredContent``.
|
|
44
|
+
- Dead code from ``ci_manager.py``: ``wait_for_pipeline``,
|
|
45
|
+
``ScheduleCompareResult`` (unused from the MCP path).
|
|
46
|
+
|
|
47
|
+
### Migration notes (v0.4.x → v0.5.0)
|
|
48
|
+
- Tools no longer return plain strings. If you call them programmatically,
|
|
49
|
+
inspect ``result.structuredContent`` for the typed payload and
|
|
50
|
+
``result.content[0].text`` for the markdown summary.
|
|
51
|
+
- Module imports moved: ``from gitlab_ci_mcp.server import mcp`` still
|
|
52
|
+
works, but tool functions now live under ``gitlab_ci_mcp.tools.*``.
|
|
53
|
+
|
|
54
|
+
## [0.4.2] — 2026-04-17
|
|
55
|
+
|
|
56
|
+
### Changed
|
|
57
|
+
- `warnings.filterwarnings("ignore")` and `urllib3.disable_warnings()` now
|
|
58
|
+
target **only** `urllib3.exceptions.InsecureRequestWarning` so future
|
|
59
|
+
deprecation / runtime warnings from any library still surface.
|
|
60
|
+
- `evaluations/questions.xml` — destructive-op questions (trigger / cancel /
|
|
61
|
+
retry / delete / create / merge) reframed as "Which tool should you call
|
|
62
|
+
to …?" to make the routing-only evaluation intent unambiguous. Added a
|
|
63
|
+
top-of-file comment stating harnesses must capture tool names, not execute
|
|
64
|
+
the tools.
|
|
65
|
+
|
|
66
|
+
## [0.4.1] — 2026-04-17
|
|
67
|
+
|
|
68
|
+
### Added
|
|
69
|
+
- `gitlab_get_job_log` — new `grep_pattern` + `grep_context` parameters for
|
|
70
|
+
regex-filtering large CI logs with surrounding context instead of blindly
|
|
71
|
+
tailing. Falls back to literal substring on invalid regex.
|
|
72
|
+
- `errors.handle` — explicit branches for HTTP 429 (rate-limit with wait/retry
|
|
73
|
+
guidance) and 5xx (transient server error, retry hint), applied uniformly
|
|
74
|
+
across Get/Create/Update/Delete exceptions.
|
|
75
|
+
- Tests for 429 / 5xx error paths, secret-masking helper, and job-log grep
|
|
76
|
+
parameters.
|
|
77
|
+
|
|
78
|
+
### Changed
|
|
79
|
+
- `gitlab_list_schedules` — expanded secret redaction from `TOKEN`/`PASSWORD`
|
|
80
|
+
to also match `SECRET`, `CREDENTIAL`, `PRIVATE_KEY`, `API_KEY`. Now *masks
|
|
81
|
+
values* (`"***"`) instead of dropping keys, so the agent can still see which
|
|
82
|
+
variables exist on a schedule.
|
|
83
|
+
- `evaluations/questions.xml` — added 7 multi-tool composition questions on
|
|
84
|
+
top of the 22 tool-picking ones.
|
|
85
|
+
|
|
86
|
+
### Fixed
|
|
87
|
+
- `tests/test_tools_mocked.py` — removed a leftover `os.environ.pop(v, None)`
|
|
88
|
+
that used the loop variable outside its scope (redundant with
|
|
89
|
+
`monkeypatch.delenv`).
|
|
90
|
+
|
|
91
|
+
## [0.4.0] — 2026-04-17
|
|
92
|
+
|
|
93
|
+
### Added
|
|
94
|
+
- **Lifespan management** (`asynccontextmanager`) — `python-gitlab` HTTP
|
|
95
|
+
sessions closed cleanly on server shutdown.
|
|
96
|
+
- **MCP Context integration** — `gitlab_pipeline_health` and
|
|
97
|
+
`gitlab_get_job_log` are now `async def` and emit `ctx.info` / `ctx.report_progress`
|
|
98
|
+
events, letting clients display progress for the slower operations.
|
|
99
|
+
- **MCP Resources** — `gitlab://project/info` (markdown snapshot of the default
|
|
100
|
+
project) and `gitlab://project/ci-config` (raw `.gitlab-ci.yml`).
|
|
101
|
+
- Tests for lifespan, async tools' Context parameters, and resource registration.
|
|
102
|
+
|
|
103
|
+
### Changed
|
|
104
|
+
- README: "Design highlights" section extended with Lifespan / Context /
|
|
105
|
+
Resources entries and a "Threading model" subsection documenting why most
|
|
106
|
+
tools remain sync (FastMCP runs them in a worker thread).
|
|
107
|
+
|
|
108
|
+
## [0.3.1] — 2026-04-17
|
|
109
|
+
|
|
110
|
+
### Added
|
|
111
|
+
- `Examples` section on every remaining tool docstring — all 23 tools now
|
|
112
|
+
include "Use when / Don't use when" guidance for LLM tool-picking.
|
|
113
|
+
- `CHANGELOG.md`.
|
|
114
|
+
- README section on rate limits and connection reuse.
|
|
115
|
+
|
|
116
|
+
## [0.3.0] — 2026-04-17
|
|
117
|
+
|
|
118
|
+
### Added
|
|
119
|
+
- **Pagination**: new `gitlab_ci_mcp.pagination` module exposes `page`,
|
|
120
|
+
`per_page`, `total`, `total_pages`, `next_page`, `has_more` on all list
|
|
121
|
+
tools (`list_pipelines`, `list_branches`, `list_tags`,
|
|
122
|
+
`list_merge_requests`, `list_repository_tree`).
|
|
123
|
+
- Markdown formatters render a pagination footer with a next-page hint.
|
|
124
|
+
- **Docstring `Examples:` sections** on 14 tools covering "Use when / Don't
|
|
125
|
+
use when" — improves agent routing accuracy.
|
|
126
|
+
- **Mock tests** (`tests/test_tools_mocked.py`, 7 cases) using the
|
|
127
|
+
`responses` library: happy paths (JSON + markdown), pagination,
|
|
128
|
+
401/404 error paths, missing env, project info markdown shape.
|
|
129
|
+
- **Evaluations** (`evaluations/questions.xml`): 22 tool-picking QA pairs
|
|
130
|
+
for agent-level evaluation; plus a minimal runner snippet.
|
|
131
|
+
|
|
132
|
+
### Changed
|
|
133
|
+
- `responses>=0.25` added to dev dependencies.
|
|
134
|
+
|
|
135
|
+
## [0.2.0] — 2026-04-17
|
|
136
|
+
|
|
137
|
+
### Added
|
|
138
|
+
- Tool annotations (`readOnlyHint`, `destructiveHint`, `idempotentHint`,
|
|
139
|
+
`openWorldHint`) on all 23 tools.
|
|
140
|
+
- Pydantic input validation via `typing.Annotated + pydantic.Field` on every
|
|
141
|
+
argument (descriptions, ranges, lengths, Literal enums).
|
|
142
|
+
- Dual response format: `response_format='markdown'` (default) or
|
|
143
|
+
`'json'` on read tools.
|
|
144
|
+
- New `gitlab_ci_mcp.errors` module — actionable error messages for
|
|
145
|
+
auth / 404 / 403 / 5xx / `ValueError` instead of raw tracebacks.
|
|
146
|
+
- New `gitlab_ci_mcp.formatters` module — compact markdown renderings
|
|
147
|
+
for pipelines, jobs, schedules, branches, tags, MRs, diffs, repo tree,
|
|
148
|
+
file content, compare, project info.
|
|
149
|
+
|
|
150
|
+
### Changed
|
|
151
|
+
- FastMCP server name `'gitlab'` → `'gitlab_ci_mcp'` to match
|
|
152
|
+
`{service}_mcp` convention.
|
|
153
|
+
- README redesigned with a "Design highlights" section explaining the
|
|
154
|
+
above.
|
|
155
|
+
|
|
156
|
+
## [0.1.0] — 2026-04-17
|
|
157
|
+
|
|
158
|
+
### Added
|
|
159
|
+
- Initial release. FastMCP server exposing 22 tools over stdio for
|
|
160
|
+
pipelines, schedules, branches, tags, merge requests, repository
|
|
161
|
+
files, and pipeline health. Env-based config, MIT license.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mikhail Shchegolev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gitlab-ci-mcp
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: MCP server for self-hosted GitLab — pipelines, schedules, branches, merge requests and repository files
|
|
5
|
+
Project-URL: Homepage, https://github.com/mshegolev/gitlab-ci-mcp
|
|
6
|
+
Project-URL: Issues, https://github.com/mshegolev/gitlab-ci-mcp/issues
|
|
7
|
+
Author: Mikhail Shchegolev
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: anthropic,ci-cd,claude,devops,gitlab,mcp
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Version Control
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: mcp>=1.2
|
|
22
|
+
Requires-Dist: python-gitlab>=4.0
|
|
23
|
+
Requires-Dist: urllib3>=2.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
26
|
+
Requires-Dist: responses>=0.25; extra == 'dev'
|
|
27
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# gitlab-ci-mcp
|
|
31
|
+
|
|
32
|
+
MCP server for GitLab CI/CD. Lets an LLM agent (Claude Code, Cursor, OpenCode, DevX Agent, etc.) work with pipelines, jobs, schedules, branches, tags, merge requests and repository files.
|
|
33
|
+
|
|
34
|
+
Python, [FastMCP](https://github.com/modelcontextprotocol/python-sdk), stdio transport.
|
|
35
|
+
|
|
36
|
+
Works with any GitLab — SaaS `gitlab.com` or self-hosted / on-prem. Designed with corporate networks in mind: configurable `NO_PROXY` handling, optional SSL-verify toggle, per-project scoping via env vars.
|
|
37
|
+
|
|
38
|
+
## Design highlights
|
|
39
|
+
|
|
40
|
+
- **Tool annotations** — every tool carries `readOnlyHint` / `destructiveHint` / `idempotentHint` / `openWorldHint` so MCP clients can classify operations (e.g. ask for confirmation only on destructive ones like `gitlab_merge_mr`, `gitlab_delete_schedule`).
|
|
41
|
+
- **Structured output on every tool** — each tool declares a TypedDict return type, so FastMCP auto-generates an `outputSchema` and every result carries `structuredContent` alongside a pre-rendered markdown text block. Clients that can render structured data use it; agents that prefer compact text get the markdown. No `response_format` parameter needed.
|
|
42
|
+
- **Structured errors** — authentication, 404, 403, 429 (rate-limit), 5xx, missing-env errors are converted to actionable `ToolError` messages (e.g. _"GitLab authentication failed… verify GITLAB_TOKEN has `api` scope"_) and surfaced as `isError=True` results.
|
|
43
|
+
- **Pydantic input validation** — every argument has typed constraints (ranges, lengths, literals) auto-exposed as JSON Schema.
|
|
44
|
+
- **Project scoping per call** — every tool accepts an optional `project_path` that overrides `GITLAB_PROJECT_PATH` for cross-project queries.
|
|
45
|
+
- **Pagination** — list tools return a `pagination` block with `page`, `total`, `has_more`, `next_page` and a next-page hint in the markdown footer.
|
|
46
|
+
- **MCP Context integration** — `gitlab_pipeline_health` and `gitlab_get_job_log` are `async` and emit `info` logs / `report_progress` events through the MCP Context so clients can show progress bars.
|
|
47
|
+
- **MCP Resources** — `gitlab://project/info` and `gitlab://project/ci-config` mirror common lookups for clients that prefer the Resource model over tools.
|
|
48
|
+
- **Lifespan management** — `python-gitlab` HTTP sessions are closed cleanly on server shutdown via an `asynccontextmanager` lifespan hook.
|
|
49
|
+
- **Log grep** — `gitlab_get_job_log` accepts `grep_pattern` + `grep_context` (surrounding lines) for regex-filtering megabyte-scale CI logs without pulling the whole trace into agent context.
|
|
50
|
+
|
|
51
|
+
### Threading model
|
|
52
|
+
|
|
53
|
+
FastMCP automatically runs synchronous tools in a worker thread
|
|
54
|
+
(`anyio.to_thread.run_sync`), so they do not block the asyncio event loop —
|
|
55
|
+
`python-gitlab` is a synchronous library and wrapping every call in
|
|
56
|
+
`asyncio.to_thread` ourselves would be ceremony. Tools that benefit from the
|
|
57
|
+
MCP Context (progress, info logs) are written as `async def` and explicitly
|
|
58
|
+
wrap `python-gitlab` calls with `asyncio.to_thread`.
|
|
59
|
+
|
|
60
|
+
## Features
|
|
61
|
+
|
|
62
|
+
23 tools covering the everyday CI/CD surface:
|
|
63
|
+
|
|
64
|
+
**Pipelines**
|
|
65
|
+
`gitlab_list_pipelines` · `gitlab_get_pipeline` · `gitlab_get_pipeline_jobs` · `gitlab_get_job_log` · `gitlab_trigger_pipeline` · `gitlab_retry_pipeline` · `gitlab_cancel_pipeline` · `gitlab_pipeline_health`
|
|
66
|
+
|
|
67
|
+
**Schedules**
|
|
68
|
+
`gitlab_list_schedules` · `gitlab_create_schedule` · `gitlab_update_schedule` · `gitlab_delete_schedule`
|
|
69
|
+
|
|
70
|
+
**Branches & tags**
|
|
71
|
+
`gitlab_list_branches` · `gitlab_list_tags` · `gitlab_compare_branches`
|
|
72
|
+
|
|
73
|
+
**Merge requests**
|
|
74
|
+
`gitlab_list_merge_requests` · `gitlab_get_merge_request` · `gitlab_get_merge_request_changes` · `gitlab_create_merge_request` · `gitlab_merge_mr`
|
|
75
|
+
|
|
76
|
+
**Repository & project**
|
|
77
|
+
`gitlab_get_file` · `gitlab_list_repository_tree` · `gitlab_project_info`
|
|
78
|
+
|
|
79
|
+
### Pipeline health report
|
|
80
|
+
|
|
81
|
+
`gitlab_pipeline_health` returns a ready-to-read summary over 7/30 days:
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
Last 7d: 96.4% up | 27/28 success
|
|
85
|
+
Last 30d: 92.1% | 105/114 success
|
|
86
|
+
Last 10: success success success failed success ...
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Handy for on-call / triage: `покажи health master за последние 7 дней`.
|
|
90
|
+
|
|
91
|
+
## Installation
|
|
92
|
+
|
|
93
|
+
Requires Python 3.10+.
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# via uvx (recommended)
|
|
97
|
+
uvx --from gitlab-ci-mcp gitlab-ci-mcp
|
|
98
|
+
|
|
99
|
+
# or via pip/pipx
|
|
100
|
+
pipx install gitlab-ci-mcp
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Configuration
|
|
104
|
+
|
|
105
|
+
All config is via environment variables:
|
|
106
|
+
|
|
107
|
+
| Variable | Required | Description |
|
|
108
|
+
| --- | --- | --- |
|
|
109
|
+
| `GITLAB_URL` | **yes** | Base URL, e.g. `https://gitlab.example.com` |
|
|
110
|
+
| `GITLAB_TOKEN` | **yes** | Personal Access Token with `api` scope |
|
|
111
|
+
| `GITLAB_PROJECT_PATH` | **yes** | Default project, e.g. `my-org/my-repo` |
|
|
112
|
+
| `GITLAB_SSL_VERIFY` | no | `true` (default) / `false` |
|
|
113
|
+
| `GITLAB_NO_PROXY_DOMAINS` | no | Comma-separated domains to add to `NO_PROXY` (useful in corp networks behind a local HTTP proxy — e.g. `.corp.example.com,gitlab.internal`) |
|
|
114
|
+
|
|
115
|
+
Every tool accepts an optional `project_path` arg that overrides `GITLAB_PROJECT_PATH` per call — useful for cross-project queries.
|
|
116
|
+
|
|
117
|
+
## Claude Code
|
|
118
|
+
|
|
119
|
+
**Full walkthrough:** [docs/claude-code.md](docs/claude-code.md) — prerequisites, two install paths, multi-project setup, self-hosted GitLab behind a corp proxy, troubleshooting, uninstall.
|
|
120
|
+
|
|
121
|
+
Short version:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
claude mcp add gitlab uvx --from gitlab-ci-mcp gitlab-ci-mcp \
|
|
125
|
+
--env GITLAB_URL=https://gitlab.example.com \
|
|
126
|
+
--env GITLAB_TOKEN=glpat-xxxxxx \
|
|
127
|
+
--env GITLAB_PROJECT_PATH=my-org/my-repo
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Or in `~/.claude.json` / project `.mcp.json`:
|
|
131
|
+
|
|
132
|
+
```json
|
|
133
|
+
{
|
|
134
|
+
"mcpServers": {
|
|
135
|
+
"gitlab": {
|
|
136
|
+
"type": "stdio",
|
|
137
|
+
"command": "uvx",
|
|
138
|
+
"args": ["--from", "gitlab-ci-mcp", "gitlab-ci-mcp"],
|
|
139
|
+
"env": {
|
|
140
|
+
"GITLAB_URL": "https://gitlab.example.com",
|
|
141
|
+
"GITLAB_TOKEN": "${GITLAB_TOKEN}",
|
|
142
|
+
"GITLAB_PROJECT_PATH": "my-org/my-repo",
|
|
143
|
+
"GITLAB_SSL_VERIFY": "true"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Check:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
claude mcp list
|
|
154
|
+
# gitlab: uvx --from gitlab-ci-mcp gitlab-ci-mcp - ✓ Connected
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Cursor / OpenCode / DevX Agent
|
|
158
|
+
|
|
159
|
+
Same idea — point the MCP config to `uvx --from gitlab-ci-mcp gitlab-ci-mcp` with the env vars above. See each tool's own MCP config syntax.
|
|
160
|
+
|
|
161
|
+
## Example prompts
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
что сломалось в последнем pipeline master
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
покажи health master за 7 дней для проекта my-org/other-repo
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
создай MR из feature/foo в master с title "feat: foo"
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
покажи содержимое .gitlab-ci.yml из master
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Rate limits & connection reuse
|
|
180
|
+
|
|
181
|
+
GitLab enforces a per-user rate limit (typically 2000 req/h for the REST API,
|
|
182
|
+
configurable by the admin — see your instance's `/admin/application_settings/network`).
|
|
183
|
+
|
|
184
|
+
- The server caches one `python-gitlab` HTTP session **per `project_path`**, so
|
|
185
|
+
repeated tool calls against the same project reuse the connection and do not
|
|
186
|
+
re-authenticate each time.
|
|
187
|
+
- List tools default to `per_page=20` to keep a single call within a small
|
|
188
|
+
number of API requests.
|
|
189
|
+
- If you hit a `429 Too Many Requests`, the error handler returns an actionable
|
|
190
|
+
message — wait and try again with larger `per_page` or fewer calls.
|
|
191
|
+
|
|
192
|
+
## Self-hosted GitLab behind a corporate proxy
|
|
193
|
+
|
|
194
|
+
When your laptop has a local HTTP proxy (e.g. `http://127.0.0.1:3128` for corp web access) but GitLab is on the intranet, the proxy intercepts and kills internal requests. Two options:
|
|
195
|
+
|
|
196
|
+
1. Set `GITLAB_NO_PROXY_DOMAINS` — the server will add them to `NO_PROXY` at startup **and clear `HTTP_PROXY`/`HTTPS_PROXY` from its own process** so they don't affect GitLab traffic.
|
|
197
|
+
2. Pass explicitly empty `HTTP_PROXY=""` etc. in the MCP `env` section.
|
|
198
|
+
|
|
199
|
+
## Development
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
git clone https://github.com/mshegolev/gitlab-ci-mcp
|
|
203
|
+
cd gitlab-ci-mcp
|
|
204
|
+
python -m venv .venv && . .venv/bin/activate
|
|
205
|
+
pip install -e '.[dev]'
|
|
206
|
+
pytest
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Run the server directly (stdio transport, waits on stdin for MCP messages):
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
GITLAB_URL=... GITLAB_TOKEN=... GITLAB_PROJECT_PATH=... gitlab-ci-mcp
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
MIT — see [LICENSE](LICENSE).
|
|
218
|
+
|
|
219
|
+
## Acknowledgements
|
|
220
|
+
|
|
221
|
+
Built on [python-gitlab](https://github.com/python-gitlab/python-gitlab) and the [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk).
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# gitlab-ci-mcp
|
|
2
|
+
|
|
3
|
+
MCP server for GitLab CI/CD. Lets an LLM agent (Claude Code, Cursor, OpenCode, DevX Agent, etc.) work with pipelines, jobs, schedules, branches, tags, merge requests and repository files.
|
|
4
|
+
|
|
5
|
+
Python, [FastMCP](https://github.com/modelcontextprotocol/python-sdk), stdio transport.
|
|
6
|
+
|
|
7
|
+
Works with any GitLab — SaaS `gitlab.com` or self-hosted / on-prem. Designed with corporate networks in mind: configurable `NO_PROXY` handling, optional SSL-verify toggle, per-project scoping via env vars.
|
|
8
|
+
|
|
9
|
+
## Design highlights
|
|
10
|
+
|
|
11
|
+
- **Tool annotations** — every tool carries `readOnlyHint` / `destructiveHint` / `idempotentHint` / `openWorldHint` so MCP clients can classify operations (e.g. ask for confirmation only on destructive ones like `gitlab_merge_mr`, `gitlab_delete_schedule`).
|
|
12
|
+
- **Structured output on every tool** — each tool declares a TypedDict return type, so FastMCP auto-generates an `outputSchema` and every result carries `structuredContent` alongside a pre-rendered markdown text block. Clients that can render structured data use it; agents that prefer compact text get the markdown. No `response_format` parameter needed.
|
|
13
|
+
- **Structured errors** — authentication, 404, 403, 429 (rate-limit), 5xx, missing-env errors are converted to actionable `ToolError` messages (e.g. _"GitLab authentication failed… verify GITLAB_TOKEN has `api` scope"_) and surfaced as `isError=True` results.
|
|
14
|
+
- **Pydantic input validation** — every argument has typed constraints (ranges, lengths, literals) auto-exposed as JSON Schema.
|
|
15
|
+
- **Project scoping per call** — every tool accepts an optional `project_path` that overrides `GITLAB_PROJECT_PATH` for cross-project queries.
|
|
16
|
+
- **Pagination** — list tools return a `pagination` block with `page`, `total`, `has_more`, `next_page` and a next-page hint in the markdown footer.
|
|
17
|
+
- **MCP Context integration** — `gitlab_pipeline_health` and `gitlab_get_job_log` are `async` and emit `info` logs / `report_progress` events through the MCP Context so clients can show progress bars.
|
|
18
|
+
- **MCP Resources** — `gitlab://project/info` and `gitlab://project/ci-config` mirror common lookups for clients that prefer the Resource model over tools.
|
|
19
|
+
- **Lifespan management** — `python-gitlab` HTTP sessions are closed cleanly on server shutdown via an `asynccontextmanager` lifespan hook.
|
|
20
|
+
- **Log grep** — `gitlab_get_job_log` accepts `grep_pattern` + `grep_context` (surrounding lines) for regex-filtering megabyte-scale CI logs without pulling the whole trace into agent context.
|
|
21
|
+
|
|
22
|
+
### Threading model
|
|
23
|
+
|
|
24
|
+
FastMCP automatically runs synchronous tools in a worker thread
|
|
25
|
+
(`anyio.to_thread.run_sync`), so they do not block the asyncio event loop —
|
|
26
|
+
`python-gitlab` is a synchronous library and wrapping every call in
|
|
27
|
+
`asyncio.to_thread` ourselves would be ceremony. Tools that benefit from the
|
|
28
|
+
MCP Context (progress, info logs) are written as `async def` and explicitly
|
|
29
|
+
wrap `python-gitlab` calls with `asyncio.to_thread`.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
23 tools covering the everyday CI/CD surface:
|
|
34
|
+
|
|
35
|
+
**Pipelines**
|
|
36
|
+
`gitlab_list_pipelines` · `gitlab_get_pipeline` · `gitlab_get_pipeline_jobs` · `gitlab_get_job_log` · `gitlab_trigger_pipeline` · `gitlab_retry_pipeline` · `gitlab_cancel_pipeline` · `gitlab_pipeline_health`
|
|
37
|
+
|
|
38
|
+
**Schedules**
|
|
39
|
+
`gitlab_list_schedules` · `gitlab_create_schedule` · `gitlab_update_schedule` · `gitlab_delete_schedule`
|
|
40
|
+
|
|
41
|
+
**Branches & tags**
|
|
42
|
+
`gitlab_list_branches` · `gitlab_list_tags` · `gitlab_compare_branches`
|
|
43
|
+
|
|
44
|
+
**Merge requests**
|
|
45
|
+
`gitlab_list_merge_requests` · `gitlab_get_merge_request` · `gitlab_get_merge_request_changes` · `gitlab_create_merge_request` · `gitlab_merge_mr`
|
|
46
|
+
|
|
47
|
+
**Repository & project**
|
|
48
|
+
`gitlab_get_file` · `gitlab_list_repository_tree` · `gitlab_project_info`
|
|
49
|
+
|
|
50
|
+
### Pipeline health report
|
|
51
|
+
|
|
52
|
+
`gitlab_pipeline_health` returns a ready-to-read summary over 7/30 days:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
Last 7d: 96.4% up | 27/28 success
|
|
56
|
+
Last 30d: 92.1% | 105/114 success
|
|
57
|
+
Last 10: success success success failed success ...
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Handy for on-call / triage: `покажи health master за последние 7 дней`.
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
Requires Python 3.10+.
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# via uvx (recommended)
|
|
68
|
+
uvx --from gitlab-ci-mcp gitlab-ci-mcp
|
|
69
|
+
|
|
70
|
+
# or via pip/pipx
|
|
71
|
+
pipx install gitlab-ci-mcp
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Configuration
|
|
75
|
+
|
|
76
|
+
All config is via environment variables:
|
|
77
|
+
|
|
78
|
+
| Variable | Required | Description |
|
|
79
|
+
| --- | --- | --- |
|
|
80
|
+
| `GITLAB_URL` | **yes** | Base URL, e.g. `https://gitlab.example.com` |
|
|
81
|
+
| `GITLAB_TOKEN` | **yes** | Personal Access Token with `api` scope |
|
|
82
|
+
| `GITLAB_PROJECT_PATH` | **yes** | Default project, e.g. `my-org/my-repo` |
|
|
83
|
+
| `GITLAB_SSL_VERIFY` | no | `true` (default) / `false` |
|
|
84
|
+
| `GITLAB_NO_PROXY_DOMAINS` | no | Comma-separated domains to add to `NO_PROXY` (useful in corp networks behind a local HTTP proxy — e.g. `.corp.example.com,gitlab.internal`) |
|
|
85
|
+
|
|
86
|
+
Every tool accepts an optional `project_path` arg that overrides `GITLAB_PROJECT_PATH` per call — useful for cross-project queries.
|
|
87
|
+
|
|
88
|
+
## Claude Code
|
|
89
|
+
|
|
90
|
+
**Full walkthrough:** [docs/claude-code.md](docs/claude-code.md) — prerequisites, two install paths, multi-project setup, self-hosted GitLab behind a corp proxy, troubleshooting, uninstall.
|
|
91
|
+
|
|
92
|
+
Short version:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
claude mcp add gitlab uvx --from gitlab-ci-mcp gitlab-ci-mcp \
|
|
96
|
+
--env GITLAB_URL=https://gitlab.example.com \
|
|
97
|
+
--env GITLAB_TOKEN=glpat-xxxxxx \
|
|
98
|
+
--env GITLAB_PROJECT_PATH=my-org/my-repo
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Or in `~/.claude.json` / project `.mcp.json`:
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"mcpServers": {
|
|
106
|
+
"gitlab": {
|
|
107
|
+
"type": "stdio",
|
|
108
|
+
"command": "uvx",
|
|
109
|
+
"args": ["--from", "gitlab-ci-mcp", "gitlab-ci-mcp"],
|
|
110
|
+
"env": {
|
|
111
|
+
"GITLAB_URL": "https://gitlab.example.com",
|
|
112
|
+
"GITLAB_TOKEN": "${GITLAB_TOKEN}",
|
|
113
|
+
"GITLAB_PROJECT_PATH": "my-org/my-repo",
|
|
114
|
+
"GITLAB_SSL_VERIFY": "true"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Check:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
claude mcp list
|
|
125
|
+
# gitlab: uvx --from gitlab-ci-mcp gitlab-ci-mcp - ✓ Connected
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Cursor / OpenCode / DevX Agent
|
|
129
|
+
|
|
130
|
+
Same idea — point the MCP config to `uvx --from gitlab-ci-mcp gitlab-ci-mcp` with the env vars above. See each tool's own MCP config syntax.
|
|
131
|
+
|
|
132
|
+
## Example prompts
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
что сломалось в последнем pipeline master
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
покажи health master за 7 дней для проекта my-org/other-repo
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
создай MR из feature/foo в master с title "feat: foo"
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
покажи содержимое .gitlab-ci.yml из master
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Rate limits & connection reuse
|
|
151
|
+
|
|
152
|
+
GitLab enforces a per-user rate limit (typically 2000 req/h for the REST API,
|
|
153
|
+
configurable by the admin — see your instance's `/admin/application_settings/network`).
|
|
154
|
+
|
|
155
|
+
- The server caches one `python-gitlab` HTTP session **per `project_path`**, so
|
|
156
|
+
repeated tool calls against the same project reuse the connection and do not
|
|
157
|
+
re-authenticate each time.
|
|
158
|
+
- List tools default to `per_page=20` to keep a single call within a small
|
|
159
|
+
number of API requests.
|
|
160
|
+
- If you hit a `429 Too Many Requests`, the error handler returns an actionable
|
|
161
|
+
message — wait and try again with larger `per_page` or fewer calls.
|
|
162
|
+
|
|
163
|
+
## Self-hosted GitLab behind a corporate proxy
|
|
164
|
+
|
|
165
|
+
When your laptop has a local HTTP proxy (e.g. `http://127.0.0.1:3128` for corp web access) but GitLab is on the intranet, the proxy intercepts and kills internal requests. Two options:
|
|
166
|
+
|
|
167
|
+
1. Set `GITLAB_NO_PROXY_DOMAINS` — the server will add them to `NO_PROXY` at startup **and clear `HTTP_PROXY`/`HTTPS_PROXY` from its own process** so they don't affect GitLab traffic.
|
|
168
|
+
2. Pass explicitly empty `HTTP_PROXY=""` etc. in the MCP `env` section.
|
|
169
|
+
|
|
170
|
+
## Development
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
git clone https://github.com/mshegolev/gitlab-ci-mcp
|
|
174
|
+
cd gitlab-ci-mcp
|
|
175
|
+
python -m venv .venv && . .venv/bin/activate
|
|
176
|
+
pip install -e '.[dev]'
|
|
177
|
+
pytest
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Run the server directly (stdio transport, waits on stdin for MCP messages):
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
GITLAB_URL=... GITLAB_TOKEN=... GITLAB_PROJECT_PATH=... gitlab-ci-mcp
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## License
|
|
187
|
+
|
|
188
|
+
MIT — see [LICENSE](LICENSE).
|
|
189
|
+
|
|
190
|
+
## Acknowledgements
|
|
191
|
+
|
|
192
|
+
Built on [python-gitlab](https://github.com/python-gitlab/python-gitlab) and the [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk).
|