@zereight/mcp-gitlab 2.1.70 → 2.2.1

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 (158) hide show
  1. package/README.ko.md +9 -5
  2. package/README.md +15 -11
  3. package/README.pt-BR.md +9 -5
  4. package/README.zh-CN.md +9 -5
  5. package/build/config.js +12 -4
  6. package/build/deprecated-env.js +63 -0
  7. package/build/index.js +430 -200
  8. package/build/oauth-device-flow.js +80 -0
  9. package/build/oauth.js +135 -18
  10. package/build/schemas.js +1 -1
  11. package/build/server/remote-http-stack.js +39 -0
  12. package/build/tools/discover-activation.js +38 -0
  13. package/build/tools/exposed-tools.js +35 -0
  14. package/build/tools/listed-tools.js +76 -0
  15. package/build/tools/registry.js +232 -63
  16. package/build/tools/tool-descriptions.js +3 -3
  17. package/build/tools/tool-profile.js +66 -0
  18. package/build/utils/compact-tool-allowlist.js +14 -0
  19. package/build/utils/logger.js +34 -12
  20. package/package.json +3 -3
  21. package/build/scripts/check-skill-sync.js +0 -143
  22. package/build/scripts/generate-server-card.js +0 -39
  23. package/build/scripts/generate-tool-coverage.js +0 -58
  24. package/build/scripts/generate-tool-docs.js +0 -430
  25. package/build/scripts/tool-coverage/coverage.js +0 -341
  26. package/build/scripts/tool-coverage/coverage.test.js +0 -142
  27. package/build/test/callback-proxy-tests.js +0 -321
  28. package/build/test/cli/args.test.js +0 -175
  29. package/build/test/cli/boolean-flags.test.js +0 -106
  30. package/build/test/cli/compact-mcp-result.test.js +0 -93
  31. package/build/test/cli/credentials.test.js +0 -153
  32. package/build/test/cli/exposure.test.js +0 -104
  33. package/build/test/cli/load-config-snapshot.js +0 -5
  34. package/build/test/cli/output.test.js +0 -74
  35. package/build/test/cli/replay-command.test.js +0 -37
  36. package/build/test/cli/router.test.js +0 -183
  37. package/build/test/client-pool-test.js +0 -109
  38. package/build/test/clients/client.js +0 -34
  39. package/build/test/clients/custom-header-client.js +0 -122
  40. package/build/test/clients/sse-client.js +0 -95
  41. package/build/test/clients/stdio-client.js +0 -113
  42. package/build/test/clients/streamable-http-client.js +0 -95
  43. package/build/test/config-allowed-groups.test.js +0 -97
  44. package/build/test/create-commit-actions.test.js +0 -102
  45. package/build/test/draft-note-schema.test.js +0 -44
  46. package/build/test/dynamic-api-url-allowlist.test.js +0 -121
  47. package/build/test/dynamic-api-url-test.js +0 -304
  48. package/build/test/dynamic-routing-tests.js +0 -495
  49. package/build/test/get-merge-request-discussion-schema.test.js +0 -30
  50. package/build/test/gitlab-api-tool-errors.test.js +0 -112
  51. package/build/test/gitlab-artifact-entry-schema.test.js +0 -44
  52. package/build/test/gitlab-diff-schema.test.js +0 -36
  53. package/build/test/gitlab-pipeline-schedule-schema.test.js +0 -32
  54. package/build/test/gitlab-tag-schema.test.js +0 -51
  55. package/build/test/group-milestone-schema.test.js +0 -45
  56. package/build/test/mcp-oauth-tests.js +0 -905
  57. package/build/test/mcp-server-name.test.js +0 -87
  58. package/build/test/merge-merge-request-schema.test.js +0 -75
  59. package/build/test/multi-server-test.js +0 -190
  60. package/build/test/no-proxy-integration-test.js +0 -183
  61. package/build/test/no-proxy-test.js +0 -149
  62. package/build/test/nullable-gitlab-response-fields.test.js +0 -37
  63. package/build/test/nullish-tool-arguments-schema.test.js +0 -118
  64. package/build/test/oauth-device-flow-tests.js +0 -450
  65. package/build/test/oauth-download-url.test.js +0 -157
  66. package/build/test/oauth-startup.test.js +0 -204
  67. package/build/test/oauth-tests.js +0 -428
  68. package/build/test/path-segment-encoding.test.js +0 -98
  69. package/build/test/remote-auth-simple-test.js +0 -277
  70. package/build/test/remote-auth-tests.js +0 -314
  71. package/build/test/response-masking.test.js +0 -445
  72. package/build/test/schema-tests.js +0 -1679
  73. package/build/test/server/metrics.test.js +0 -47
  74. package/build/test/server/request-helpers.test.js +0 -48
  75. package/build/test/server/version.test.js +0 -13
  76. package/build/test/sse-auth-guard.test.js +0 -96
  77. package/build/test/sse-session-limits.test.js +0 -273
  78. package/build/test/stateless/callback-proxy.test.js +0 -510
  79. package/build/test/stateless/client-id.test.js +0 -177
  80. package/build/test/stateless/codec.test.js +0 -328
  81. package/build/test/stateless/config-ttl.test.js +0 -149
  82. package/build/test/stateless/consumed-proxy-code-cache.test.js +0 -150
  83. package/build/test/stateless/session-id-integration.test.js +0 -675
  84. package/build/test/stateless/session-id.test.js +0 -157
  85. package/build/test/streamable-http-concurrent-session.test.js +0 -171
  86. package/build/test/streamable-http-dns-rebinding.test.js +0 -185
  87. package/build/test/streamable-http-sse-stream.test.js +0 -350
  88. package/build/test/streamable-http-static-token-auth.test.js +0 -157
  89. package/build/test/streamable-http-unauthenticated-discovery.test.js +0 -207
  90. package/build/test/test-all-transport-server.js +0 -255
  91. package/build/test/test-auth-retry.js +0 -195
  92. package/build/test/test-blank-filters.js +0 -156
  93. package/build/test/test-ci-catalog.js +0 -177
  94. package/build/test/test-ci-lint.js +0 -191
  95. package/build/test/test-ci-variables.js +0 -309
  96. package/build/test/test-create-repository.js +0 -120
  97. package/build/test/test-dependency-proxy.js +0 -195
  98. package/build/test/test-deployment-tools.js +0 -463
  99. package/build/test/test-download-attachment.js +0 -190
  100. package/build/test/test-dynamic-project-scope.js +0 -524
  101. package/build/test/test-empty-toolsets.js +0 -535
  102. package/build/test/test-get-file-blame.js +0 -145
  103. package/build/test/test-get-file-contents.js +0 -128
  104. package/build/test/test-geteffectiveprojectid.js +0 -804
  105. package/build/test/test-health-check.js +0 -115
  106. package/build/test/test-issue-description-patch.js +0 -256
  107. package/build/test/test-job-artifacts.js +0 -275
  108. package/build/test/test-json-schema.js +0 -166
  109. package/build/test/test-list-group-members.js +0 -150
  110. package/build/test/test-list-group-merge-requests.js +0 -165
  111. package/build/test/test-list-issues.js +0 -170
  112. package/build/test/test-list-merge-requests.js +0 -201
  113. package/build/test/test-list-milestones.js +0 -145
  114. package/build/test/test-list-project-members.js +0 -132
  115. package/build/test/test-merge-request-approval-state-tools.js +0 -213
  116. package/build/test/test-merge-request-approvals.js +0 -187
  117. package/build/test/test-merge-request-pipelines.js +0 -106
  118. package/build/test/test-mr-diffs-filter.js +0 -132
  119. package/build/test/test-mr-file-diffs.js +0 -251
  120. package/build/test/test-oauth-proxy-rate-limit.js +0 -133
  121. package/build/test/test-orbit.js +0 -155
  122. package/build/test/test-permission-mode.js +0 -424
  123. package/build/test/test-pipeline-schedules.js +0 -484
  124. package/build/test/test-protected-branches.js +0 -174
  125. package/build/test/test-remote-downloads.js +0 -510
  126. package/build/test/test-search-code.js +0 -275
  127. package/build/test/test-snippets.js +0 -735
  128. package/build/test/test-tags.js +0 -220
  129. package/build/test/test-todos.js +0 -195
  130. package/build/test/test-token-optimizations.js +0 -691
  131. package/build/test/test-toolset-filtering.js +0 -499
  132. package/build/test/test-update-issue-slim.js +0 -141
  133. package/build/test/test-update-project.js +0 -112
  134. package/build/test/test-upload-markdown.js +0 -206
  135. package/build/test/test-vulnerabilities.js +0 -399
  136. package/build/test/test-webhooks.js +0 -218
  137. package/build/test/tool-description-quality.test.js +0 -50
  138. package/build/test/utils/bulk-publish-options.test.js +0 -32
  139. package/build/test/utils/download-token.test.js +0 -35
  140. package/build/test/utils/forwarded-public-base-url.test.js +0 -46
  141. package/build/test/utils/gitlab-instance-version.test.js +0 -32
  142. package/build/test/utils/gitlab-version-gate.test.js +0 -74
  143. package/build/test/utils/graphql-query.test.js +0 -168
  144. package/build/test/utils/helpers-path.test.js +0 -104
  145. package/build/test/utils/jmespath-tool-result.test.js +0 -91
  146. package/build/test/utils/masking.test.js +0 -384
  147. package/build/test/utils/merge-request-position.test.js +0 -57
  148. package/build/test/utils/mock-gitlab-server.js +0 -614
  149. package/build/test/utils/proxy-client-ip.test.js +0 -28
  150. package/build/test/utils/redact-sensitive.test.js +0 -32
  151. package/build/test/utils/safe-redirect-fetch.test.js +0 -463
  152. package/build/test/utils/server-launcher.js +0 -231
  153. package/build/test/utils/tool-args.test.js +0 -210
  154. package/build/test/utils/url.test.js +0 -141
  155. package/build/test/utils/version-check.test.js +0 -239
  156. package/build/test/utils/wiki-title.test.js +0 -21
  157. package/build/test-note.js +0 -54
  158. package/build/test-resolve-issue-note.js +0 -127
@@ -1,87 +0,0 @@
1
- import { after, describe, test } from "node:test";
2
- import assert from "node:assert";
3
- import { cleanupServers, findAvailablePort, HOST, launchServer, TransportMode, } from "./utils/server-launcher.js";
4
- async function rawMcpRequest(url, body, headers = {}) {
5
- const response = await fetch(url, {
6
- method: "POST",
7
- headers: {
8
- "Content-Type": "application/json",
9
- Accept: "application/json, text/event-stream",
10
- ...headers,
11
- },
12
- body: JSON.stringify(body),
13
- });
14
- const text = await response.text();
15
- const contentType = response.headers.get("content-type") ?? "";
16
- if (contentType.includes("text/event-stream")) {
17
- const dataLines = text
18
- .split("\n")
19
- .filter(line => line.startsWith("data: "))
20
- .map(line => line.slice(6));
21
- return {
22
- status: response.status,
23
- data: dataLines.length > 0 ? JSON.parse(dataLines.at(-1)) : null,
24
- text,
25
- };
26
- }
27
- return {
28
- status: response.status,
29
- data: text ? JSON.parse(text) : null,
30
- text,
31
- };
32
- }
33
- const initializeBody = {
34
- jsonrpc: "2.0",
35
- id: 1,
36
- method: "initialize",
37
- params: {
38
- protocolVersion: "2025-03-26",
39
- capabilities: {},
40
- clientInfo: { name: "server-name-test", version: "1.0.0" },
41
- },
42
- };
43
- let portOffset = 0;
44
- async function launchWithServerName(mcpServerName) {
45
- const port = await findAvailablePort(3700 + portOffset++ * 10);
46
- const server = await launchServer({
47
- mode: TransportMode.STREAMABLE_HTTP,
48
- port,
49
- timeout: 10_000,
50
- env: {
51
- STREAMABLE_HTTP: "true",
52
- REMOTE_AUTHORIZATION: "true",
53
- GITLAB_ALLOW_UNAUTHENTICATED_TOOL_DISCOVERY: "true",
54
- GITLAB_API_URL: "https://gitlab.example.com/api/v4",
55
- ...(mcpServerName !== undefined ? { MCP_SERVER_NAME: mcpServerName } : {}),
56
- },
57
- });
58
- return { server, mcpUrl: `http://${HOST}:${port}/mcp` };
59
- }
60
- describe("MCP_SERVER_NAME", { timeout: 20_000 }, () => {
61
- let servers = [];
62
- after(() => {
63
- cleanupServers(servers);
64
- servers = [];
65
- });
66
- test("defaults to zereight-gitlab-mcp-server when unset", async () => {
67
- const { server, mcpUrl } = await launchWithServerName();
68
- servers.push(server);
69
- const response = await rawMcpRequest(mcpUrl, initializeBody);
70
- assert.strictEqual(response.status, 200, response.text);
71
- assert.strictEqual(response.data?.result?.serverInfo?.name, "zereight-gitlab-mcp-server");
72
- });
73
- test("reports the overridden name when MCP_SERVER_NAME is set", async () => {
74
- const { server, mcpUrl } = await launchWithServerName("gitlab-selfhosted-readonly");
75
- servers.push(server);
76
- const response = await rawMcpRequest(mcpUrl, initializeBody);
77
- assert.strictEqual(response.status, 200, response.text);
78
- assert.strictEqual(response.data?.result?.serverInfo?.name, "gitlab-selfhosted-readonly");
79
- });
80
- test("treats a whitespace-only MCP_SERVER_NAME as unset", async () => {
81
- const { server, mcpUrl } = await launchWithServerName(" ");
82
- servers.push(server);
83
- const response = await rawMcpRequest(mcpUrl, initializeBody);
84
- assert.strictEqual(response.status, 200, response.text);
85
- assert.strictEqual(response.data?.result?.serverInfo?.name, "zereight-gitlab-mcp-server");
86
- });
87
- });
@@ -1,75 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert";
3
- import { GitLabMergeRequestSchema, MergeMergeRequestSchema } from "../schemas.js";
4
- const HEAD_SHA = "e82eb4a098e32c796079ca3915e07487fc4db24c";
5
- const PROJECT_ID = "group/project";
6
- const MERGE_REQUEST_IID = "42";
7
- function mergeArgs(overrides = {}) {
8
- return {
9
- project_id: PROJECT_ID,
10
- merge_request_iid: MERGE_REQUEST_IID,
11
- ...overrides,
12
- };
13
- }
14
- function mergeRequest(overrides = {}) {
15
- return {
16
- id: "1001",
17
- iid: MERGE_REQUEST_IID,
18
- project_id: "123",
19
- title: "Add milestone exposure",
20
- description: "Expose MR milestone",
21
- state: "opened",
22
- author: {
23
- id: "1",
24
- username: "octocat",
25
- name: "Octo Cat",
26
- avatar_url: null,
27
- web_url: "https://gitlab.example.com/octocat",
28
- },
29
- assignees: [],
30
- reviewers: [],
31
- source_branch: "feature/milestone",
32
- target_branch: "main",
33
- web_url: "https://gitlab.example.com/group/project/-/merge_requests/42",
34
- created_at: "2026-05-07T00:00:00.000Z",
35
- updated_at: "2026-05-07T00:00:00.000Z",
36
- merged_at: null,
37
- closed_at: null,
38
- merge_commit_sha: null,
39
- ...overrides,
40
- };
41
- }
42
- describe("When parsing merge_merge_request arguments", () => {
43
- describe("with sha provided", () => {
44
- it("should keep sha on the parsed object", () => {
45
- const parsed = MergeMergeRequestSchema.parse(mergeArgs({ sha: HEAD_SHA }));
46
- assert.strictEqual(parsed.sha, HEAD_SHA);
47
- });
48
- });
49
- describe("with sha omitted", () => {
50
- it("should parse and leave sha undefined", () => {
51
- const parsed = MergeMergeRequestSchema.parse(mergeArgs());
52
- assert.strictEqual(parsed.sha, undefined);
53
- });
54
- });
55
- describe("with an unknown extra field", () => {
56
- it("should strip the unknown field", () => {
57
- const parsed = MergeMergeRequestSchema.parse(mergeArgs({ not_a_schema_field: "drop-me" }));
58
- assert.equal("not_a_schema_field" in parsed, false);
59
- });
60
- });
61
- });
62
- describe("When parsing a GitLab merge request response", () => {
63
- describe("with sha present", () => {
64
- it("should keep sha instead of stripping it", () => {
65
- const parsed = GitLabMergeRequestSchema.parse(mergeRequest({ sha: HEAD_SHA }));
66
- assert.strictEqual(parsed.sha, HEAD_SHA);
67
- });
68
- });
69
- describe("with sha omitted", () => {
70
- it("should accept the payload", () => {
71
- const parsed = GitLabMergeRequestSchema.parse(mergeRequest());
72
- assert.strictEqual(parsed.sha, undefined);
73
- });
74
- });
75
- });
@@ -1,190 +0,0 @@
1
- import { describe, test, after, before } from 'node:test';
2
- import assert from 'node:assert';
3
- import { launchServer, findAvailablePort, TransportMode, HOST } from './utils/server-launcher.js';
4
- import { MockGitLabServer, findMockServerPort } from './utils/mock-gitlab-server.js';
5
- import { CustomHeaderClient } from './clients/custom-header-client.js';
6
- const MOCK_TOKEN = 'glpat-mock-token-12345';
7
- const project1 = {
8
- id: 1,
9
- name: "ProjectFromServer1",
10
- description: "Mock project from server 1",
11
- path_with_namespace: "group1/project1",
12
- web_url: "http://mock.gitlab/group1/project1",
13
- default_branch: "main",
14
- visibility: "private",
15
- path: "project1",
16
- created_at: new Date().toISOString(),
17
- namespace: {
18
- id: 1,
19
- name: "group1",
20
- path: "group1",
21
- kind: "group",
22
- full_path: "group1",
23
- },
24
- };
25
- const project2 = {
26
- id: 2,
27
- name: "ProjectFromServer2",
28
- description: "Mock project from server 2",
29
- path_with_namespace: "group2/project2",
30
- web_url: "http://mock.gitlab/group2/project2",
31
- default_branch: "main",
32
- visibility: "private",
33
- path: "project2",
34
- created_at: new Date().toISOString(),
35
- namespace: {
36
- id: 2,
37
- name: "group2",
38
- path: "group2",
39
- kind: "group",
40
- full_path: "group2",
41
- },
42
- };
43
- describe("Single Client Mode (ENABLE_DYNAMIC_API_URL=false)", () => {
44
- let mcpServer;
45
- let mcpUrl;
46
- let mockServer1;
47
- before(async () => {
48
- const mockPort = await findMockServerPort();
49
- mockServer1 = new MockGitLabServer({ port: mockPort, validTokens: [MOCK_TOKEN] });
50
- mockServer1.addMockHandler('get', '/projects/1', (req, res) => { res.json(project1); });
51
- await mockServer1.start();
52
- const mcpPort = await findAvailablePort(3002);
53
- mcpServer = await launchServer({
54
- mode: TransportMode.STREAMABLE_HTTP,
55
- port: mcpPort,
56
- env: {
57
- GITLAB_API_URL: `${mockServer1.getUrl()}/api/v4`,
58
- ENABLE_DYNAMIC_API_URL: "false",
59
- REMOTE_AUTHORIZATION: "true",
60
- },
61
- });
62
- mcpUrl = `http://${HOST}:${mcpPort}/mcp`;
63
- });
64
- after(async () => {
65
- if (mcpServer)
66
- mcpServer.kill();
67
- if (mockServer1)
68
- await mockServer1.stop();
69
- });
70
- test("should use the default server when no header is provided", async () => {
71
- const client = new CustomHeaderClient({ headers: { 'authorization': `Bearer ${MOCK_TOKEN}` } });
72
- await client.connect(mcpUrl);
73
- const result = await client.callTool('get_project', { project_id: "1" });
74
- if (result.content[0].type === 'text') {
75
- const textContent = JSON.parse(result.content[0].text);
76
- assert.deepStrictEqual(textContent, project1);
77
- }
78
- else {
79
- assert.fail('Expected text content from tool call');
80
- }
81
- await client.disconnect();
82
- });
83
- test("should IGNORE the custom header and still use the default server", async () => {
84
- const client = new CustomHeaderClient({
85
- headers: {
86
- 'authorization': `Bearer ${MOCK_TOKEN}`,
87
- 'X-GitLab-API-URL': `http://localhost:9999/api/v4`,
88
- }
89
- });
90
- await client.connect(mcpUrl);
91
- const result = await client.callTool('get_project', { project_id: "1" });
92
- if (result.content[0].type === 'text') {
93
- const textContent = JSON.parse(result.content[0].text);
94
- assert.deepStrictEqual(textContent, project1);
95
- }
96
- else {
97
- assert.fail('Expected text content from tool call');
98
- }
99
- await client.disconnect();
100
- });
101
- });
102
- describe("Dynamic Client Mode (ENABLE_DYNAMIC_API_URL=true)", () => {
103
- let mcpServer;
104
- let mcpUrl;
105
- let mockServer1;
106
- let mockServer2;
107
- before(async () => {
108
- const port1 = await findMockServerPort();
109
- const port2 = await findMockServerPort();
110
- mockServer1 = new MockGitLabServer({ port: port1, validTokens: [MOCK_TOKEN] });
111
- mockServer2 = new MockGitLabServer({ port: port2, validTokens: [MOCK_TOKEN] });
112
- mockServer1.addMockHandler('get', '/projects/1', (req, res) => { res.json(project1); });
113
- mockServer2.addMockHandler('get', '/projects/2', (req, res) => { res.json(project2); });
114
- await mockServer1.start();
115
- await mockServer2.start();
116
- const mcpPort = await findAvailablePort(3012);
117
- mcpServer = await launchServer({
118
- mode: TransportMode.STREAMABLE_HTTP,
119
- port: mcpPort,
120
- env: {
121
- GITLAB_API_URL: `${mockServer1.getUrl()}/api/v4,${mockServer2.getUrl()}/api/v4`,
122
- ENABLE_DYNAMIC_API_URL: "true",
123
- REMOTE_AUTHORIZATION: "true",
124
- },
125
- });
126
- mcpUrl = `http://${HOST}:${mcpPort}/mcp`;
127
- });
128
- after(async () => {
129
- if (mcpServer)
130
- mcpServer.kill();
131
- if (mockServer1)
132
- await mockServer1.stop();
133
- if (mockServer2)
134
- await mockServer2.stop();
135
- });
136
- test("should use the default server (first in list) when no header is provided", async () => {
137
- const client = new CustomHeaderClient({ headers: { 'authorization': `Bearer ${MOCK_TOKEN}` } });
138
- await client.connect(mcpUrl);
139
- const result = await client.callTool('get_project', { project_id: "1" });
140
- if (result.content[0].type === 'text') {
141
- const textContent = JSON.parse(result.content[0].text);
142
- assert.deepStrictEqual(textContent, project1);
143
- }
144
- else {
145
- assert.fail('Expected text content from tool call');
146
- }
147
- await client.disconnect();
148
- });
149
- test("should switch to the second server when the header is provided", async () => {
150
- const client = new CustomHeaderClient({
151
- headers: {
152
- 'authorization': `Bearer ${MOCK_TOKEN}`,
153
- 'X-GitLab-API-URL': `${mockServer2.getUrl()}/api/v4`,
154
- }
155
- });
156
- await client.connect(mcpUrl);
157
- const result = await client.callTool('get_project', { project_id: "2" });
158
- if (result.content[0].type === 'text') {
159
- const textContent = JSON.parse(result.content[0].text);
160
- assert.deepStrictEqual(textContent, project2);
161
- }
162
- else {
163
- assert.fail('Expected text content from tool call');
164
- }
165
- await client.disconnect();
166
- });
167
- test("should fail tool call when header contains a non-whitelisted URL", async () => {
168
- const client = new CustomHeaderClient({
169
- headers: {
170
- 'authorization': `Bearer ${MOCK_TOKEN}`,
171
- 'X-GitLab-API-URL': 'http://localhost:9999/api/v4',
172
- }
173
- });
174
- // Connect succeeds (server accepts any valid URL format),
175
- // but tool calls fail because the target server doesn't exist
176
- await client.connect(mcpUrl);
177
- try {
178
- const result = await client.callTool('get_project', { project_id: "1" });
179
- // If callTool returns (doesn't throw), check for error in response
180
- const content = result.content[0];
181
- assert.ok('text' in content, 'Should have text content');
182
- assert.ok(content.text.includes('Error') || content.text.includes('error') || content.text.includes('ECONNREFUSED') || result.isError, 'Should return an error for unreachable server');
183
- }
184
- catch (err) {
185
- // MCP client may throw for server-side errors (-32603)
186
- assert.ok(err.message.includes('ECONNREFUSED') || err.message.includes('failed') || err.message.includes('error'), `Should contain connection error info: ${err.message}`);
187
- }
188
- await client.disconnect();
189
- });
190
- });
@@ -1,183 +0,0 @@
1
- /**
2
- * NO_PROXY Integration Test
3
- * Tests NO_PROXY functionality with mock servers
4
- */
5
- import { describe, test, after, before } from 'node:test';
6
- import assert from 'node:assert';
7
- import { launchServer, findAvailablePort, cleanupServers, TransportMode, HOST } from './utils/server-launcher.js';
8
- import { MockGitLabServer, findMockServerPort } from './utils/mock-gitlab-server.js';
9
- import { CustomHeaderClient } from './clients/custom-header-client.js';
10
- // Test constants
11
- const MOCK_TOKEN = 'glpat-mock-token-12345';
12
- // Port ranges
13
- const MOCK_GITLAB_PORT_BASE = 9600;
14
- const MCP_SERVER_PORT_BASE = 3600;
15
- console.log('🌐 NO_PROXY Integration Test Suite');
16
- console.log('');
17
- describe('NO_PROXY Integration Tests', () => {
18
- let mcpUrl;
19
- let mockGitLab;
20
- let servers = [];
21
- let mockGitLabUrl;
22
- let mockGitLabHost;
23
- before(async () => {
24
- // Start mock GitLab server
25
- const mockPort = await findMockServerPort();
26
- mockGitLab = new MockGitLabServer({
27
- port: mockPort,
28
- validTokens: [MOCK_TOKEN]
29
- });
30
- await mockGitLab.start();
31
- mockGitLabUrl = mockGitLab.getUrl();
32
- // Extract the host:port part for NO_PROXY
33
- const url = new URL(mockGitLabUrl);
34
- mockGitLabHost = url.host; // This includes port if non-standard
35
- console.log(`Mock GitLab: ${mockGitLabUrl}`);
36
- console.log(`Mock GitLab Host: ${mockGitLabHost}`);
37
- });
38
- after(async () => {
39
- cleanupServers(servers);
40
- if (mockGitLab) {
41
- await mockGitLab.stop();
42
- }
43
- });
44
- test('should bypass proxy when hostname is in NO_PROXY', async () => {
45
- // Start MCP server with proxy settings and NO_PROXY
46
- const mcpPort = await findAvailablePort(MCP_SERVER_PORT_BASE);
47
- const server = await launchServer({
48
- mode: TransportMode.STREAMABLE_HTTP,
49
- port: mcpPort,
50
- timeout: 5000,
51
- env: {
52
- STREAMABLE_HTTP: 'true',
53
- REMOTE_AUTHORIZATION: 'true',
54
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
55
- // Set a fake proxy that would fail if used
56
- HTTP_PROXY: 'http://nonexistent-proxy.example.com:9999',
57
- HTTPS_PROXY: 'http://nonexistent-proxy.example.com:9999',
58
- // Bypass proxy for our mock GitLab server
59
- NO_PROXY: mockGitLabHost,
60
- }
61
- });
62
- servers.push(server);
63
- mcpUrl = `http://${HOST}:${mcpPort}/mcp`;
64
- console.log(`MCP Server: ${mcpUrl}`);
65
- console.log(`NO_PROXY: ${mockGitLabHost}`);
66
- // Create client and make a request
67
- const client = new CustomHeaderClient({
68
- 'authorization': `Bearer ${MOCK_TOKEN}`,
69
- });
70
- await client.connect(mcpUrl);
71
- // This should succeed because the proxy is bypassed
72
- const result = await client.callTool('list_projects', { per_page: 1 });
73
- console.log(' ✓ Request succeeded with NO_PROXY bypass');
74
- assert.ok(result, 'Request should succeed');
75
- await client.disconnect();
76
- });
77
- test('should use proxy when hostname is NOT in NO_PROXY', async () => {
78
- // Start MCP server with proxy settings but NO_PROXY doesn't match
79
- const mcpPort = await findAvailablePort(MCP_SERVER_PORT_BASE + 1);
80
- const server = await launchServer({
81
- mode: TransportMode.STREAMABLE_HTTP,
82
- port: mcpPort,
83
- timeout: 5000,
84
- env: {
85
- STREAMABLE_HTTP: 'true',
86
- REMOTE_AUTHORIZATION: 'true',
87
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
88
- // Set a fake proxy that would fail if used
89
- HTTP_PROXY: 'http://nonexistent-proxy.example.com:9999',
90
- HTTPS_PROXY: 'http://nonexistent-proxy.example.com:9999',
91
- // NO_PROXY doesn't match our server
92
- NO_PROXY: 'different-host.example.com,10.0.0.1',
93
- }
94
- });
95
- servers.push(server);
96
- mcpUrl = `http://${HOST}:${mcpPort}/mcp`;
97
- console.log(`MCP Server: ${mcpUrl}`);
98
- console.log(`NO_PROXY: different-host.example.com,10.0.0.1 (should NOT match)`);
99
- // Create client and make a request
100
- const client = new CustomHeaderClient({
101
- 'authorization': `Bearer ${MOCK_TOKEN}`,
102
- });
103
- await client.connect(mcpUrl);
104
- // This should fail because it tries to use the nonexistent proxy
105
- try {
106
- await client.callTool('list_projects', { per_page: 1 });
107
- assert.fail('Request should have failed due to proxy connection error');
108
- }
109
- catch (error) {
110
- console.log(' ✓ Request failed as expected (proxy error)');
111
- // Expected to fail with connection/proxy error
112
- assert.ok(error, 'Should throw an error when proxy fails');
113
- }
114
- await client.disconnect();
115
- });
116
- test('should bypass proxy with wildcard NO_PROXY', async () => {
117
- // Start MCP server with wildcard NO_PROXY
118
- const mcpPort = await findAvailablePort(MCP_SERVER_PORT_BASE + 2);
119
- const server = await launchServer({
120
- mode: TransportMode.STREAMABLE_HTTP,
121
- port: mcpPort,
122
- timeout: 5000,
123
- env: {
124
- STREAMABLE_HTTP: 'true',
125
- REMOTE_AUTHORIZATION: 'true',
126
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
127
- // Set a fake proxy that would fail if used
128
- HTTP_PROXY: 'http://nonexistent-proxy.example.com:9999',
129
- HTTPS_PROXY: 'http://nonexistent-proxy.example.com:9999',
130
- // Wildcard bypasses all proxies
131
- NO_PROXY: '*',
132
- }
133
- });
134
- servers.push(server);
135
- mcpUrl = `http://${HOST}:${mcpPort}/mcp`;
136
- console.log(`MCP Server: ${mcpUrl}`);
137
- console.log(`NO_PROXY: * (wildcard - bypasses all)`);
138
- // Create client and make a request
139
- const client = new CustomHeaderClient({
140
- 'authorization': `Bearer ${MOCK_TOKEN}`,
141
- });
142
- await client.connect(mcpUrl);
143
- // This should succeed because wildcard bypasses all proxies
144
- const result = await client.callTool('list_projects', { per_page: 1 });
145
- console.log(' ✓ Request succeeded with wildcard NO_PROXY');
146
- assert.ok(result, 'Request should succeed');
147
- await client.disconnect();
148
- });
149
- test('should bypass proxy with exact IP and localhost', async () => {
150
- // Start MCP server with explicit IP and localhost patterns
151
- const mcpPort = await findAvailablePort(MCP_SERVER_PORT_BASE + 3);
152
- const server = await launchServer({
153
- mode: TransportMode.STREAMABLE_HTTP,
154
- port: mcpPort,
155
- timeout: 5000,
156
- env: {
157
- STREAMABLE_HTTP: 'true',
158
- REMOTE_AUTHORIZATION: 'true',
159
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
160
- // Set a fake proxy that would fail if used
161
- HTTP_PROXY: 'http://nonexistent-proxy.example.com:9999',
162
- HTTPS_PROXY: 'http://nonexistent-proxy.example.com:9999',
163
- // Use explicit localhost and 127.0.0.1 patterns
164
- NO_PROXY: 'localhost,127.0.0.1',
165
- }
166
- });
167
- servers.push(server);
168
- mcpUrl = `http://${HOST}:${mcpPort}/mcp`;
169
- console.log(`MCP Server: ${mcpUrl}`);
170
- console.log(`NO_PROXY: localhost,127.0.0.1 (exact matches)`);
171
- // Create client and make a request
172
- const client = new CustomHeaderClient({
173
- 'authorization': `Bearer ${MOCK_TOKEN}`,
174
- });
175
- await client.connect(mcpUrl);
176
- // This should succeed because 127.0.0.1 and localhost are explicitly in NO_PROXY
177
- const result = await client.callTool('list_projects', { per_page: 1 });
178
- console.log(' ✓ Request succeeded with exact IP/localhost NO_PROXY match');
179
- assert.ok(result, 'Request should succeed');
180
- await client.disconnect();
181
- });
182
- });
183
- console.log('✅ NO_PROXY integration tests completed');