@zereight/mcp-gitlab 2.1.69 → 2.2.0
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.
- package/README.ko.md +10 -4
- package/README.md +238 -233
- package/README.pt-BR.md +4 -4
- package/README.zh-CN.md +6 -4
- package/build/config.js +12 -4
- package/build/deprecated-env.js +47 -0
- package/build/index.js +456 -237
- package/build/oauth-device-flow.js +80 -0
- package/build/oauth.js +135 -18
- package/build/schemas.js +1 -1
- package/build/server/remote-http-stack.js +39 -0
- package/build/tools/discover-activation.js +38 -0
- package/build/tools/exposed-tools.js +35 -0
- package/build/tools/listed-tools.js +76 -0
- package/build/tools/registry.js +226 -57
- package/build/tools/tool-profile.js +66 -0
- package/build/utils/compact-tool-allowlist.js +14 -0
- package/build/utils/logger.js +34 -12
- package/build/utils/url.js +15 -0
- package/package.json +3 -3
- package/build/scripts/check-skill-sync.js +0 -143
- package/build/scripts/generate-server-card.js +0 -39
- package/build/scripts/generate-tool-coverage.js +0 -58
- package/build/scripts/generate-tool-docs.js +0 -430
- package/build/scripts/tool-coverage/coverage.js +0 -341
- package/build/scripts/tool-coverage/coverage.test.js +0 -142
- package/build/test/callback-proxy-tests.js +0 -321
- package/build/test/cli/args.test.js +0 -175
- package/build/test/cli/boolean-flags.test.js +0 -106
- package/build/test/cli/compact-mcp-result.test.js +0 -93
- package/build/test/cli/exposure.test.js +0 -104
- package/build/test/cli/load-config-snapshot.js +0 -5
- package/build/test/cli/output.test.js +0 -74
- package/build/test/cli/replay-command.test.js +0 -37
- package/build/test/cli/router.test.js +0 -183
- package/build/test/client-pool-test.js +0 -109
- package/build/test/clients/client.js +0 -34
- package/build/test/clients/custom-header-client.js +0 -122
- package/build/test/clients/sse-client.js +0 -95
- package/build/test/clients/stdio-client.js +0 -113
- package/build/test/clients/streamable-http-client.js +0 -95
- package/build/test/config-allowed-groups.test.js +0 -97
- package/build/test/create-commit-actions.test.js +0 -102
- package/build/test/draft-note-schema.test.js +0 -44
- package/build/test/dynamic-api-url-allowlist.test.js +0 -121
- package/build/test/dynamic-api-url-test.js +0 -304
- package/build/test/dynamic-routing-tests.js +0 -495
- package/build/test/get-merge-request-discussion-schema.test.js +0 -30
- package/build/test/gitlab-artifact-entry-schema.test.js +0 -44
- package/build/test/gitlab-diff-schema.test.js +0 -36
- package/build/test/gitlab-pipeline-schedule-schema.test.js +0 -32
- package/build/test/gitlab-tag-schema.test.js +0 -51
- package/build/test/group-milestone-schema.test.js +0 -45
- package/build/test/mcp-oauth-tests.js +0 -905
- package/build/test/mcp-server-name.test.js +0 -87
- package/build/test/merge-merge-request-schema.test.js +0 -75
- package/build/test/multi-server-test.js +0 -190
- package/build/test/no-proxy-integration-test.js +0 -183
- package/build/test/no-proxy-test.js +0 -149
- package/build/test/nullable-gitlab-response-fields.test.js +0 -37
- package/build/test/nullish-tool-arguments-schema.test.js +0 -118
- package/build/test/oauth-device-flow-tests.js +0 -450
- package/build/test/oauth-startup.test.js +0 -204
- package/build/test/oauth-tests.js +0 -428
- package/build/test/path-segment-encoding.test.js +0 -98
- package/build/test/remote-auth-simple-test.js +0 -277
- package/build/test/remote-auth-tests.js +0 -314
- package/build/test/response-masking.test.js +0 -445
- package/build/test/schema-tests.js +0 -1679
- package/build/test/server/metrics.test.js +0 -47
- package/build/test/server/request-helpers.test.js +0 -48
- package/build/test/server/version.test.js +0 -13
- package/build/test/sse-auth-guard.test.js +0 -96
- package/build/test/sse-session-limits.test.js +0 -273
- package/build/test/stateless/callback-proxy.test.js +0 -510
- package/build/test/stateless/client-id.test.js +0 -177
- package/build/test/stateless/codec.test.js +0 -328
- package/build/test/stateless/config-ttl.test.js +0 -149
- package/build/test/stateless/consumed-proxy-code-cache.test.js +0 -150
- package/build/test/stateless/session-id-integration.test.js +0 -675
- package/build/test/stateless/session-id.test.js +0 -157
- package/build/test/streamable-http-concurrent-session.test.js +0 -171
- package/build/test/streamable-http-dns-rebinding.test.js +0 -185
- package/build/test/streamable-http-sse-stream.test.js +0 -350
- package/build/test/streamable-http-static-token-auth.test.js +0 -157
- package/build/test/streamable-http-unauthenticated-discovery.test.js +0 -207
- package/build/test/test-all-transport-server.js +0 -255
- package/build/test/test-auth-retry.js +0 -195
- package/build/test/test-blank-filters.js +0 -156
- package/build/test/test-ci-catalog.js +0 -177
- package/build/test/test-ci-lint.js +0 -191
- package/build/test/test-ci-variables.js +0 -309
- package/build/test/test-create-repository.js +0 -120
- package/build/test/test-dependency-proxy.js +0 -195
- package/build/test/test-deployment-tools.js +0 -463
- package/build/test/test-download-attachment.js +0 -190
- package/build/test/test-dynamic-project-scope.js +0 -524
- package/build/test/test-empty-toolsets.js +0 -535
- package/build/test/test-get-file-blame.js +0 -145
- package/build/test/test-get-file-contents.js +0 -128
- package/build/test/test-geteffectiveprojectid.js +0 -812
- package/build/test/test-health-check.js +0 -115
- package/build/test/test-issue-description-patch.js +0 -256
- package/build/test/test-job-artifacts.js +0 -275
- package/build/test/test-json-schema.js +0 -166
- package/build/test/test-list-group-members.js +0 -150
- package/build/test/test-list-group-merge-requests.js +0 -165
- package/build/test/test-list-issues.js +0 -170
- package/build/test/test-list-merge-requests.js +0 -201
- package/build/test/test-list-milestones.js +0 -145
- package/build/test/test-list-project-members.js +0 -132
- package/build/test/test-merge-request-approval-state-tools.js +0 -213
- package/build/test/test-merge-request-approvals.js +0 -187
- package/build/test/test-merge-request-pipelines.js +0 -106
- package/build/test/test-mr-diffs-filter.js +0 -132
- package/build/test/test-mr-file-diffs.js +0 -251
- package/build/test/test-oauth-proxy-rate-limit.js +0 -133
- package/build/test/test-orbit.js +0 -155
- package/build/test/test-permission-mode.js +0 -424
- package/build/test/test-pipeline-schedules.js +0 -482
- package/build/test/test-protected-branches.js +0 -174
- package/build/test/test-remote-downloads.js +0 -510
- package/build/test/test-search-code.js +0 -275
- package/build/test/test-snippets.js +0 -735
- package/build/test/test-tags.js +0 -220
- package/build/test/test-todos.js +0 -195
- package/build/test/test-token-optimizations.js +0 -691
- package/build/test/test-toolset-filtering.js +0 -499
- package/build/test/test-update-issue-slim.js +0 -141
- package/build/test/test-update-project.js +0 -112
- package/build/test/test-upload-markdown.js +0 -206
- package/build/test/test-vulnerabilities.js +0 -399
- package/build/test/test-webhooks.js +0 -218
- package/build/test/tool-description-quality.test.js +0 -50
- package/build/test/utils/bulk-publish-options.test.js +0 -32
- package/build/test/utils/download-token.test.js +0 -35
- package/build/test/utils/forwarded-public-base-url.test.js +0 -46
- package/build/test/utils/gitlab-instance-version.test.js +0 -32
- package/build/test/utils/gitlab-version-gate.test.js +0 -74
- package/build/test/utils/graphql-query.test.js +0 -168
- package/build/test/utils/helpers-path.test.js +0 -104
- package/build/test/utils/jmespath-tool-result.test.js +0 -91
- package/build/test/utils/masking.test.js +0 -384
- package/build/test/utils/merge-request-position.test.js +0 -57
- package/build/test/utils/mock-gitlab-server.js +0 -614
- package/build/test/utils/proxy-client-ip.test.js +0 -28
- package/build/test/utils/redact-sensitive.test.js +0 -32
- package/build/test/utils/safe-redirect-fetch.test.js +0 -463
- package/build/test/utils/server-launcher.js +0 -231
- package/build/test/utils/tool-args.test.js +0 -210
- package/build/test/utils/url.test.js +0 -128
- package/build/test/utils/version-check.test.js +0 -239
- package/build/test/utils/wiki-title.test.js +0 -21
- package/build/test-note.js +0 -54
- package/build/test-resolve-issue-note.js +0 -127
|
@@ -1,424 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Permission Mode Test Suite
|
|
3
|
-
*
|
|
4
|
-
* Tests GITLAB_PERMISSION_MODE (readonly / modify / full), its interaction with
|
|
5
|
-
* the legacy GITLAB_READ_ONLY_MODE flag, and enforcement at list_tools,
|
|
6
|
-
* call_tool, and execute_graphql levels.
|
|
7
|
-
*/
|
|
8
|
-
import { describe, test, after, before } from "node:test";
|
|
9
|
-
import assert from "node:assert";
|
|
10
|
-
import { allTools, deleteTools, destructiveTools } from "../tools/registry.js";
|
|
11
|
-
import { launchServer, findAvailablePort, cleanupServers, TransportMode, HOST, } from "./utils/server-launcher.js";
|
|
12
|
-
import { MockGitLabServer, findMockServerPort } from "./utils/mock-gitlab-server.js";
|
|
13
|
-
import { CustomHeaderClient } from "./clients/custom-header-client.js";
|
|
14
|
-
const MOCK_TOKEN = "glpat-permission-mode-test";
|
|
15
|
-
const MOCK_PORT_BASE = 9700;
|
|
16
|
-
const MCP_PORT_BASE = 3700;
|
|
17
|
-
let mockGitLab;
|
|
18
|
-
let mockGitLabUrl;
|
|
19
|
-
let portCounter = 0;
|
|
20
|
-
async function nextMcpPort() {
|
|
21
|
-
return findAvailablePort(MCP_PORT_BASE + portCounter++ * 10);
|
|
22
|
-
}
|
|
23
|
-
async function launchMcpServer(extraEnv = {}) {
|
|
24
|
-
const port = await nextMcpPort();
|
|
25
|
-
return launchServer({
|
|
26
|
-
mode: TransportMode.STREAMABLE_HTTP,
|
|
27
|
-
port,
|
|
28
|
-
timeout: 10000,
|
|
29
|
-
env: {
|
|
30
|
-
STREAMABLE_HTTP: "true",
|
|
31
|
-
REMOTE_AUTHORIZATION: "true",
|
|
32
|
-
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
33
|
-
GITLAB_TOOLSETS: "all",
|
|
34
|
-
// execute_graphql is in no toolset; opt in so the guards under test are reachable.
|
|
35
|
-
GITLAB_TOOLS: "execute_graphql",
|
|
36
|
-
...extraEnv,
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
function mcpUrl(server) {
|
|
41
|
-
return `http://${HOST}:${server.port}/mcp`;
|
|
42
|
-
}
|
|
43
|
-
async function connectClient(server) {
|
|
44
|
-
const client = new CustomHeaderClient({
|
|
45
|
-
authorization: `Bearer ${MOCK_TOKEN}`,
|
|
46
|
-
});
|
|
47
|
-
await client.connect(mcpUrl(server));
|
|
48
|
-
return client;
|
|
49
|
-
}
|
|
50
|
-
async function getToolNames(server) {
|
|
51
|
-
const client = await connectClient(server);
|
|
52
|
-
const result = await client.listTools();
|
|
53
|
-
await client.disconnect();
|
|
54
|
-
return result.tools.map((t) => t.name);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Asserts that a query passes the modify-mode guard *and* is forwarded to GitLab. The mock
|
|
58
|
-
* server has no `/api/graphql` route, so the call comes back as a downstream
|
|
59
|
-
* "GraphQL request failed" — that failure is the evidence the guard let the query through,
|
|
60
|
-
* which a "does not throw" check alone would not provide.
|
|
61
|
-
*/
|
|
62
|
-
async function assertQueryReachesGitLab(server, query) {
|
|
63
|
-
const client = await connectClient(server);
|
|
64
|
-
try {
|
|
65
|
-
let outcome;
|
|
66
|
-
try {
|
|
67
|
-
outcome = JSON.stringify(await client.callTool("execute_graphql", { query }));
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
outcome = error instanceof Error ? error.message : String(error);
|
|
71
|
-
}
|
|
72
|
-
assert.ok(!outcome.includes("modify mode"), `the guard must not fire for "${query}", got: ${outcome}`);
|
|
73
|
-
assert.ok(outcome.includes("GraphQL request failed"), `"${query}" should be forwarded to GitLab after passing the guard, got: ${outcome}`);
|
|
74
|
-
}
|
|
75
|
-
finally {
|
|
76
|
-
await client.disconnect();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
const DELETE_SAMPLE_TOOLS = [
|
|
80
|
-
"delete_issue",
|
|
81
|
-
"delete_branch",
|
|
82
|
-
"delete_label",
|
|
83
|
-
"delete_wiki_page",
|
|
84
|
-
"delete_milestone",
|
|
85
|
-
"delete_group_milestone",
|
|
86
|
-
"delete_project_variable",
|
|
87
|
-
"delete_webhook",
|
|
88
|
-
"delete_snippet",
|
|
89
|
-
];
|
|
90
|
-
// Destructive teardown tools whose names do not start with `delete_`. All five are listed
|
|
91
|
-
// here (list-hiding) and exercised with explicit `callTool` literals below (call-rejection),
|
|
92
|
-
// so the tool-coverage detector sees the call path too.
|
|
93
|
-
const DESTRUCTIVE_SAMPLE_TOOLS = [
|
|
94
|
-
"cancel_pipeline",
|
|
95
|
-
"cancel_pipeline_job",
|
|
96
|
-
"stop_environment",
|
|
97
|
-
"stop_stale_environments",
|
|
98
|
-
"unprotect_branch",
|
|
99
|
-
];
|
|
100
|
-
const MODIFY_SAMPLE_TOOLS = [
|
|
101
|
-
"create_issue",
|
|
102
|
-
"update_issue",
|
|
103
|
-
"create_merge_request",
|
|
104
|
-
"create_branch",
|
|
105
|
-
"push_files",
|
|
106
|
-
"merge_merge_request",
|
|
107
|
-
];
|
|
108
|
-
const READ_SAMPLE_TOOLS = ["list_issues", "get_project", "list_merge_requests"];
|
|
109
|
-
describe("Modify-mode deny list invariants", () => {
|
|
110
|
-
test("deleteTools is a subset of destructiveTools", () => {
|
|
111
|
-
for (const name of deleteTools) {
|
|
112
|
-
assert.ok(destructiveTools.has(name), `"${name}" is blocked in modify mode but missing from destructiveTools`);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
test("every blocked tool exists in the registry", () => {
|
|
116
|
-
const names = new Set(allTools.map(tool => tool.name));
|
|
117
|
-
for (const name of deleteTools) {
|
|
118
|
-
assert.ok(names.has(name), `"${name}" is in deleteTools but not in allTools`);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
test("every destructive sample tool is in the modify-mode deny list", () => {
|
|
122
|
-
for (const name of DESTRUCTIVE_SAMPLE_TOOLS) {
|
|
123
|
-
assert.ok(deleteTools.has(name), `"${name}" should be blocked in modify mode`);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
describe("Permission Mode", { concurrency: 1 }, () => {
|
|
128
|
-
before(async () => {
|
|
129
|
-
const mockPort = await findMockServerPort();
|
|
130
|
-
mockGitLab = new MockGitLabServer({
|
|
131
|
-
port: mockPort,
|
|
132
|
-
validTokens: [MOCK_TOKEN],
|
|
133
|
-
});
|
|
134
|
-
await mockGitLab.start();
|
|
135
|
-
mockGitLabUrl = mockGitLab.getUrl();
|
|
136
|
-
});
|
|
137
|
-
after(async () => {
|
|
138
|
-
if (mockGitLab)
|
|
139
|
-
await mockGitLab.stop();
|
|
140
|
-
});
|
|
141
|
-
describe("full mode (default)", () => {
|
|
142
|
-
let server;
|
|
143
|
-
const servers = [];
|
|
144
|
-
before(async () => {
|
|
145
|
-
server = await launchMcpServer();
|
|
146
|
-
servers.push(server);
|
|
147
|
-
});
|
|
148
|
-
after(() => cleanupServers(servers));
|
|
149
|
-
test("exposes read, modify, and delete tools", async () => {
|
|
150
|
-
const names = await getToolNames(server);
|
|
151
|
-
for (const name of [
|
|
152
|
-
...READ_SAMPLE_TOOLS,
|
|
153
|
-
...MODIFY_SAMPLE_TOOLS,
|
|
154
|
-
...DELETE_SAMPLE_TOOLS,
|
|
155
|
-
...DESTRUCTIVE_SAMPLE_TOOLS,
|
|
156
|
-
]) {
|
|
157
|
-
assert.ok(names.includes(name), `full mode: expected "${name}" to be present`);
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
describe("modify mode", () => {
|
|
162
|
-
let server;
|
|
163
|
-
const servers = [];
|
|
164
|
-
before(async () => {
|
|
165
|
-
server = await launchMcpServer({ GITLAB_PERMISSION_MODE: "modify" });
|
|
166
|
-
servers.push(server);
|
|
167
|
-
});
|
|
168
|
-
after(() => cleanupServers(servers));
|
|
169
|
-
test("hides delete tools but keeps read and modify tools", async () => {
|
|
170
|
-
const names = await getToolNames(server);
|
|
171
|
-
for (const name of DELETE_SAMPLE_TOOLS) {
|
|
172
|
-
assert.ok(!names.includes(name), `modify mode: expected "${name}" to be absent`);
|
|
173
|
-
}
|
|
174
|
-
for (const name of [...READ_SAMPLE_TOOLS, ...MODIFY_SAMPLE_TOOLS]) {
|
|
175
|
-
assert.ok(names.includes(name), `modify mode: expected "${name}" to be present`);
|
|
176
|
-
}
|
|
177
|
-
assert.ok(!names.some(n => n.startsWith("delete_")), "no delete_* tool should be listed");
|
|
178
|
-
});
|
|
179
|
-
test("hides destructive stop/cancel/unprotect tools", async () => {
|
|
180
|
-
const names = await getToolNames(server);
|
|
181
|
-
for (const name of DESTRUCTIVE_SAMPLE_TOOLS) {
|
|
182
|
-
assert.ok(!names.includes(name), `modify mode: expected "${name}" to be absent`);
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
test("rejects destructive stop/cancel/unprotect tool calls", async () => {
|
|
186
|
-
const client = await connectClient(server);
|
|
187
|
-
try {
|
|
188
|
-
await assert.rejects(() => client.callTool("cancel_pipeline", { project_id: "1", pipeline_id: 1 }), (error) => error.message.includes("not allowed in modify mode"), "cancel_pipeline should be rejected in modify mode");
|
|
189
|
-
await assert.rejects(() => client.callTool("cancel_pipeline_job", { project_id: "1", job_id: 1 }), (error) => error.message.includes("not allowed in modify mode"), "cancel_pipeline_job should be rejected in modify mode");
|
|
190
|
-
await assert.rejects(() => client.callTool("stop_environment", { project_id: "1", environment_id: 1 }), (error) => error.message.includes("not allowed in modify mode"), "stop_environment should be rejected in modify mode");
|
|
191
|
-
await assert.rejects(() => client.callTool("stop_stale_environments", {
|
|
192
|
-
project_id: "1",
|
|
193
|
-
before: "2026-01-01T00:00:00Z",
|
|
194
|
-
}), (error) => error.message.includes("not allowed in modify mode"), "stop_stale_environments should be rejected in modify mode");
|
|
195
|
-
await assert.rejects(() => client.callTool("unprotect_branch", { project_id: "1", branch: "main" }), (error) => error.message.includes("not allowed in modify mode"), "unprotect_branch should be rejected in modify mode");
|
|
196
|
-
}
|
|
197
|
-
finally {
|
|
198
|
-
await client.disconnect();
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
test("hides purge_dependency_proxy_cache", async () => {
|
|
202
|
-
const names = await getToolNames(server);
|
|
203
|
-
assert.ok(!names.includes("purge_dependency_proxy_cache"), "modify mode: purge_dependency_proxy_cache should be absent");
|
|
204
|
-
});
|
|
205
|
-
test("rejects direct delete tool calls", async () => {
|
|
206
|
-
const client = await connectClient(server);
|
|
207
|
-
try {
|
|
208
|
-
await assert.rejects(() => client.callTool("delete_issue", { project_id: "1", issue_iid: 1 }), (error) => error.message.includes("not allowed in modify mode"), "delete_issue should be rejected in modify mode");
|
|
209
|
-
await assert.rejects(() => client.callTool("purge_dependency_proxy_cache", { group_id: "my-group" }), (error) => error.message.includes("not allowed in modify mode"), "purge_dependency_proxy_cache should be rejected in modify mode");
|
|
210
|
-
}
|
|
211
|
-
finally {
|
|
212
|
-
await client.disconnect();
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
test("rejects delete mutations via execute_graphql", async () => {
|
|
216
|
-
const client = await connectClient(server);
|
|
217
|
-
try {
|
|
218
|
-
await assert.rejects(() => client.callTool("execute_graphql", {
|
|
219
|
-
query: 'mutation { issueDelete(input: { projectPath: "g/p", iid: "1" }) { errors } }',
|
|
220
|
-
}), (error) => error.message.includes("destructive mutations in modify mode"), "delete mutation should be rejected in modify mode");
|
|
221
|
-
}
|
|
222
|
-
finally {
|
|
223
|
-
await client.disconnect();
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
test("rejects push_files delete actions", async () => {
|
|
227
|
-
const client = await connectClient(server);
|
|
228
|
-
try {
|
|
229
|
-
await assert.rejects(() => client.callTool("push_files", {
|
|
230
|
-
project_id: "1",
|
|
231
|
-
branch: "main",
|
|
232
|
-
commit_message: "m",
|
|
233
|
-
files: [{ file_path: "a.txt", action: "delete" }],
|
|
234
|
-
}), (error) => error.message.includes("delete or move actions in modify mode"), "push_files delete should be rejected in modify mode");
|
|
235
|
-
}
|
|
236
|
-
finally {
|
|
237
|
-
await client.disconnect();
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
test("rejects push_files move actions", async () => {
|
|
241
|
-
const client = await connectClient(server);
|
|
242
|
-
try {
|
|
243
|
-
await assert.rejects(() => client.callTool("push_files", {
|
|
244
|
-
project_id: "1",
|
|
245
|
-
branch: "main",
|
|
246
|
-
commit_message: "m",
|
|
247
|
-
files: [{ file_path: "b.txt", action: "move", previous_path: "a.txt" }],
|
|
248
|
-
}), (error) => error.message.includes("delete or move actions in modify mode"), "push_files move should be rejected in modify mode");
|
|
249
|
-
}
|
|
250
|
-
finally {
|
|
251
|
-
await client.disconnect();
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
test("does not apply the modify-mode guard to non-delete mutations", async () => {
|
|
255
|
-
// issueSetSeverity writes, but nothing about it is destructive.
|
|
256
|
-
await assertQueryReachesGitLab(server, "mutation { issueSetSeverity(input: { severity: HIGH }) { errors } }");
|
|
257
|
-
});
|
|
258
|
-
test("does not apply the modify-mode guard when the alias looks destructive", async () => {
|
|
259
|
-
// "stop" is only the caller-chosen label here; the field is issueSetSeverity.
|
|
260
|
-
await assertQueryReachesGitLab(server, "mutation { stop: issueSetSeverity(input: { severity: HIGH }) { errors } }");
|
|
261
|
-
});
|
|
262
|
-
test("rejects a destructive mutation hidden behind a harmless alias", async () => {
|
|
263
|
-
const client = await connectClient(server);
|
|
264
|
-
try {
|
|
265
|
-
await assert.rejects(() => client.callTool("execute_graphql", {
|
|
266
|
-
query: "mutation { harmless: environmentStop(input: {}) { errors } }",
|
|
267
|
-
}), (error) => error.message.includes("destructive mutations in modify mode"), "a destructive field must be rejected even when aliased");
|
|
268
|
-
}
|
|
269
|
-
finally {
|
|
270
|
-
await client.disconnect();
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
test("rejects jobUnschedule", async () => {
|
|
274
|
-
const client = await connectClient(server);
|
|
275
|
-
try {
|
|
276
|
-
await assert.rejects(() => client.callTool("execute_graphql", {
|
|
277
|
-
query: 'mutation { jobUnschedule(input: { id: "gid://gitlab/Ci::Build/1" }) { errors } }',
|
|
278
|
-
}), (error) => error.message.includes("destructive mutations in modify mode"), "jobUnschedule must be rejected in modify mode");
|
|
279
|
-
}
|
|
280
|
-
finally {
|
|
281
|
-
await client.disconnect();
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
describe("call-time enforcement of list filters (modify mode)", () => {
|
|
286
|
-
const servers = [];
|
|
287
|
-
after(() => cleanupServers(servers));
|
|
288
|
-
/** Calls a tool on a fresh client and returns the serialized result, or the error message. */
|
|
289
|
-
async function callOutcome(server, name, args) {
|
|
290
|
-
const client = await connectClient(server);
|
|
291
|
-
try {
|
|
292
|
-
return JSON.stringify(await client.callTool(name, args));
|
|
293
|
-
}
|
|
294
|
-
catch (error) {
|
|
295
|
-
return error instanceof Error ? error.message : String(error);
|
|
296
|
-
}
|
|
297
|
-
finally {
|
|
298
|
-
await client.disconnect();
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
test("rejects a regex-denied tool and an execute_graphql with no GITLAB_TOOLS entry", async () => {
|
|
302
|
-
const server = await launchMcpServer({
|
|
303
|
-
GITLAB_PERMISSION_MODE: "modify",
|
|
304
|
-
GITLAB_TOOLS: "",
|
|
305
|
-
GITLAB_DENIED_TOOLS_REGEX: "^merge_merge_request$",
|
|
306
|
-
});
|
|
307
|
-
servers.push(server);
|
|
308
|
-
const names = await getToolNames(server);
|
|
309
|
-
assert.ok(!names.includes("merge_merge_request"), "regex-denied tool must be unlisted");
|
|
310
|
-
assert.ok(!names.includes("execute_graphql"), "execute_graphql must be unlisted");
|
|
311
|
-
const merge = await callOutcome(server, "merge_merge_request", {
|
|
312
|
-
project_id: "1",
|
|
313
|
-
merge_request_iid: 1,
|
|
314
|
-
});
|
|
315
|
-
assert.ok(merge.includes("not available"), `merge_merge_request: ${merge}`);
|
|
316
|
-
const graphql = await callOutcome(server, "execute_graphql", {
|
|
317
|
-
query: "query { currentUser { id } }",
|
|
318
|
-
});
|
|
319
|
-
assert.ok(graphql.includes("not available"), `execute_graphql: ${graphql}`);
|
|
320
|
-
});
|
|
321
|
-
test("policy-hidden tool is unlisted but still callable", async () => {
|
|
322
|
-
const server = await launchMcpServer({
|
|
323
|
-
GITLAB_PERMISSION_MODE: "modify",
|
|
324
|
-
GITLAB_TOOL_POLICY_HIDDEN: "list_issues",
|
|
325
|
-
});
|
|
326
|
-
servers.push(server);
|
|
327
|
-
const names = await getToolNames(server);
|
|
328
|
-
assert.ok(!names.includes("list_issues"), "hidden tool must be unlisted");
|
|
329
|
-
const outcome = await callOutcome(server, "list_issues", { project_id: "1" });
|
|
330
|
-
assert.ok(!outcome.includes("not available"), `hidden tool must stay callable: ${outcome}`);
|
|
331
|
-
});
|
|
332
|
-
test("policy-hidden tool that is also regex-denied is rejected", async () => {
|
|
333
|
-
const server = await launchMcpServer({
|
|
334
|
-
GITLAB_PERMISSION_MODE: "modify",
|
|
335
|
-
GITLAB_TOOL_POLICY_HIDDEN: "list_issues",
|
|
336
|
-
GITLAB_DENIED_TOOLS_REGEX: "^list_issues$",
|
|
337
|
-
});
|
|
338
|
-
servers.push(server);
|
|
339
|
-
const names = await getToolNames(server);
|
|
340
|
-
assert.ok(!names.includes("list_issues"), "hidden tool must be unlisted");
|
|
341
|
-
const outcome = await callOutcome(server, "list_issues", { project_id: "1" });
|
|
342
|
-
assert.ok(outcome.includes("not available"), `regex denial must win over hidden exemption: ${outcome}`);
|
|
343
|
-
});
|
|
344
|
-
test("tool outside the enabled toolsets is rejected until discover_tools activates it", async () => {
|
|
345
|
-
const server = await launchMcpServer({
|
|
346
|
-
GITLAB_PERMISSION_MODE: "modify",
|
|
347
|
-
GITLAB_TOOLSETS: "issues",
|
|
348
|
-
});
|
|
349
|
-
servers.push(server);
|
|
350
|
-
const client = await connectClient(server);
|
|
351
|
-
try {
|
|
352
|
-
const before = await client
|
|
353
|
-
.callTool("list_pipelines", { project_id: "1" })
|
|
354
|
-
.then(r => JSON.stringify(r))
|
|
355
|
-
.catch((e) => e.message);
|
|
356
|
-
assert.ok(before.includes("not available"), `before activation: ${before}`);
|
|
357
|
-
await client.callTool("discover_tools", { category: "pipelines" });
|
|
358
|
-
const after = await client
|
|
359
|
-
.callTool("list_pipelines", { project_id: "1" })
|
|
360
|
-
.then(r => JSON.stringify(r))
|
|
361
|
-
.catch((e) => e.message);
|
|
362
|
-
assert.ok(!after.includes("not available"), `after activation: ${after}`);
|
|
363
|
-
}
|
|
364
|
-
finally {
|
|
365
|
-
await client.disconnect();
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
describe("readonly mode via GITLAB_PERMISSION_MODE", () => {
|
|
370
|
-
let server;
|
|
371
|
-
const servers = [];
|
|
372
|
-
before(async () => {
|
|
373
|
-
server = await launchMcpServer({ GITLAB_PERMISSION_MODE: "readonly" });
|
|
374
|
-
servers.push(server);
|
|
375
|
-
});
|
|
376
|
-
after(() => cleanupServers(servers));
|
|
377
|
-
test("exposes only read-only tools", async () => {
|
|
378
|
-
const names = await getToolNames(server);
|
|
379
|
-
for (const name of READ_SAMPLE_TOOLS) {
|
|
380
|
-
assert.ok(names.includes(name), `readonly mode: expected "${name}" to be present`);
|
|
381
|
-
}
|
|
382
|
-
for (const name of [...MODIFY_SAMPLE_TOOLS, ...DELETE_SAMPLE_TOOLS]) {
|
|
383
|
-
assert.ok(!names.includes(name), `readonly mode: expected "${name}" to be absent`);
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
test("rejects write tool calls", async () => {
|
|
387
|
-
const client = await connectClient(server);
|
|
388
|
-
try {
|
|
389
|
-
await assert.rejects(() => client.callTool("create_issue", { project_id: "1", title: "t" }), (error) => error.message.includes("not allowed in read-only mode"), "create_issue should be rejected in readonly mode");
|
|
390
|
-
}
|
|
391
|
-
finally {
|
|
392
|
-
await client.disconnect();
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
});
|
|
396
|
-
describe("legacy GITLAB_READ_ONLY_MODE interaction", () => {
|
|
397
|
-
const servers = [];
|
|
398
|
-
after(() => cleanupServers(servers));
|
|
399
|
-
test("GITLAB_READ_ONLY_MODE=true still behaves as readonly", async () => {
|
|
400
|
-
const server = await launchMcpServer({ GITLAB_READ_ONLY_MODE: "true" });
|
|
401
|
-
servers.push(server);
|
|
402
|
-
const names = await getToolNames(server);
|
|
403
|
-
assert.ok(names.includes("list_issues"), "read tool should be present");
|
|
404
|
-
assert.ok(!names.includes("create_issue"), "write tool should be absent");
|
|
405
|
-
assert.ok(!names.includes("delete_issue"), "delete tool should be absent");
|
|
406
|
-
});
|
|
407
|
-
test("GITLAB_READ_ONLY_MODE=true wins over GITLAB_PERMISSION_MODE=full", async () => {
|
|
408
|
-
const server = await launchMcpServer({
|
|
409
|
-
GITLAB_READ_ONLY_MODE: "true",
|
|
410
|
-
GITLAB_PERMISSION_MODE: "full",
|
|
411
|
-
});
|
|
412
|
-
servers.push(server);
|
|
413
|
-
const names = await getToolNames(server);
|
|
414
|
-
assert.ok(!names.includes("create_issue"), "legacy readonly should take precedence");
|
|
415
|
-
assert.ok(!names.includes("delete_issue"), "legacy readonly should take precedence");
|
|
416
|
-
});
|
|
417
|
-
test("rejects invalid GITLAB_PERMISSION_MODE even when GITLAB_READ_ONLY_MODE=true", async () => {
|
|
418
|
-
await assert.rejects(launchMcpServer({
|
|
419
|
-
GITLAB_READ_ONLY_MODE: "true",
|
|
420
|
-
GITLAB_PERMISSION_MODE: "write",
|
|
421
|
-
}), (error) => error.message.includes("Server process exited with code 1"), "invalid permission mode should fail startup before legacy override applies");
|
|
422
|
-
});
|
|
423
|
-
});
|
|
424
|
-
});
|