mcp-gitlab 0.25.2__tar.gz → 0.26.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.
Files changed (80) hide show
  1. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.claude-plugin/plugin.json +1 -1
  2. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.copier-answers.yml +1 -1
  3. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.github/workflows/link-check.yml +1 -1
  4. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.github/workflows/lint.yml +1 -1
  5. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.github/workflows/publish.yml +2 -2
  6. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.github/workflows/reconcile.yml +1 -1
  7. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.github/workflows/release.yml +1 -1
  8. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.github/workflows/tests.yml +1 -1
  9. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.mcp.json +1 -1
  10. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/AGENTS.md +18 -4
  11. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/CHANGELOG.md +16 -0
  12. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/Dockerfile +1 -1
  13. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/PKG-INFO +29 -4
  14. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/README.md +28 -3
  15. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/gemini-extension.json +14 -2
  16. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/llms-full.txt +1 -1
  17. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/llms.txt +1 -1
  18. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/pyproject.toml +1 -1
  19. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/server.json +31 -3
  20. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/__init__.py +25 -1
  21. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/servers/gitlab.py +84 -14
  22. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/conftest.py +2 -0
  23. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/test_toolsets.py +173 -3
  24. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/uv.lock +4 -4
  25. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.dockerignore +0 -0
  26. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.env.example +0 -0
  27. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  28. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  29. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.github/conformance-baseline.yml +0 -0
  30. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.github/conformance-env +0 -0
  31. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.github/dependabot.yml +0 -0
  32. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/.gitignore +0 -0
  33. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/LICENSE +0 -0
  34. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/assets/icon.svg +0 -0
  35. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/docs/oauth.md +0 -0
  36. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/docs/specs/2026-09-21-test-confidence-and-error-contract.md +0 -0
  37. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/evaluations/eval.xml +0 -0
  38. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/glama.json +0 -0
  39. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/ruff.toml +0 -0
  40. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/__main__.py +0 -0
  41. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/client.py +0 -0
  42. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/config.py +0 -0
  43. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/exceptions.py +0 -0
  44. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/local_auth.py +0 -0
  45. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/oauth.py +0 -0
  46. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/py.typed +0 -0
  47. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/resources/approval-workflow.md +0 -0
  48. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/resources/code-review.md +0 -0
  49. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/resources/codeowners.md +0 -0
  50. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/resources/conventional-commits.md +0 -0
  51. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/resources/git-workflow.md +0 -0
  52. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/resources/gitlab-ci.md +0 -0
  53. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/resources/mr-hygiene.md +0 -0
  54. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/resources/prompts/approve-mr.md +0 -0
  55. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/resources/prompts/diagnose-pipeline.md +0 -0
  56. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/resources/prompts/prepare-release.md +0 -0
  57. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/resources/prompts/review-mr.md +0 -0
  58. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/resources/prompts/setup-branch-protection.md +0 -0
  59. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/resources/prompts/triage-issues.md +0 -0
  60. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/servers/__init__.py +0 -0
  61. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/servers/_helpers.py +0 -0
  62. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/servers/prompts.py +0 -0
  63. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/src/mcp_gitlab/servers/resources.py +0 -0
  64. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/__init__.py +0 -0
  65. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/test_links.py +0 -0
  66. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/__init__.py +0 -0
  67. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/test_cli.py +0 -0
  68. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/test_client.py +0 -0
  69. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/test_config.py +0 -0
  70. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/test_exceptions.py +0 -0
  71. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/test_health.py +0 -0
  72. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/test_local_auth.py +0 -0
  73. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/test_oauth.py +0 -0
  74. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/test_oauth_http.py +0 -0
  75. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/test_prompts.py +0 -0
  76. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/test_read_only_lock.py +0 -0
  77. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/test_resources.py +0 -0
  78. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/test_server_assembly.py +0 -0
  79. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/test_tool_contract.py +0 -0
  80. {mcp_gitlab-0.25.2 → mcp_gitlab-0.26.0}/tests/unit/test_tools.py +0 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mcp-gitlab",
3
3
  "displayName": "GitLab",
4
- "version": "0.25.2",
4
+ "version": "0.26.0",
5
5
  "description": "GitLab MCP server (MCP 2026-07-28): projects, MRs, pipelines, CI/CD, issues; writes or read-only",
6
6
  "author": {
7
7
  "name": "vish288"
@@ -1,5 +1,5 @@
1
1
  # Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
2
- _commit: v1.6.2
2
+ _commit: v1.6.3
3
3
  _src_path: gh:vish288/.github
4
4
  conformance: true
5
5
  conformance_env: []
@@ -8,4 +8,4 @@ permissions:
8
8
  contents: read
9
9
  jobs:
10
10
  links:
11
- uses: vish288/.github/.github/workflows/link-check.yml@dc5dc3596ee1ad2931a147da13148c7b80437e24 # v1.6.2
11
+ uses: vish288/.github/.github/workflows/link-check.yml@565176949ef5dbf6d5dbeadf6a020b2df9c393cb # v1.6.3
@@ -5,4 +5,4 @@ permissions:
5
5
  contents: read
6
6
  jobs:
7
7
  lint:
8
- uses: vish288/.github/.github/workflows/lint.yml@dc5dc3596ee1ad2931a147da13148c7b80437e24 # v1.6.2
8
+ uses: vish288/.github/.github/workflows/lint.yml@565176949ef5dbf6d5dbeadf6a020b2df9c393cb # v1.6.3
@@ -30,7 +30,7 @@ permissions: {}
30
30
 
31
31
  jobs:
32
32
  prepare:
33
- uses: vish288/.github/.github/workflows/publish-prepare.yml@dc5dc3596ee1ad2931a147da13148c7b80437e24 # v1.6.2
33
+ uses: vish288/.github/.github/workflows/publish-prepare.yml@565176949ef5dbf6d5dbeadf6a020b2df9c393cb # v1.6.3
34
34
  with:
35
35
  dry_run: ${{ inputs.dry_run }}
36
36
  permissions:
@@ -68,7 +68,7 @@ jobs:
68
68
  finish:
69
69
  needs: [prepare, pypi]
70
70
  if: ${{ !cancelled() && !inputs.dry_run && (needs.prepare.outputs.pypi == 'done' || needs.pypi.result == 'success') }}
71
- uses: vish288/.github/.github/workflows/publish-finish.yml@dc5dc3596ee1ad2931a147da13148c7b80437e24 # v1.6.2
71
+ uses: vish288/.github/.github/workflows/publish-finish.yml@565176949ef5dbf6d5dbeadf6a020b2df9c393cb # v1.6.3
72
72
  with:
73
73
  dry_run: ${{ inputs.dry_run }}
74
74
  fail_at: ${{ inputs.fail_at }}
@@ -9,7 +9,7 @@ on:
9
9
  workflow_dispatch:
10
10
  jobs:
11
11
  reconcile:
12
- uses: vish288/.github/.github/workflows/reconcile.yml@dc5dc3596ee1ad2931a147da13148c7b80437e24 # v1.6.2
12
+ uses: vish288/.github/.github/workflows/reconcile.yml@565176949ef5dbf6d5dbeadf6a020b2df9c393cb # v1.6.3
13
13
  permissions:
14
14
  contents: read
15
15
  actions: write
@@ -27,7 +27,7 @@ on:
27
27
  default: none
28
28
  jobs:
29
29
  release:
30
- uses: vish288/.github/.github/workflows/release.yml@dc5dc3596ee1ad2931a147da13148c7b80437e24 # v1.6.2
30
+ uses: vish288/.github/.github/workflows/release.yml@565176949ef5dbf6d5dbeadf6a020b2df9c393cb # v1.6.3
31
31
  with:
32
32
  bump: ${{ inputs.bump }}
33
33
  version: ${{ inputs.version }}
@@ -5,7 +5,7 @@ permissions:
5
5
  contents: read
6
6
  jobs:
7
7
  test:
8
- uses: vish288/.github/.github/workflows/tests.yml@dc5dc3596ee1ad2931a147da13148c7b80437e24 # v1.6.2
8
+ uses: vish288/.github/.github/workflows/tests.yml@565176949ef5dbf6d5dbeadf6a020b2df9c393cb # v1.6.3
9
9
  with:
10
10
  coverage_min: 98
11
11
  service: mcp-gitlab
@@ -3,7 +3,7 @@
3
3
  "gitlab": {
4
4
  "command": "uvx",
5
5
  "args": [
6
- "mcp-gitlab@0.25.2"
6
+ "mcp-gitlab@0.26.0"
7
7
  ],
8
8
  "env": {
9
9
  "GITLAB_TOKEN": "${user_config.gitlab_token}",
@@ -44,7 +44,7 @@ emits OpenTelemetry spans for `tools/call` and propagates trace context by defau
44
44
  - **Local sign-in**: `src/mcp_gitlab/local_auth.py` — device and PKCE flows, credentials file, refresh under lock; used when no env token is set
45
45
  - **OAuth**: `src/mcp_gitlab/oauth.py` — `GitLabProvider` (a fastmcp `OAuthProxy` in front of GitLab) and `GitLabTokenVerifier` (validates a GitLab OAuth token via `GET /oauth/token/info`). Only used when `--auth oauth`
46
46
  - **Exceptions**: `src/mcp_gitlab/exceptions.py` — `GitLabError` base; `GitLabApiError`, `GitLabAuthError`, `GitLabNotFoundError`, `GitLabRateLimitError` (with `retry_after`), `GitLabTimeoutError`, `GitLabConnectionError`, `GitLabWriteDisabledError`
47
- - **Tests**: `tests/` — `unit/test_tools.py` (143 tool-level tests via the FastMCP in-memory client), plus `test_client.py`, `test_config.py`, `test_local_auth.py`, `test_exceptions.py`, `test_prompts.py`, `test_resources.py`, and `tests/test_links.py`. Shared fixtures (`config`, `client`, `mock_api` via respx) live in `tests/conftest.py`
47
+ - **Tests**: `tests/` — `unit/test_tools.py` (tool-level tests via the FastMCP in-memory client; the test count is whatever `uv run pytest -q` reports), plus `test_client.py`, `test_config.py`, `test_local_auth.py`, `test_exceptions.py`, `test_prompts.py`, `test_resources.py`, and `tests/test_links.py`. Shared fixtures (`config`, `client`, `mock_api` via respx) live in `tests/conftest.py`
48
48
 
49
49
  ## Development
50
50
 
@@ -112,9 +112,11 @@ sources (any locking one wins; a falsy value never unlocks and logs a WARNING; a
112
112
  value fails closed), and the lifespan calls `_lock_read_only(server)`, which
113
113
  `server.disable(tags={"write"})` so write tools and write-workflow prompts drop out of
114
114
  `tools/list`/`prompts/list` and `tools/call` on them returns "Unknown tool". The lock is
115
- computed once and never cleared; the only `enable` call in `src/` is the `MCP_TOOLSETS`
115
+ computed once and never cleared; the only `enable` call in `src/` is the `MCP_TOOLSETS` / `MCP_TOOLS`
116
116
  allowlist (`_apply_toolsets`), which runs before the lock and never names the `write` tag, so
117
- the lock stays the last word. The lock is unconditional on auth mode (oauth also hides by
117
+ the lock stays the last word. `_lock_read_only` appends its `disable` on every lifespan entry
118
+ (only the instructions sentence is added once), so a re-entered lifespan keeps the lock after the
119
+ fresh allowlist. The lock is unconditional on auth mode (oauth also hides by
118
120
  tag); the per-user `read_api` scope refusal in `_check_write` stays call-time. Every write
119
121
  tool MUST still call `_check_write(ctx)` (via `@tool_result(write=True)`, or inline as
120
122
  `gitlab_merge_mr_sequence` does) as defence in depth.
@@ -174,6 +176,16 @@ asserts every raw domain tag belongs to exactly one group and only those five to
174
176
  `review,ci` (46) and `code,review` (40) reach or pass Cursor's 40-tool warning; every single group
175
177
  stays under it.
176
178
 
179
+ `MCP_TOOLS` / `--tools` (include) and `MCP_EXCLUDE_TOOLS` / `--exclude-tools` (exclude) filter by
180
+ tool name, exactly as in `tools/list` (comma-separated, whitespace ignored, case-sensitive; unset
181
+ or empty means no filtering). Order: the `MCP_TOOLSETS` allowlist, intersected with `MCP_TOOLS`
182
+ (one `enable(tags=..., names=..., only=True)` carries both criteria), then `disable(names=...)` for
183
+ `MCP_EXCLUDE_TOOLS`, then the read-only lock. All of it lives in `_apply_toolsets`.
184
+ `validate_tool_selection` (CLI before `run_async`, and the lifespan) rejects an unknown name in
185
+ either list and a selection that leaves no tool listed, counting the read-only lock; both exit 2
186
+ (`ToolSelectionError`). A valid name already removed by the toolsets or read-only selection is
187
+ not an error. With both variables unset the server is untouched.
188
+
177
189
  ## Common Workflows
178
190
 
179
191
  - **Code review**: `gitlab_list_mrs` → `gitlab_mr_changes` → `gitlab_list_mr_discussions` → `gitlab_add_mr_note` or `gitlab_create_mr_discussion` → `gitlab_resolve_discussion`
@@ -208,6 +220,8 @@ plus an assistant acknowledgment.
208
220
  | `GITLAB_READ_ONLY` | no | `false` | Truthy (or unrecognised) locks the server read-only: the write tools are not listed and are refused before any API call |
209
221
  | `MCP_READ_ONLY` | no | `false` | Same as `GITLAB_READ_ONLY`; shared name across the mcp-* servers. Either being truthy locks read-only, and nothing turns it off at runtime |
210
222
  | `MCP_TOOLSETS` | no | all | Comma list of tool groups (`code`, `review`, `ci`, `issues`, `release`, `admin`); unset or `all` lists every tool. Validated at startup (unknown name exits 2); `MCP_READ_ONLY` applies after the selection |
223
+ | `MCP_TOOLS` | no | all | Comma list of tool names to keep, as in `tools/list`; narrows the `MCP_TOOLSETS` selection. Unknown name exits 2 |
224
+ | `MCP_EXCLUDE_TOOLS` | no | none | Comma list of tool names to drop, applied after `MCP_TOOLSETS` and `MCP_TOOLS`. Unknown name, or a selection that leaves no tools, exits 2 |
211
225
  | `GITLAB_TIMEOUT` | no | `30` | Request timeout in seconds |
212
226
  | `GITLAB_SSL_VERIFY` | no | `true` | `false`/`0`/`no` skips verification — self-signed certs only |
213
227
  | `GITLAB_AUTH` | no | `token` | `token` (PAT from env) or `oauth` (OAuth 2.1 proxy to GitLab; `streamable-http` only) |
@@ -224,7 +238,7 @@ The server reads the token from the first of `GITLAB_TOKEN`, `GITLAB_PAT`,
224
238
  `read_api` for read-only deployments. The server never persists an env token. Stored OAuth
225
239
  credentials live in `~/.config/mcp-gitlab/credentials.json`.
226
240
 
227
- CLI flags override env: `--gitlab-url`, `--read-only`, `--toolsets`, plus
241
+ CLI flags override env: `--gitlab-url`, `--read-only`, `--toolsets`, `--tools`, `--exclude-tools`, plus
228
242
  `--transport {stdio,sse,streamable-http}` with `--host` (default `127.0.0.1`) and `--port`
229
243
  (default `8000`); host/port apply only to non-stdio transports (`--gitlab-token` is deprecated
230
244
  and hidden from `--help`; it still works and warns on stderr — set `GITLAB_TOKEN` instead). The
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.26.0] - 2026-12-02
4
+
5
+ ### Features
6
+ - feat(config): filter tools by name with MCP_TOOLS and MCP_EXCLUDE_TOOLS (bd9feeb)
7
+
8
+ ### Bug Fixes
9
+ - fix: keep the read-only lock last when the lifespan is re-entered (ad495f5)
10
+
11
+ ### Documentation
12
+ - docs: drop hard-coded test count from AGENTS.md (80ce2b2)
13
+
14
+ ### Chores
15
+ - chore(deps): bump cachetools to 8.0.4 (76a1212)
16
+ - chore(fleet): template v1.6.3 (7d5f7ad)
17
+
18
+
3
19
  ## [0.25.2] - 2026-11-30
4
20
 
5
21
  ### Bug Fixes
@@ -14,7 +14,7 @@
14
14
  FROM python:3.13-slim
15
15
 
16
16
  # uv provides reproducible, frozen installs from uv.lock.
17
- COPY --from=ghcr.io/astral-sh/uv:0.13.7@sha256:96f40d3904aad8d0bd010539001d36c8e2188b981e1334471a90c4a1d93bb490 /uv /uvx /bin/
17
+ COPY --from=ghcr.io/astral-sh/uv:0.13.10@sha256:a3ea1357342c1a4bf9a0c53a3deb1b55379aefa037338d8113d5771efa01774f /uv /uvx /bin/
18
18
 
19
19
  ENV UV_COMPILE_BYTECODE=1 \
20
20
  UV_LINK_MODE=copy \
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: mcp-gitlab
3
- Version: 0.25.2
3
+ Version: 0.26.0
4
4
  Summary: GitLab MCP server for the MCP 2026-07-28 specification (MCP 2.0): projects, MRs, pipelines, CI/CD, approvals and issues for AI assistants. Runs with writes, or locked read-only via MCP_READ_ONLY
5
5
  Project-URL: Homepage, https://github.com/vish288/mcp-gitlab
6
6
  Project-URL: Repository, https://github.com/vish288/mcp-gitlab
@@ -170,6 +170,8 @@ Drop `MCP_READ_ONLY` to allow writes. On a shared or hosted server put it in the
170
170
  | `MCP_READ_ONLY` | No | `false` | Shared name across the mcp-* servers. Any value other than `false`/`0`/`no`/`off`/empty locks the server read-only: the 57 write tools and write-workflow prompts are not listed, and nothing can turn it back off at runtime |
171
171
  | `GITLAB_READ_ONLY` | No | `false` | Per-server alias for `MCP_READ_ONLY`; either one locks the server read-only. `--read-only` can only raise the lock |
172
172
  | `MCP_TOOLSETS` | No | all | Comma list of tool groups to expose (see Toolsets); unset or `all` lists every tool. `MCP_READ_ONLY` still applies after the selection |
173
+ | `MCP_TOOLS` | No | - | Comma list of tool names to expose, as in `tools/list` (see Toolsets); applied after `MCP_TOOLSETS`. Unset lists every tool the toolsets allow |
174
+ | `MCP_EXCLUDE_TOOLS` | No | - | Comma list of tool names to hide, as in `tools/list` (see Toolsets); applied after `MCP_TOOLSETS` and `MCP_TOOLS` |
173
175
  | `GITLAB_HTTP_BEARER_TOKEN` | No | - | Bearer token (min 16 chars) required to bind an HTTP transport to a non-loopback host; clients send `Authorization: Bearer <token>`; token mode only |
174
176
  | `GITLAB_TIMEOUT` | No | `30` | Request timeout in seconds |
175
177
  | `GITLAB_SSL_VERIFY` | No | `true` | Set to `false` to skip SSL verification |
@@ -211,6 +213,29 @@ MCP_TOOLSETS=issues,release uvx mcp-gitlab
211
213
 
212
214
  Resources and prompts are unaffected by the selection.
213
215
 
216
+ #### Individual tools
217
+
218
+ For a finer cut, `MCP_TOOLS` (or `--tools`) keeps only the named tools and `MCP_EXCLUDE_TOOLS`
219
+ (or `--exclude-tools`) hides the named ones. Both take comma-separated names exactly as they
220
+ appear in `tools/list` (whitespace around a name is ignored; unset or empty means no filtering).
221
+ The steps run in this order, each narrowing the last:
222
+
223
+ 1. the tools the `MCP_TOOLSETS` selection allows (all when unset);
224
+ 2. if `MCP_TOOLS` is set, only those names;
225
+ 3. minus every name in `MCP_EXCLUDE_TOOLS`;
226
+ 4. `MCP_READ_ONLY` then hides the write tools whatever the lists say.
227
+
228
+ A valid name that an earlier step already removed has no effect and is not an error. An unknown
229
+ name in either list, or a selection that leaves no tools, exits 2 with one line naming the
230
+ problem.
231
+
232
+ ```bash
233
+ # Review group without the merge button: 28 tools
234
+ MCP_TOOLSETS=review MCP_EXCLUDE_TOOLS=gitlab_merge_mr uvx mcp-gitlab
235
+ # Exactly two tools
236
+ MCP_TOOLS=gitlab_get_mr,gitlab_list_mrs uvx mcp-gitlab
237
+ ```
238
+
214
239
  ### Supported Token Types
215
240
 
216
241
  The server checks these environment variables in order — first match wins:
@@ -709,13 +734,13 @@ user, and defaults to locked read-only (`MCP_READ_ONLY=true`); override it to al
709
734
  # locked read-only (the image default) — stdio for an MCP client
710
735
  docker run --rm -i \
711
736
  -e GITLAB_URL=https://gitlab.example.com -e GITLAB_TOKEN=glpat-xxxxxxxxxxxxxxxxxxxx \
712
- ghcr.io/vish288/mcp-gitlab:0.25.2
737
+ ghcr.io/vish288/mcp-gitlab:0.26.0
713
738
 
714
739
  # allow writes: override the read-only default
715
740
  docker run --rm -i \
716
741
  -e MCP_READ_ONLY=false \
717
742
  -e GITLAB_URL=https://gitlab.example.com -e GITLAB_TOKEN=glpat-xxxxxxxxxxxxxxxxxxxx \
718
- ghcr.io/vish288/mcp-gitlab:0.25.2
743
+ ghcr.io/vish288/mcp-gitlab:0.26.0
719
744
  ```
720
745
 
721
746
  For an HTTP transport, append `--transport streamable-http --host 0.0.0.0`; a non-loopback bind in
@@ -725,7 +750,7 @@ Verify the build provenance before you run it. The attestation is signed by the
725
750
  publish workflow in `vish288/.github`, not by this repo, hence `--signer-repo`:
726
751
 
727
752
  ```bash
728
- gh attestation verify oci://ghcr.io/vish288/mcp-gitlab:0.25.2 -R vish288/mcp-gitlab --signer-repo vish288/.github
753
+ gh attestation verify oci://ghcr.io/vish288/mcp-gitlab:0.26.0 -R vish288/mcp-gitlab --signer-repo vish288/.github
729
754
  ```
730
755
 
731
756
  To build from source instead (uv, the committed `uv.lock`), run `docker build -t mcp-gitlab .` and
@@ -135,6 +135,8 @@ Drop `MCP_READ_ONLY` to allow writes. On a shared or hosted server put it in the
135
135
  | `MCP_READ_ONLY` | No | `false` | Shared name across the mcp-* servers. Any value other than `false`/`0`/`no`/`off`/empty locks the server read-only: the 57 write tools and write-workflow prompts are not listed, and nothing can turn it back off at runtime |
136
136
  | `GITLAB_READ_ONLY` | No | `false` | Per-server alias for `MCP_READ_ONLY`; either one locks the server read-only. `--read-only` can only raise the lock |
137
137
  | `MCP_TOOLSETS` | No | all | Comma list of tool groups to expose (see Toolsets); unset or `all` lists every tool. `MCP_READ_ONLY` still applies after the selection |
138
+ | `MCP_TOOLS` | No | - | Comma list of tool names to expose, as in `tools/list` (see Toolsets); applied after `MCP_TOOLSETS`. Unset lists every tool the toolsets allow |
139
+ | `MCP_EXCLUDE_TOOLS` | No | - | Comma list of tool names to hide, as in `tools/list` (see Toolsets); applied after `MCP_TOOLSETS` and `MCP_TOOLS` |
138
140
  | `GITLAB_HTTP_BEARER_TOKEN` | No | - | Bearer token (min 16 chars) required to bind an HTTP transport to a non-loopback host; clients send `Authorization: Bearer <token>`; token mode only |
139
141
  | `GITLAB_TIMEOUT` | No | `30` | Request timeout in seconds |
140
142
  | `GITLAB_SSL_VERIFY` | No | `true` | Set to `false` to skip SSL verification |
@@ -176,6 +178,29 @@ MCP_TOOLSETS=issues,release uvx mcp-gitlab
176
178
 
177
179
  Resources and prompts are unaffected by the selection.
178
180
 
181
+ #### Individual tools
182
+
183
+ For a finer cut, `MCP_TOOLS` (or `--tools`) keeps only the named tools and `MCP_EXCLUDE_TOOLS`
184
+ (or `--exclude-tools`) hides the named ones. Both take comma-separated names exactly as they
185
+ appear in `tools/list` (whitespace around a name is ignored; unset or empty means no filtering).
186
+ The steps run in this order, each narrowing the last:
187
+
188
+ 1. the tools the `MCP_TOOLSETS` selection allows (all when unset);
189
+ 2. if `MCP_TOOLS` is set, only those names;
190
+ 3. minus every name in `MCP_EXCLUDE_TOOLS`;
191
+ 4. `MCP_READ_ONLY` then hides the write tools whatever the lists say.
192
+
193
+ A valid name that an earlier step already removed has no effect and is not an error. An unknown
194
+ name in either list, or a selection that leaves no tools, exits 2 with one line naming the
195
+ problem.
196
+
197
+ ```bash
198
+ # Review group without the merge button: 28 tools
199
+ MCP_TOOLSETS=review MCP_EXCLUDE_TOOLS=gitlab_merge_mr uvx mcp-gitlab
200
+ # Exactly two tools
201
+ MCP_TOOLS=gitlab_get_mr,gitlab_list_mrs uvx mcp-gitlab
202
+ ```
203
+
179
204
  ### Supported Token Types
180
205
 
181
206
  The server checks these environment variables in order — first match wins:
@@ -674,13 +699,13 @@ user, and defaults to locked read-only (`MCP_READ_ONLY=true`); override it to al
674
699
  # locked read-only (the image default) — stdio for an MCP client
675
700
  docker run --rm -i \
676
701
  -e GITLAB_URL=https://gitlab.example.com -e GITLAB_TOKEN=glpat-xxxxxxxxxxxxxxxxxxxx \
677
- ghcr.io/vish288/mcp-gitlab:0.25.2
702
+ ghcr.io/vish288/mcp-gitlab:0.26.0
678
703
 
679
704
  # allow writes: override the read-only default
680
705
  docker run --rm -i \
681
706
  -e MCP_READ_ONLY=false \
682
707
  -e GITLAB_URL=https://gitlab.example.com -e GITLAB_TOKEN=glpat-xxxxxxxxxxxxxxxxxxxx \
683
- ghcr.io/vish288/mcp-gitlab:0.25.2
708
+ ghcr.io/vish288/mcp-gitlab:0.26.0
684
709
  ```
685
710
 
686
711
  For an HTTP transport, append `--transport streamable-http --host 0.0.0.0`; a non-loopback bind in
@@ -690,7 +715,7 @@ Verify the build provenance before you run it. The attestation is signed by the
690
715
  publish workflow in `vish288/.github`, not by this repo, hence `--signer-repo`:
691
716
 
692
717
  ```bash
693
- gh attestation verify oci://ghcr.io/vish288/mcp-gitlab:0.25.2 -R vish288/mcp-gitlab --signer-repo vish288/.github
718
+ gh attestation verify oci://ghcr.io/vish288/mcp-gitlab:0.26.0 -R vish288/mcp-gitlab --signer-repo vish288/.github
694
719
  ```
695
720
 
696
721
  To build from source instead (uv, the committed `uv.lock`), run `docker build -t mcp-gitlab .` and
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "mcp-gitlab",
3
- "version": "0.25.2",
3
+ "version": "0.26.0",
4
4
  "description": "GitLab MCP server (MCP 2026-07-28): projects, MRs, pipelines, CI/CD, issues; writes or read-only",
5
5
  "mcpServers": {
6
6
  "mcp-gitlab": {
7
7
  "command": "uvx",
8
8
  "args": [
9
- "mcp-gitlab@0.25.2"
9
+ "mcp-gitlab@0.26.0"
10
10
  ]
11
11
  }
12
12
  },
@@ -41,6 +41,18 @@
41
41
  "required": false,
42
42
  "sensitive": false
43
43
  },
44
+ {
45
+ "name": "MCP_TOOLS",
46
+ "description": "Comma list of tool names to expose, exactly as in tools/list (e.g. gitlab_get_mr,gitlab_list_mrs); unset lists every tool the toolsets allow. Applied after MCP_TOOLSETS; unknown names exit 2",
47
+ "required": false,
48
+ "sensitive": false
49
+ },
50
+ {
51
+ "name": "MCP_EXCLUDE_TOOLS",
52
+ "description": "Comma list of tool names to hide, exactly as in tools/list; applied after MCP_TOOLSETS and MCP_TOOLS. Unknown names, or a selection that leaves no tools, exit 2",
53
+ "required": false,
54
+ "sensitive": false
55
+ },
44
56
  {
45
57
  "name": "GITLAB_AUTH",
46
58
  "description": "Authentication mode: token (default) or oauth (OAuth 2.1 proxy; streamable-http only)",
@@ -5,7 +5,7 @@
5
5
  MCP server that wraps the GitLab REST API. Works with GitLab.com and self-hosted instances (CE/EE). No GitLab Duo or Premium required. Built with FastMCP, httpx, and Pydantic.
6
6
 
7
7
  - **Install**: `uvx mcp-gitlab`
8
- - **Version**: 0.25.2
8
+ - **Version**: 0.26.0
9
9
  - **Python**: >=3.11
10
10
  - **License**: MIT
11
11
  - **Protocol**: MCP 2026-07-28 (MCP 2.0); compatible with 2025-11-25 clients; built on FastMCP 4.x
@@ -5,7 +5,7 @@
5
5
  MCP server that wraps the GitLab REST API. Works with GitLab.com and self-hosted instances (CE/EE). No GitLab Duo or Premium required. Built with FastMCP, httpx, and Pydantic.
6
6
 
7
7
  - **Install**: `uvx mcp-gitlab`
8
- - **Version**: 0.25.2
8
+ - **Version**: 0.26.0
9
9
  - **Python**: >=3.11
10
10
  - **License**: MIT
11
11
  - **Protocol**: MCP 2026-07-28 (MCP 2.0); compatible with 2025-11-25 clients; built on FastMCP 4.x
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mcp-gitlab"
3
- version = "0.25.2"
3
+ version = "0.26.0"
4
4
  description = "GitLab MCP server for the MCP 2026-07-28 specification (MCP 2.0): projects, MRs, pipelines, CI/CD, approvals and issues for AI assistants. Runs with writes, or locked read-only via MCP_READ_ONLY"
5
5
  readme = "README.md"
6
6
  license = {text = "MIT"}
@@ -7,7 +7,7 @@
7
7
  "url": "https://github.com/vish288/mcp-gitlab",
8
8
  "source": "github"
9
9
  },
10
- "version": "0.25.2",
10
+ "version": "0.26.0",
11
11
  "websiteUrl": "https://vish288.github.io/mcp-install?server=mcp-gitlab",
12
12
  "icons": [
13
13
  {
@@ -22,7 +22,7 @@
22
22
  {
23
23
  "registryType": "pypi",
24
24
  "identifier": "mcp-gitlab",
25
- "version": "0.25.2",
25
+ "version": "0.26.0",
26
26
  "runtimeHint": "uvx",
27
27
  "transport": {
28
28
  "type": "stdio"
@@ -63,6 +63,20 @@
63
63
  "format": "string",
64
64
  "isSecret": false
65
65
  },
66
+ {
67
+ "name": "MCP_TOOLS",
68
+ "description": "Comma list of tool names to expose, exactly as in tools/list (e.g. gitlab_get_mr,gitlab_list_mrs); unset lists every tool the toolsets allow. Applied after MCP_TOOLSETS; unknown names exit 2",
69
+ "isRequired": false,
70
+ "format": "string",
71
+ "isSecret": false
72
+ },
73
+ {
74
+ "name": "MCP_EXCLUDE_TOOLS",
75
+ "description": "Comma list of tool names to hide, exactly as in tools/list; applied after MCP_TOOLSETS and MCP_TOOLS. Unknown names, or a selection that leaves no tools, exit 2",
76
+ "isRequired": false,
77
+ "format": "string",
78
+ "isSecret": false
79
+ },
66
80
  {
67
81
  "name": "GITLAB_AUTH",
68
82
  "description": "Authentication mode: token (default) or oauth (OAuth 2.1 proxy; streamable-http only)",
@@ -116,7 +130,7 @@
116
130
  },
117
131
  {
118
132
  "registryType": "oci",
119
- "identifier": "ghcr.io/vish288/mcp-gitlab:0.25.2",
133
+ "identifier": "ghcr.io/vish288/mcp-gitlab:0.26.0",
120
134
  "transport": {
121
135
  "type": "stdio"
122
136
  },
@@ -156,6 +170,20 @@
156
170
  "format": "string",
157
171
  "isSecret": false
158
172
  },
173
+ {
174
+ "name": "MCP_TOOLS",
175
+ "description": "Comma list of tool names to expose, exactly as in tools/list (e.g. gitlab_get_mr,gitlab_list_mrs); unset lists every tool the toolsets allow. Applied after MCP_TOOLSETS; unknown names exit 2",
176
+ "isRequired": false,
177
+ "format": "string",
178
+ "isSecret": false
179
+ },
180
+ {
181
+ "name": "MCP_EXCLUDE_TOOLS",
182
+ "description": "Comma list of tool names to hide, exactly as in tools/list; applied after MCP_TOOLSETS and MCP_TOOLS. Unknown names, or a selection that leaves no tools, exit 2",
183
+ "isRequired": false,
184
+ "format": "string",
185
+ "isSecret": false
186
+ },
159
187
  {
160
188
  "name": "GITLAB_AUTH",
161
189
  "description": "Authentication mode: token (default) or oauth (OAuth 2.1 proxy; streamable-http only)",
@@ -107,6 +107,16 @@ def _apply_token_http_auth(mcp: Any, host: str) -> None:
107
107
  help="Comma list of tool groups to expose "
108
108
  "(code, review, ci, issues, release, admin; default: all)",
109
109
  )
110
+ @click.option(
111
+ "--tools",
112
+ envvar="MCP_TOOLS",
113
+ help="Comma list of tool names to expose, as in tools/list (default: all the toolsets allow)",
114
+ )
115
+ @click.option(
116
+ "--exclude-tools",
117
+ envvar="MCP_EXCLUDE_TOOLS",
118
+ help="Comma list of tool names to hide, as in tools/list; applied after --tools",
119
+ )
110
120
  @click.option(
111
121
  "--auth",
112
122
  type=click.Choice(["token", "oauth"]),
@@ -124,6 +134,8 @@ def main(
124
134
  gitlab_token: str | None,
125
135
  read_only: bool,
126
136
  toolsets: str | None,
137
+ tools: str | None,
138
+ exclude_tools: str | None,
127
139
  auth: str,
128
140
  ) -> None:
129
141
  """Run the GitLab MCP server. Subcommands: auth."""
@@ -147,6 +159,10 @@ def main(
147
159
  # of the startup config so an unknown group is one clear line and exit 2.
148
160
  if toolsets:
149
161
  os.environ["MCP_TOOLSETS"] = toolsets
162
+ if tools:
163
+ os.environ["MCP_TOOLS"] = tools
164
+ if exclude_tools:
165
+ os.environ["MCP_EXCLUDE_TOOLS"] = exclude_tools
150
166
  os.environ["GITLAB_AUTH"] = auth
151
167
 
152
168
  if auth == "oauth" and transport != "streamable-http":
@@ -170,7 +186,7 @@ def main(
170
186
 
171
187
  from .config import GitLabConfig
172
188
  from .servers import prompts, resources # noqa: F401 — registers decorators
173
- from .servers.gitlab import mcp, parse_toolsets
189
+ from .servers.gitlab import mcp, parse_toolsets, validate_tool_selection
174
190
 
175
191
  # Validate configuration before run_async so a bad config is one clear
176
192
  # `Error:` line + exit 2, not a traceback from inside the lifespan (D7).
@@ -198,6 +214,14 @@ def main(
198
214
  cfg.credentials = _SIGNED_IN
199
215
  cfg.validate()
200
216
  parse_toolsets(os.getenv("MCP_TOOLSETS"))
217
+ if os.getenv("MCP_TOOLS") or os.getenv("MCP_EXCLUDE_TOOLS"):
218
+ validate_tool_selection(
219
+ asyncio.run(mcp.local_provider.list_tools()),
220
+ os.getenv("MCP_TOOLSETS"),
221
+ os.getenv("MCP_TOOLS"),
222
+ os.getenv("MCP_EXCLUDE_TOOLS"),
223
+ read_only=cfg.read_only,
224
+ )
201
225
  except ValueError as e:
202
226
  click.echo(f"Error: {e}", err=True)
203
227
  ctx.exit(2)
@@ -9,7 +9,7 @@ import json
9
9
  import logging
10
10
  import os
11
11
  import re
12
- from collections.abc import AsyncIterator, Awaitable, Callable
12
+ from collections.abc import AsyncIterator, Awaitable, Callable, Sequence
13
13
  from contextlib import asynccontextmanager
14
14
  from importlib.metadata import version
15
15
  from typing import Annotated, Any, Literal
@@ -20,7 +20,7 @@ import httpx
20
20
  from fastmcp import Context, FastMCP
21
21
  from fastmcp.exceptions import ToolError
22
22
  from fastmcp.server.dependencies import get_access_token
23
- from fastmcp.tools import ToolResult
23
+ from fastmcp.tools import Tool, ToolResult
24
24
  from mcp.types import Icon, TextContent
25
25
  from pydantic import Field
26
26
  from starlette.requests import Request
@@ -77,12 +77,13 @@ def _lock_read_only(server: FastMCP, *, sources: list[str] | None = None) -> Non
77
77
  code only, and this server never calls them (a src-scan test enforces that). The lock
78
78
  is unconditional on auth mode (oauth also hides by tag); the per-user ``read_api`` scope
79
79
  refusal in ``_check_write`` stays call-time. ``_check_write`` itself stays as defence in
80
- depth. Idempotent off the appended instructions sentence so a re-entered lifespan (tests)
81
- does not stack transforms — no separate module flag to reset.
80
+ depth. The ``disable`` is appended on every call, so a re-entered lifespan puts it after
81
+ the fresh ``_apply_toolsets`` allowlist (a later transform wins); a duplicate ``disable`` is
82
+ harmless. Only the instructions sentence is added once, keyed off its own text.
82
83
  """
84
+ server.disable(tags={"write"})
83
85
  if _LOCK_SUFFIX in (server.instructions or ""):
84
86
  return
85
- server.disable(tags={"write"})
86
87
  server.instructions = (server.instructions or "") + _LOCK_SUFFIX
87
88
  named = f" ({', '.join(sources)})" if sources else ""
88
89
  _log.info("read-only: LOCKED%s — write tools and prompts hidden", named)
@@ -132,20 +133,77 @@ def parse_toolsets(raw: str | None) -> set[str] | None:
132
133
  return tags
133
134
 
134
135
 
135
- def _apply_toolsets(server: FastMCP, raw: str | None) -> None:
136
- """Allowlist tools for the selected toolsets, keeping every resource and prompt.
136
+ class ToolSelectionError(ValueError):
137
+ """MCP_TOOLS / MCP_EXCLUDE_TOOLS named an unknown tool, or the selection lists no tool."""
138
+
139
+
140
+ def parse_tool_names(raw: str | None) -> set[str]:
141
+ """Split MCP_TOOLS / MCP_EXCLUDE_TOOLS: comma-separated, trimmed, case-sensitive, no blanks."""
142
+ return {n.strip() for n in (raw or "").split(",") if n.strip()}
137
143
 
138
- fastmcp 4.1.6: ``enable(tags=..., only=True)`` switches to allowlist mode over *all*
144
+
145
+ def validate_tool_selection(
146
+ tools: Sequence[Tool],
147
+ toolsets: str | None,
148
+ include: str | None,
149
+ exclude: str | None,
150
+ *,
151
+ read_only: bool,
152
+ ) -> None:
153
+ """Startup check for MCP_TOOLSETS + MCP_TOOLS + MCP_EXCLUDE_TOOLS.
154
+
155
+ Raises ``UnknownToolsetError`` / ``ToolSelectionError`` (both ``ValueError``) for an
156
+ unknown group, an unknown tool name in either list, or a selection that leaves no tool
157
+ listed. A valid name that the toolsets or read-only selection already removes is not an
158
+ error: it just has no effect, as ``_apply_toolsets`` composes the three by intersection.
159
+ """
160
+ tags = parse_toolsets(toolsets)
161
+ inc, exc = parse_tool_names(include), parse_tool_names(exclude)
162
+ if not inc and not exc:
163
+ return
164
+ known = {t.name for t in tools}
165
+ for var, names in (("MCP_TOOLS", inc), ("MCP_EXCLUDE_TOOLS", exc)):
166
+ if unknown := sorted(names - known):
167
+ msg = f"Unknown {var} tool name(s): {', '.join(unknown)} (names as in tools/list)"
168
+ raise ToolSelectionError(msg)
169
+ if not any(
170
+ (tags is None or t.tags & tags)
171
+ and (not inc or t.name in inc)
172
+ and t.name not in exc
173
+ and not (read_only and "write" in t.tags)
174
+ for t in tools
175
+ ):
176
+ msg = "MCP_TOOLSETS / MCP_TOOLS / MCP_EXCLUDE_TOOLS / read-only leave no tools listed"
177
+ raise ToolSelectionError(msg)
178
+
179
+
180
+ def _apply_toolsets(
181
+ server: FastMCP,
182
+ raw: str | None,
183
+ include: str | None = None,
184
+ exclude: str | None = None,
185
+ ) -> None:
186
+ """Allowlist tools for the selected toolsets and tool names, keeping resources and prompts.
187
+
188
+ Order: the toolsets allowlist, intersected with ``MCP_TOOLS`` when set (one ``enable``
189
+ carrying both criteria matches their intersection), then ``MCP_EXCLUDE_TOOLS`` removes
190
+ names (a later ``disable`` wins).
191
+
192
+ fastmcp 4.1.6: ``enable(..., only=True)`` switches to allowlist mode over *all*
139
193
  component types, so resources and prompts would vanish; the chained
140
194
  ``enable(components=...)`` re-lists every resource/template/prompt. This runs before the
141
195
  read-only ``disable(tags={"write"})`` so the lock stays the last word — an allowlisted
142
- group still carries its write tools until the lock removes them. A no-op when no toolset
143
- is selected, so the default server is untouched.
196
+ group still carries its write tools until the lock removes them. A no-op when nothing is
197
+ selected, so the default server is untouched.
144
198
  """
145
199
  tags = parse_toolsets(raw)
146
- if tags is None:
147
- return
148
- server.enable(tags=tags, only=True).enable(components={"resource", "template", "prompt"})
200
+ inc, exc = parse_tool_names(include), parse_tool_names(exclude)
201
+ if tags is not None or inc:
202
+ server.enable(
203
+ tags=tags, names=inc or None, components={"tool"} if inc else None, only=True
204
+ ).enable(components={"resource", "template", "prompt"})
205
+ if exc:
206
+ server.disable(names=exc, components={"tool"})
149
207
 
150
208
 
151
209
  @asynccontextmanager
@@ -160,7 +218,19 @@ async def lifespan(server: FastMCP) -> AsyncIterator[dict[str, Any]]:
160
218
  config.validate()
161
219
  pkg_version = version("mcp-gitlab")
162
220
  _log.info("mcp-gitlab %s starting", pkg_version)
163
- _apply_toolsets(server, os.getenv("MCP_TOOLSETS"))
221
+ toolsets, include, exclude = (
222
+ os.getenv("MCP_TOOLSETS"),
223
+ os.getenv("MCP_TOOLS"),
224
+ os.getenv("MCP_EXCLUDE_TOOLS"),
225
+ )
226
+ validate_tool_selection(
227
+ await server.local_provider.list_tools(),
228
+ toolsets,
229
+ include,
230
+ exclude,
231
+ read_only=config.read_only,
232
+ )
233
+ _apply_toolsets(server, toolsets, include, exclude)
164
234
  if config.read_only:
165
235
  _log.info("GitLab: %s", config.url)
166
236
  _lock_read_only(server, sources=read_only_sources("GITLAB_READ_ONLY"))
@@ -34,6 +34,8 @@ def _no_ambient_read_only(monkeypatch: pytest.MonkeyPatch) -> None:
34
34
  monkeypatch.delenv("MCP_READ_ONLY", raising=False)
35
35
  monkeypatch.delenv("GITLAB_READ_ONLY", raising=False)
36
36
  monkeypatch.delenv("MCP_TOOLSETS", raising=False)
37
+ monkeypatch.delenv("MCP_TOOLS", raising=False)
38
+ monkeypatch.delenv("MCP_EXCLUDE_TOOLS", raising=False)
37
39
 
38
40
 
39
41
  @pytest.fixture
@@ -23,9 +23,11 @@ from mcp_gitlab import main
23
23
  from mcp_gitlab.servers import prompts, resources # noqa: F401 — registers decorators
24
24
  from mcp_gitlab.servers.gitlab import (
25
25
  TOOLSET_GROUPS,
26
+ ToolSelectionError,
26
27
  UnknownToolsetError,
27
28
  mcp,
28
29
  parse_toolsets,
30
+ validate_tool_selection,
29
31
  )
30
32
 
31
33
  # Non-domain tags every tool carries; the remainder is its one or two domain tags.
@@ -57,10 +59,16 @@ _PROMPTS = 6
57
59
 
58
60
 
59
61
  async def _boot(
60
- monkeypatch, toolsets: str | None, *, read_only: bool = False
62
+ monkeypatch,
63
+ toolsets: str | None,
64
+ *,
65
+ read_only: bool = False,
66
+ tools: str | None = None,
67
+ exclude: str | None = None,
61
68
  ) -> tuple[set[str], int, int]:
62
- """Boot ``mcp`` through a real client with the given MCP_TOOLSETS / MCP_READ_ONLY env and
63
- return (tool names, resource count, prompt count), restoring visibility afterwards."""
69
+ """Boot ``mcp`` through a real client with the given MCP_TOOLSETS / MCP_TOOLS /
70
+ MCP_EXCLUDE_TOOLS / MCP_READ_ONLY env and return (tool names, resource count, prompt
71
+ count), restoring visibility afterwards."""
64
72
  monkeypatch.setenv("GITLAB_URL", "https://gitlab.example.com")
65
73
  monkeypatch.setenv("GITLAB_TOKEN", "test-token")
66
74
  monkeypatch.delenv("GITLAB_READ_ONLY", raising=False)
@@ -68,6 +76,10 @@ async def _boot(
68
76
  monkeypatch.delenv("MCP_TOOLSETS", raising=False)
69
77
  if toolsets is not None:
70
78
  monkeypatch.setenv("MCP_TOOLSETS", toolsets)
79
+ if tools is not None:
80
+ monkeypatch.setenv("MCP_TOOLS", tools)
81
+ if exclude is not None:
82
+ monkeypatch.setenv("MCP_EXCLUDE_TOOLS", exclude)
71
83
  if read_only:
72
84
  monkeypatch.setenv("MCP_READ_ONLY", "true")
73
85
  tx = len(mcp._transforms)
@@ -190,3 +202,161 @@ def test_cli_unknown_toolset_exits_2():
190
202
  assert result.exit_code == 2
191
203
  assert "bogus" in result.output
192
204
  assert "code" in result.output
205
+
206
+
207
+ # ── MCP_TOOLS / MCP_EXCLUDE_TOOLS: filtering by tool name (workbench-backlog#80) ──────
208
+ #
209
+ # Order: the MCP_TOOLSETS selection, narrowed to MCP_TOOLS when set, minus MCP_EXCLUDE_TOOLS;
210
+ # MCP_READ_ONLY still hides write tools last. A valid name the earlier steps already removed
211
+ # has no effect. An unknown name, or a selection that lists no tool, exits 2.
212
+
213
+ _GET_MR, _LIST_MRS, _MERGE_MR = "gitlab_get_mr", "gitlab_list_mrs", "gitlab_merge_mr"
214
+ _GET_ISSUE, _CREATE_ISSUE = "gitlab_get_issue", "gitlab_create_issue"
215
+
216
+
217
+ async def test_tools_include_only(monkeypatch):
218
+ tools, res, prm = await _boot(monkeypatch, None, tools=f" {_GET_MR} , {_LIST_MRS} ,")
219
+ assert tools == {_GET_MR, _LIST_MRS}
220
+ assert (res, prm) == (_RESOURCES, _PROMPTS)
221
+
222
+
223
+ async def test_exclude_only(monkeypatch):
224
+ tools, res, prm = await _boot(monkeypatch, None, exclude=f"{_GET_MR}, {_MERGE_MR}")
225
+ assert len(tools) == _ALL_TOOLS - 2
226
+ assert not tools & {_GET_MR, _MERGE_MR}
227
+ assert (res, prm) == (_RESOURCES, _PROMPTS)
228
+
229
+
230
+ async def test_include_and_exclude_exclude_wins(monkeypatch):
231
+ tools, _, _ = await _boot(
232
+ monkeypatch,
233
+ None,
234
+ tools=f"{_GET_MR},{_LIST_MRS},{_MERGE_MR}",
235
+ exclude=f"{_LIST_MRS},{_MERGE_MR}",
236
+ )
237
+ assert tools == {_GET_MR}
238
+
239
+
240
+ async def test_tools_narrow_toolsets_to_the_intersection(monkeypatch):
241
+ """_GET_MR is valid but outside `issues`, so it has no effect (not an error)."""
242
+ tools, res, prm = await _boot(monkeypatch, "issues", tools=f"{_GET_ISSUE},{_GET_MR}")
243
+ assert tools == {_GET_ISSUE}
244
+ assert (res, prm) == (_RESOURCES, _PROMPTS)
245
+
246
+
247
+ async def test_exclude_trims_toolsets(monkeypatch):
248
+ tools, _, _ = await _boot(monkeypatch, "issues", exclude=f"{_CREATE_ISSUE},{_GET_MR}")
249
+ assert len(tools) == _EXPECTED["issues"][0] - 1
250
+ assert _CREATE_ISSUE not in tools
251
+
252
+
253
+ async def test_tools_with_read_only_still_hides_writes(monkeypatch):
254
+ tools, _, _ = await _boot(
255
+ monkeypatch, None, tools=f"{_GET_ISSUE},{_CREATE_ISSUE}", read_only=True
256
+ )
257
+ assert tools == {_GET_ISSUE}
258
+
259
+
260
+ @pytest.mark.parametrize(
261
+ ("toolsets", "tools"),
262
+ [(None, f"{_GET_ISSUE},{_CREATE_ISSUE}"), ("issues", None)],
263
+ ids=["MCP_TOOLS", "MCP_TOOLSETS"],
264
+ )
265
+ async def test_read_only_survives_a_re_entered_lifespan(monkeypatch, toolsets, tools):
266
+ """Entering the lifespan twice on one server must not let the second allowlist land after
267
+ the first read-only disable: the lock is re-appended last on every entry."""
268
+ monkeypatch.setenv("GITLAB_URL", "https://gitlab.example.com")
269
+ monkeypatch.setenv("GITLAB_TOKEN", "test-token")
270
+ monkeypatch.setenv("MCP_READ_ONLY", "true")
271
+ for var, value in (("MCP_TOOLSETS", toolsets), ("MCP_TOOLS", tools)):
272
+ if value is None:
273
+ monkeypatch.delenv(var, raising=False)
274
+ else:
275
+ monkeypatch.setenv(var, value)
276
+ tx = len(mcp._transforms)
277
+ instructions = mcp.instructions
278
+ try:
279
+ for _ in range(2):
280
+ async with Client(mcp) as client:
281
+ listed = {t.name for t in await client.list_tools()}
282
+ assert _GET_ISSUE in listed
283
+ assert _CREATE_ISSUE not in listed
284
+ write_names = {t.name for t in await _registered_tools() if "write" in t.tags}
285
+ assert not listed & write_names
286
+ finally:
287
+ del mcp._transforms[tx:]
288
+ mcp.instructions = instructions
289
+
290
+
291
+ async def test_blank_name_lists_change_nothing(monkeypatch):
292
+ """Unset, empty and separator-only values: every tool listed, in the same order."""
293
+ names = []
294
+ for tools_env, exclude_env in [(None, None), ("", ""), (" ", " , ")]:
295
+ monkeypatch.setenv("GITLAB_URL", "https://gitlab.example.com")
296
+ monkeypatch.setenv("GITLAB_TOKEN", "test-token")
297
+ for var, value in (("MCP_TOOLS", tools_env), ("MCP_EXCLUDE_TOOLS", exclude_env)):
298
+ if value is None:
299
+ monkeypatch.delenv(var, raising=False)
300
+ else:
301
+ monkeypatch.setenv(var, value)
302
+ tx = len(mcp._transforms)
303
+ try:
304
+ async with Client(mcp) as client:
305
+ names.append([t.name for t in await client.list_tools()])
306
+ finally:
307
+ del mcp._transforms[tx:]
308
+ assert len(names[0]) == _ALL_TOOLS
309
+ assert names[0] == names[1] == names[2]
310
+
311
+
312
+ async def _registered_tools():
313
+ return await mcp.local_provider.list_tools()
314
+
315
+
316
+ @pytest.mark.parametrize(
317
+ ("include", "exclude", "bad"),
318
+ [("gitlab_nope", None, "gitlab_nope"), (None, f"{_GET_MR}, gitlab_gone", "gitlab_gone")],
319
+ )
320
+ async def test_validate_unknown_name_raises_naming_it(include, exclude, bad):
321
+ with pytest.raises(ToolSelectionError) as exc:
322
+ validate_tool_selection(await _registered_tools(), None, include, exclude, read_only=False)
323
+ assert bad in str(exc.value)
324
+ assert _GET_MR not in str(exc.value)
325
+
326
+
327
+ async def test_validate_empty_selection_raises():
328
+ tools = await _registered_tools()
329
+ every = ",".join(t.name for t in tools)
330
+ for kwargs in (
331
+ {"toolsets": "issues", "include": _GET_MR, "exclude": None, "read_only": False},
332
+ {"toolsets": None, "include": None, "exclude": every, "read_only": False},
333
+ {"toolsets": None, "include": _CREATE_ISSUE, "exclude": None, "read_only": True},
334
+ ):
335
+ with pytest.raises(ToolSelectionError, match="no tools"):
336
+ validate_tool_selection(tools, **kwargs)
337
+
338
+
339
+ async def test_validate_valid_selection_passes():
340
+ validate_tool_selection(
341
+ await _registered_tools(), "issues", f"{_GET_ISSUE},{_GET_MR}", None, read_only=True
342
+ )
343
+
344
+
345
+ @pytest.mark.parametrize(
346
+ ("argv", "expected"),
347
+ [
348
+ (["--tools", f"{_GET_MR},bogus_tool"], "bogus_tool"),
349
+ (["--exclude-tools", "other_bogus"], "other_bogus"),
350
+ (["--toolsets", "issues", "--tools", _GET_MR], "no tools"),
351
+ (["--read-only", "--tools", _CREATE_ISSUE], "no tools"),
352
+ ],
353
+ )
354
+ def test_cli_bad_tool_selection_exits_2(argv, expected):
355
+ with patch.dict(
356
+ "os.environ",
357
+ {"GITLAB_URL": "https://gitlab.example.com", "GITLAB_TOKEN": "t"},
358
+ clear=False,
359
+ ):
360
+ result = CliRunner().invoke(main, argv)
361
+ assert result.exit_code == 2
362
+ assert expected in result.output
@@ -63,11 +63,11 @@ wheels = [
63
63
 
64
64
  [[package]]
65
65
  name = "cachetools"
66
- version = "7.3.0"
66
+ version = "8.0.4"
67
67
  source = { registry = "https://pypi.org/simple" }
68
- sdist = { url = "https://files.pythonhosted.org/packages/5f/6b/6c1553e1e8f672f9423344a1915aad1537439ad3d14a3fbc1a02159cfd94/cachetools-7.3.0.tar.gz", hash = "sha256:3f63fc208410f0c3a3b37883c4903ecdacd6f0b259134e6d2e82debd5b2e01de", size = 48563, upload-time = "2026-11-05T20:38:46.434Z" }
68
+ sdist = { url = "https://files.pythonhosted.org/packages/23/c0/8b8604ddbcc52916e4ee0753b921376d8f56eb7788ed08c0e204a1beda1a/cachetools-8.0.4.tar.gz", hash = "sha256:ce520d6f857f34d792847328f1a55f567650c34f86be6a99ba720330f14b9abd", size = 54309, upload-time = "2026-11-29T21:22:47.518Z" }
69
69
  wheels = [
70
- { url = "https://files.pythonhosted.org/packages/29/aa/e54a49d0927b2fa7b86bc94dbde57125e38e8cfca7a31b6764e8dbf35e9f/cachetools-7.3.0-py3-none-any.whl", hash = "sha256:2105787c94619bde7072624fec0fe7b8a08bb7bf6c757c318f8925573c6f07c9", size = 19575, upload-time = "2026-11-05T20:38:44.928Z" },
70
+ { url = "https://files.pythonhosted.org/packages/d8/ba/8185433edc823452ffd60e89ebdcb74c7b9279a7c897e4efff5f60dbc7cd/cachetools-8.0.4-py3-none-any.whl", hash = "sha256:848260eb4bd6dd7da26989f087080d8f08a745b1d3a6e1a27f64f0efe11a9a26", size = 19664, upload-time = "2026-11-29T21:22:46.083Z" },
71
71
  ]
72
72
 
73
73
  [[package]]
@@ -764,7 +764,7 @@ wheels = [
764
764
 
765
765
  [[package]]
766
766
  name = "mcp-gitlab"
767
- version = "0.25.2"
767
+ version = "0.26.0"
768
768
  source = { editable = "." }
769
769
  dependencies = [
770
770
  { name = "click" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes