@zereight/mcp-gitlab 2.1.70 → 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.
Files changed (157) hide show
  1. package/README.ko.md +3 -1
  2. package/README.md +6 -2
  3. package/README.pt-BR.md +1 -1
  4. package/README.zh-CN.md +3 -1
  5. package/build/config.js +12 -4
  6. package/build/deprecated-env.js +47 -0
  7. package/build/index.js +369 -184
  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 +226 -57
  16. package/build/tools/tool-profile.js +66 -0
  17. package/build/utils/compact-tool-allowlist.js +14 -0
  18. package/build/utils/logger.js +34 -12
  19. package/package.json +3 -3
  20. package/build/scripts/check-skill-sync.js +0 -143
  21. package/build/scripts/generate-server-card.js +0 -39
  22. package/build/scripts/generate-tool-coverage.js +0 -58
  23. package/build/scripts/generate-tool-docs.js +0 -430
  24. package/build/scripts/tool-coverage/coverage.js +0 -341
  25. package/build/scripts/tool-coverage/coverage.test.js +0 -142
  26. package/build/test/callback-proxy-tests.js +0 -321
  27. package/build/test/cli/args.test.js +0 -175
  28. package/build/test/cli/boolean-flags.test.js +0 -106
  29. package/build/test/cli/compact-mcp-result.test.js +0 -93
  30. package/build/test/cli/credentials.test.js +0 -153
  31. package/build/test/cli/exposure.test.js +0 -104
  32. package/build/test/cli/load-config-snapshot.js +0 -5
  33. package/build/test/cli/output.test.js +0 -74
  34. package/build/test/cli/replay-command.test.js +0 -37
  35. package/build/test/cli/router.test.js +0 -183
  36. package/build/test/client-pool-test.js +0 -109
  37. package/build/test/clients/client.js +0 -34
  38. package/build/test/clients/custom-header-client.js +0 -122
  39. package/build/test/clients/sse-client.js +0 -95
  40. package/build/test/clients/stdio-client.js +0 -113
  41. package/build/test/clients/streamable-http-client.js +0 -95
  42. package/build/test/config-allowed-groups.test.js +0 -97
  43. package/build/test/create-commit-actions.test.js +0 -102
  44. package/build/test/draft-note-schema.test.js +0 -44
  45. package/build/test/dynamic-api-url-allowlist.test.js +0 -121
  46. package/build/test/dynamic-api-url-test.js +0 -304
  47. package/build/test/dynamic-routing-tests.js +0 -495
  48. package/build/test/get-merge-request-discussion-schema.test.js +0 -30
  49. package/build/test/gitlab-api-tool-errors.test.js +0 -112
  50. package/build/test/gitlab-artifact-entry-schema.test.js +0 -44
  51. package/build/test/gitlab-diff-schema.test.js +0 -36
  52. package/build/test/gitlab-pipeline-schedule-schema.test.js +0 -32
  53. package/build/test/gitlab-tag-schema.test.js +0 -51
  54. package/build/test/group-milestone-schema.test.js +0 -45
  55. package/build/test/mcp-oauth-tests.js +0 -905
  56. package/build/test/mcp-server-name.test.js +0 -87
  57. package/build/test/merge-merge-request-schema.test.js +0 -75
  58. package/build/test/multi-server-test.js +0 -190
  59. package/build/test/no-proxy-integration-test.js +0 -183
  60. package/build/test/no-proxy-test.js +0 -149
  61. package/build/test/nullable-gitlab-response-fields.test.js +0 -37
  62. package/build/test/nullish-tool-arguments-schema.test.js +0 -118
  63. package/build/test/oauth-device-flow-tests.js +0 -450
  64. package/build/test/oauth-download-url.test.js +0 -157
  65. package/build/test/oauth-startup.test.js +0 -204
  66. package/build/test/oauth-tests.js +0 -428
  67. package/build/test/path-segment-encoding.test.js +0 -98
  68. package/build/test/remote-auth-simple-test.js +0 -277
  69. package/build/test/remote-auth-tests.js +0 -314
  70. package/build/test/response-masking.test.js +0 -445
  71. package/build/test/schema-tests.js +0 -1679
  72. package/build/test/server/metrics.test.js +0 -47
  73. package/build/test/server/request-helpers.test.js +0 -48
  74. package/build/test/server/version.test.js +0 -13
  75. package/build/test/sse-auth-guard.test.js +0 -96
  76. package/build/test/sse-session-limits.test.js +0 -273
  77. package/build/test/stateless/callback-proxy.test.js +0 -510
  78. package/build/test/stateless/client-id.test.js +0 -177
  79. package/build/test/stateless/codec.test.js +0 -328
  80. package/build/test/stateless/config-ttl.test.js +0 -149
  81. package/build/test/stateless/consumed-proxy-code-cache.test.js +0 -150
  82. package/build/test/stateless/session-id-integration.test.js +0 -675
  83. package/build/test/stateless/session-id.test.js +0 -157
  84. package/build/test/streamable-http-concurrent-session.test.js +0 -171
  85. package/build/test/streamable-http-dns-rebinding.test.js +0 -185
  86. package/build/test/streamable-http-sse-stream.test.js +0 -350
  87. package/build/test/streamable-http-static-token-auth.test.js +0 -157
  88. package/build/test/streamable-http-unauthenticated-discovery.test.js +0 -207
  89. package/build/test/test-all-transport-server.js +0 -255
  90. package/build/test/test-auth-retry.js +0 -195
  91. package/build/test/test-blank-filters.js +0 -156
  92. package/build/test/test-ci-catalog.js +0 -177
  93. package/build/test/test-ci-lint.js +0 -191
  94. package/build/test/test-ci-variables.js +0 -309
  95. package/build/test/test-create-repository.js +0 -120
  96. package/build/test/test-dependency-proxy.js +0 -195
  97. package/build/test/test-deployment-tools.js +0 -463
  98. package/build/test/test-download-attachment.js +0 -190
  99. package/build/test/test-dynamic-project-scope.js +0 -524
  100. package/build/test/test-empty-toolsets.js +0 -535
  101. package/build/test/test-get-file-blame.js +0 -145
  102. package/build/test/test-get-file-contents.js +0 -128
  103. package/build/test/test-geteffectiveprojectid.js +0 -804
  104. package/build/test/test-health-check.js +0 -115
  105. package/build/test/test-issue-description-patch.js +0 -256
  106. package/build/test/test-job-artifacts.js +0 -275
  107. package/build/test/test-json-schema.js +0 -166
  108. package/build/test/test-list-group-members.js +0 -150
  109. package/build/test/test-list-group-merge-requests.js +0 -165
  110. package/build/test/test-list-issues.js +0 -170
  111. package/build/test/test-list-merge-requests.js +0 -201
  112. package/build/test/test-list-milestones.js +0 -145
  113. package/build/test/test-list-project-members.js +0 -132
  114. package/build/test/test-merge-request-approval-state-tools.js +0 -213
  115. package/build/test/test-merge-request-approvals.js +0 -187
  116. package/build/test/test-merge-request-pipelines.js +0 -106
  117. package/build/test/test-mr-diffs-filter.js +0 -132
  118. package/build/test/test-mr-file-diffs.js +0 -251
  119. package/build/test/test-oauth-proxy-rate-limit.js +0 -133
  120. package/build/test/test-orbit.js +0 -155
  121. package/build/test/test-permission-mode.js +0 -424
  122. package/build/test/test-pipeline-schedules.js +0 -484
  123. package/build/test/test-protected-branches.js +0 -174
  124. package/build/test/test-remote-downloads.js +0 -510
  125. package/build/test/test-search-code.js +0 -275
  126. package/build/test/test-snippets.js +0 -735
  127. package/build/test/test-tags.js +0 -220
  128. package/build/test/test-todos.js +0 -195
  129. package/build/test/test-token-optimizations.js +0 -691
  130. package/build/test/test-toolset-filtering.js +0 -499
  131. package/build/test/test-update-issue-slim.js +0 -141
  132. package/build/test/test-update-project.js +0 -112
  133. package/build/test/test-upload-markdown.js +0 -206
  134. package/build/test/test-vulnerabilities.js +0 -399
  135. package/build/test/test-webhooks.js +0 -218
  136. package/build/test/tool-description-quality.test.js +0 -50
  137. package/build/test/utils/bulk-publish-options.test.js +0 -32
  138. package/build/test/utils/download-token.test.js +0 -35
  139. package/build/test/utils/forwarded-public-base-url.test.js +0 -46
  140. package/build/test/utils/gitlab-instance-version.test.js +0 -32
  141. package/build/test/utils/gitlab-version-gate.test.js +0 -74
  142. package/build/test/utils/graphql-query.test.js +0 -168
  143. package/build/test/utils/helpers-path.test.js +0 -104
  144. package/build/test/utils/jmespath-tool-result.test.js +0 -91
  145. package/build/test/utils/masking.test.js +0 -384
  146. package/build/test/utils/merge-request-position.test.js +0 -57
  147. package/build/test/utils/mock-gitlab-server.js +0 -614
  148. package/build/test/utils/proxy-client-ip.test.js +0 -28
  149. package/build/test/utils/redact-sensitive.test.js +0 -32
  150. package/build/test/utils/safe-redirect-fetch.test.js +0 -463
  151. package/build/test/utils/server-launcher.js +0 -231
  152. package/build/test/utils/tool-args.test.js +0 -210
  153. package/build/test/utils/url.test.js +0 -141
  154. package/build/test/utils/version-check.test.js +0 -239
  155. package/build/test/utils/wiki-title.test.js +0 -21
  156. package/build/test-note.js +0 -54
  157. package/build/test-resolve-issue-note.js +0 -127
@@ -1,109 +0,0 @@
1
- /**
2
- * Client Pool Test Suite
3
- * Tests connection pooling limits and functionality
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
- const POOL_MAX_SIZE = 2;
13
- // Port ranges
14
- const MOCK_GITLAB_PORT_BASE = 9500;
15
- const MCP_SERVER_PORT_BASE = 3500;
16
- console.log('🏊 Client Pool Test Suite');
17
- console.log('');
18
- describe('Client Pool Limits', () => {
19
- let mcpUrl;
20
- let mockGitLab;
21
- let servers = [];
22
- let mockGitLabUrl;
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
- // Start MCP server with pool limit
33
- const mcpPort = await findAvailablePort(MCP_SERVER_PORT_BASE);
34
- const server = await launchServer({
35
- mode: TransportMode.STREAMABLE_HTTP,
36
- port: mcpPort,
37
- timeout: 5000,
38
- env: {
39
- STREAMABLE_HTTP: 'true',
40
- REMOTE_AUTHORIZATION: 'true',
41
- ENABLE_DYNAMIC_API_URL: 'true', // Enable dynamic URLs to test pooling
42
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
43
- GITLAB_POOL_MAX_SIZE: String(POOL_MAX_SIZE),
44
- }
45
- });
46
- servers.push(server);
47
- mcpUrl = `http://${HOST}:${mcpPort}/mcp`;
48
- console.log(`Mock GitLab: ${mockGitLabUrl}`);
49
- console.log(`MCP Server: ${mcpUrl}`);
50
- console.log(`Pool Max Size: ${POOL_MAX_SIZE}`);
51
- });
52
- after(async () => {
53
- cleanupServers(servers);
54
- if (mockGitLab) {
55
- await mockGitLab.stop();
56
- }
57
- });
58
- test('should enforce pool size limit', async () => {
59
- // The pool size is configured to 2.
60
- // We will connect with 3 distinct URLs.
61
- // The first 2 should succeed (or fail with network error), adding to the pool.
62
- // The 3rd should fail with "Pool is full".
63
- // URL 1: 127.0.0.1 (Real mock server)
64
- const url1 = `${mockGitLabUrl}/api/v4`;
65
- const client1 = new CustomHeaderClient({
66
- 'authorization': `Bearer ${MOCK_TOKEN}`,
67
- 'x-gitlab-api-url': url1
68
- });
69
- await client1.connect(mcpUrl);
70
- await client1.callTool('list_projects', { per_page: 1 });
71
- console.log(' ✓ Request 1 (127.0.0.1) succeeded');
72
- await client1.disconnect();
73
- // URL 2: localhost (Real mock server, distinct string)
74
- const url2 = url1.replace('127.0.0.1', 'localhost');
75
- const client2 = new CustomHeaderClient({
76
- 'authorization': `Bearer ${MOCK_TOKEN}`,
77
- 'x-gitlab-api-url': url2
78
- });
79
- await client2.connect(mcpUrl);
80
- try {
81
- await client2.callTool('list_projects', { per_page: 1 });
82
- console.log(' ✓ Request 2 (localhost) succeeded');
83
- }
84
- catch (e) {
85
- // It might fail if localhost isn't listening or something, but it shouldn't be pool full
86
- console.log(' ! Request 2 failed:', e);
87
- if (String(e).includes('capacity reached')) {
88
- assert.fail('Request 2 failed with pool limit error prematurely');
89
- }
90
- }
91
- await client2.disconnect();
92
- // URL 3: gitlab-3.example.com (Fake, distinct string)
93
- // This should trigger the pool limit check
94
- const client3 = new CustomHeaderClient({
95
- 'authorization': `Bearer ${MOCK_TOKEN}`,
96
- 'x-gitlab-api-url': 'https://gitlab-3.example.com/api/v4'
97
- });
98
- await client3.connect(mcpUrl);
99
- try {
100
- await client3.callTool('list_projects', { per_page: 1 });
101
- assert.fail('Request 3 should have failed with pool limit error');
102
- }
103
- catch (error) {
104
- console.log(' ℹ️ Error received:', error.message);
105
- assert.ok(error.message.includes('capacity reached') || error.message.includes('pool is full'), 'Error should be about server capacity');
106
- }
107
- await client3.disconnect();
108
- });
109
- });
@@ -1,34 +0,0 @@
1
- /**
2
- * MCP Client Interface and error classes for testing
3
- */
4
- /**
5
- * Base error class for MCP client errors
6
- */
7
- export class MCPClientError extends Error {
8
- cause;
9
- constructor(message, cause) {
10
- super(message);
11
- this.cause = cause;
12
- this.name = 'MCPClientError';
13
- }
14
- }
15
- /**
16
- * Connection error for MCP clients
17
- */
18
- export class MCPConnectionError extends MCPClientError {
19
- constructor(message, cause) {
20
- super(message, cause);
21
- this.name = 'MCPConnectionError';
22
- }
23
- }
24
- /**
25
- * Tool call error for MCP clients
26
- */
27
- export class MCPToolCallError extends MCPClientError {
28
- toolName;
29
- constructor(message, toolName, cause) {
30
- super(message, cause);
31
- this.toolName = toolName;
32
- this.name = 'MCPToolCallError';
33
- }
34
- }
@@ -1,122 +0,0 @@
1
- /**
2
- * Custom Header MCP Client for Testing Remote Authorization
3
- * Extends StreamableHTTPTestClient to support custom headers
4
- */
5
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
6
- import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
7
- /**
8
- * MCP client with support for custom HTTP headers
9
- * Useful for testing remote authorization scenarios
10
- */
11
- export class CustomHeaderClient {
12
- client;
13
- transport = null;
14
- customHeaders;
15
- timeout;
16
- constructor(options = {}) {
17
- // Support both old signature (headers only) and new options object
18
- if ('headers' in options || 'timeout' in options || 'clientName' in options) {
19
- const opts = options;
20
- this.customHeaders = opts.headers || {};
21
- this.timeout = opts.timeout || 30000;
22
- this.client = new Client({
23
- name: opts.clientName || "test-client-with-headers",
24
- version: opts.clientVersion || "1.0.0"
25
- });
26
- }
27
- else {
28
- // Backward compatible: treat options as headers record
29
- this.customHeaders = options;
30
- this.timeout = 30000;
31
- this.client = new Client({ name: "test-client-with-headers", version: "1.0.0" });
32
- }
33
- }
34
- /**
35
- * Connect to MCP server with custom headers
36
- */
37
- async connect(url) {
38
- if (this.transport) {
39
- throw new Error('Client is already connected');
40
- }
41
- try {
42
- this.transport = new StreamableHTTPClientTransport(new URL(url), {
43
- requestInit: {
44
- headers: this.customHeaders
45
- }
46
- });
47
- await this.client.connect(this.transport);
48
- }
49
- catch (error) {
50
- this.transport = null;
51
- throw new Error(`Failed to connect: ${error instanceof Error ? error.message : String(error)}`);
52
- }
53
- }
54
- /**
55
- * Disconnect from server
56
- */
57
- async disconnect() {
58
- if (this.transport) {
59
- try {
60
- await this.transport.close();
61
- }
62
- catch (error) {
63
- // Silently ignore disconnect errors in tests
64
- // In production, you'd want proper logging
65
- }
66
- finally {
67
- this.transport = null;
68
- }
69
- }
70
- }
71
- /**
72
- * Get session ID from transport (useful for testing)
73
- */
74
- getSessionId() {
75
- return this.transport?.sessionId;
76
- }
77
- /**
78
- * Update custom headers (creates new connection if already connected)
79
- */
80
- setHeaders(headers) {
81
- if (this.transport) {
82
- throw new Error('Cannot update headers while connected. Disconnect first.');
83
- }
84
- this.customHeaders = headers;
85
- }
86
- /**
87
- * List available tools from server
88
- */
89
- async listTools() {
90
- if (!this.transport) {
91
- throw new Error('Client is not connected');
92
- }
93
- try {
94
- const response = await this.client.listTools();
95
- return response;
96
- }
97
- catch (error) {
98
- throw new Error(`Failed to list tools: ${error instanceof Error ? error.message : String(error)}`);
99
- }
100
- }
101
- /**
102
- * Call a tool on the server
103
- */
104
- async callTool(name, arguments_ = {}) {
105
- if (!this.transport) {
106
- throw new Error('Client is not connected');
107
- }
108
- try {
109
- const response = await this.client.callTool({ name, arguments: arguments_ });
110
- return response;
111
- }
112
- catch (error) {
113
- throw new Error(`Failed to call tool '${name}': ${error instanceof Error ? error.message : String(error)}`);
114
- }
115
- }
116
- /**
117
- * Get client connection status
118
- */
119
- get isConnected() {
120
- return this.transport !== null;
121
- }
122
- }
@@ -1,95 +0,0 @@
1
- /**
2
- * SSE MCP Client for testing
3
- */
4
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
5
- import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
6
- import { MCPConnectionError, MCPToolCallError } from "./client.js";
7
- export class SSETestClient {
8
- client;
9
- transport = null;
10
- constructor() {
11
- this.client = new Client({ name: "test-client", version: "1.0.0" });
12
- }
13
- /**
14
- * Connect to MCP server via SSE
15
- */
16
- async connect(url) {
17
- if (this.transport) {
18
- throw new MCPConnectionError('Client is already connected');
19
- }
20
- try {
21
- this.transport = new SSEClientTransport(new URL(url));
22
- await this.client.connect(this.transport);
23
- }
24
- catch (error) {
25
- this.transport = null;
26
- throw new MCPConnectionError(`Failed to connect to SSE server: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
27
- }
28
- }
29
- /**
30
- * Disconnect from server
31
- */
32
- async disconnect() {
33
- if (this.transport) {
34
- try {
35
- await this.transport.close();
36
- }
37
- catch (error) {
38
- // Log but don't throw on disconnect errors
39
- console.warn('Warning during disconnect:', error);
40
- }
41
- finally {
42
- this.transport = null;
43
- }
44
- }
45
- }
46
- /**
47
- * List available tools from server
48
- */
49
- async listTools() {
50
- if (!this.transport) {
51
- throw new MCPConnectionError('Client is not connected');
52
- }
53
- try {
54
- const response = await this.client.listTools();
55
- return response;
56
- }
57
- catch (error) {
58
- throw new MCPToolCallError(`Failed to list tools: ${error instanceof Error ? error.message : String(error)}`, 'listTools', error instanceof Error ? error : undefined);
59
- }
60
- }
61
- /**
62
- * Call a tool on the server
63
- */
64
- async callTool(name, arguments_ = {}) {
65
- if (!this.transport) {
66
- throw new MCPConnectionError('Client is not connected');
67
- }
68
- try {
69
- const response = await this.client.callTool({ name, arguments: arguments_ });
70
- // Ensure the response conforms to CallToolResult interface
71
- return response;
72
- }
73
- catch (error) {
74
- throw new MCPToolCallError(`Failed to call tool '${name}': ${error instanceof Error ? error.message : String(error)}`, name, error instanceof Error ? error : undefined);
75
- }
76
- }
77
- /**
78
- * Test connection by listing tools
79
- */
80
- async testConnection() {
81
- try {
82
- const tools = await this.listTools();
83
- return Array.isArray(tools.tools) && tools.tools.length > 0;
84
- }
85
- catch (error) {
86
- return false;
87
- }
88
- }
89
- /**
90
- * Get client connection status
91
- */
92
- get isConnected() {
93
- return this.transport !== null;
94
- }
95
- }
@@ -1,113 +0,0 @@
1
- /**
2
- * Stdio MCP Client for testing
3
- */
4
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
5
- import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
6
- import { MCPConnectionError, MCPToolCallError } from "./client.js";
7
- export class StdioTestClient {
8
- client;
9
- transport = null;
10
- constructor() {
11
- this.client = new Client({ name: "test-client", version: "1.0.0" });
12
- }
13
- /**
14
- * Connect to MCP server via stdio
15
- */
16
- async connect(serverPath, env) {
17
- if (this.transport) {
18
- throw new MCPConnectionError('Client is already connected');
19
- }
20
- try {
21
- const command = process.execPath;
22
- const args = [serverPath];
23
- // Prepare environment variables for the server process
24
- const serverEnv = {};
25
- // Copy process.env, filtering out undefined values
26
- for (const [key, value] of Object.entries(process.env)) {
27
- if (value !== undefined) {
28
- serverEnv[key] = value;
29
- }
30
- }
31
- // Add custom environment variables
32
- if (env) {
33
- Object.assign(serverEnv, env);
34
- }
35
- this.transport = new StdioClientTransport({
36
- command,
37
- args,
38
- env: serverEnv
39
- });
40
- await this.client.connect(this.transport);
41
- }
42
- catch (error) {
43
- this.transport = null;
44
- throw new MCPConnectionError(`Failed to connect to stdio server: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
45
- }
46
- }
47
- /**
48
- * Disconnect from server
49
- */
50
- async disconnect() {
51
- if (this.transport) {
52
- try {
53
- await this.transport.close();
54
- }
55
- catch (error) {
56
- // Log but don't throw on disconnect errors
57
- console.warn('Warning during disconnect:', error);
58
- }
59
- finally {
60
- this.transport = null;
61
- }
62
- }
63
- }
64
- /**
65
- * List available tools from server
66
- */
67
- async listTools() {
68
- if (!this.transport) {
69
- throw new MCPConnectionError('Client is not connected');
70
- }
71
- try {
72
- const response = await this.client.listTools();
73
- return response;
74
- }
75
- catch (error) {
76
- throw new MCPToolCallError(`Failed to list tools: ${error instanceof Error ? error.message : String(error)}`, 'listTools', error instanceof Error ? error : undefined);
77
- }
78
- }
79
- /**
80
- * Call a tool on the server
81
- */
82
- async callTool(name, arguments_ = {}) {
83
- if (!this.transport) {
84
- throw new MCPConnectionError('Client is not connected');
85
- }
86
- try {
87
- const response = await this.client.callTool({ name, arguments: arguments_ });
88
- // Ensure the response conforms to CallToolResult interface
89
- return response;
90
- }
91
- catch (error) {
92
- throw new MCPToolCallError(`Failed to call tool '${name}': ${error instanceof Error ? error.message : String(error)}`, name, error instanceof Error ? error : undefined);
93
- }
94
- }
95
- /**
96
- * Test connection by listing tools
97
- */
98
- async testConnection() {
99
- try {
100
- const tools = await this.listTools();
101
- return Array.isArray(tools.tools) && tools.tools.length > 0;
102
- }
103
- catch (error) {
104
- return false;
105
- }
106
- }
107
- /**
108
- * Get client connection status
109
- */
110
- get isConnected() {
111
- return this.transport !== null;
112
- }
113
- }
@@ -1,95 +0,0 @@
1
- /**
2
- * Streamable HTTP MCP Client for testing
3
- */
4
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
5
- import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
6
- import { MCPConnectionError, MCPToolCallError } from "./client.js";
7
- export class StreamableHTTPTestClient {
8
- client;
9
- transport = null;
10
- constructor() {
11
- this.client = new Client({ name: "test-client", version: "1.0.0" });
12
- }
13
- /**
14
- * Connect to MCP server via Streamable HTTP
15
- */
16
- async connect(url) {
17
- if (this.transport) {
18
- throw new MCPConnectionError('Client is already connected');
19
- }
20
- try {
21
- this.transport = new StreamableHTTPClientTransport(new URL(url));
22
- await this.client.connect(this.transport);
23
- }
24
- catch (error) {
25
- this.transport = null;
26
- throw new MCPConnectionError(`Failed to connect to Streamable HTTP server: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
27
- }
28
- }
29
- /**
30
- * Disconnect from server
31
- */
32
- async disconnect() {
33
- if (this.transport) {
34
- try {
35
- await this.transport.close();
36
- }
37
- catch (error) {
38
- // Log but don't throw on disconnect errors
39
- console.warn('Warning during disconnect:', error);
40
- }
41
- finally {
42
- this.transport = null;
43
- }
44
- }
45
- }
46
- /**
47
- * List available tools from server
48
- */
49
- async listTools() {
50
- if (!this.transport) {
51
- throw new MCPConnectionError('Client is not connected');
52
- }
53
- try {
54
- const response = await this.client.listTools();
55
- return response;
56
- }
57
- catch (error) {
58
- throw new MCPToolCallError(`Failed to list tools: ${error instanceof Error ? error.message : String(error)}`, 'listTools', error instanceof Error ? error : undefined);
59
- }
60
- }
61
- /**
62
- * Call a tool on the server
63
- */
64
- async callTool(name, arguments_ = {}) {
65
- if (!this.transport) {
66
- throw new MCPConnectionError('Client is not connected');
67
- }
68
- try {
69
- const response = await this.client.callTool({ name, arguments: arguments_ });
70
- // Ensure the response conforms to CallToolResult interface
71
- return response;
72
- }
73
- catch (error) {
74
- throw new MCPToolCallError(`Failed to call tool '${name}': ${error instanceof Error ? error.message : String(error)}`, name, error instanceof Error ? error : undefined);
75
- }
76
- }
77
- /**
78
- * Test connection by listing tools
79
- */
80
- async testConnection() {
81
- try {
82
- const tools = await this.listTools();
83
- return Array.isArray(tools.tools) && tools.tools.length > 0;
84
- }
85
- catch (error) {
86
- return false;
87
- }
88
- }
89
- /**
90
- * Get client connection status
91
- */
92
- get isConnected() {
93
- return this.transport !== null;
94
- }
95
- }
@@ -1,97 +0,0 @@
1
- /**
2
- * Tests for GITLAB_OAUTH_ALLOWED_GROUPS config resolution.
3
- *
4
- * Verifies that:
5
- * - The new GITLAB_OAUTH_ALLOWED_GROUPS env var is preferred when set.
6
- * - The deprecated GITLAB_ALLOWED_GROUPS is accepted as a fallback and
7
- * sets the deprecation flag so callers can emit a warning.
8
- * - When both are set, the new var wins and GITLAB_ALLOWED_GROUPS_RAW remains
9
- * set, so callers can emit a "set but ignored" warning.
10
- *
11
- * config.ts reads process.env at module load, so each scenario runs in a
12
- * fresh child process — same pattern as test/stateless/config-ttl.test.ts.
13
- */
14
- import assert from "node:assert/strict";
15
- import { execFileSync } from "node:child_process";
16
- import * as path from "node:path";
17
- import * as url from "node:url";
18
- import { describe, test } from "node:test";
19
- const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
20
- const CONFIG_PATH = path.resolve(__dirname, "../config.ts");
21
- function loadConfig(env) {
22
- const script = `
23
- import(${JSON.stringify(url.pathToFileURL(CONFIG_PATH).href)}).then((m) => {
24
- const out = {
25
- GITLAB_OAUTH_ALLOWED_GROUPS: m.GITLAB_OAUTH_ALLOWED_GROUPS ?? null,
26
- GITLAB_OAUTH_ALLOWED_GROUPS_RAW: m.GITLAB_OAUTH_ALLOWED_GROUPS_RAW ?? null,
27
- GITLAB_ALLOWED_GROUPS_RAW: m.GITLAB_ALLOWED_GROUPS_RAW ?? null,
28
- };
29
- process.stdout.write(JSON.stringify(out));
30
- }).catch((err) => {
31
- process.stderr.write(String(err && err.stack || err));
32
- process.exit(2);
33
- });
34
- `;
35
- const childEnv = {
36
- ...process.env,
37
- };
38
- delete childEnv.GITLAB_OAUTH_ALLOWED_GROUPS;
39
- delete childEnv.GITLAB_ALLOWED_GROUPS;
40
- for (const [k, v] of Object.entries(env)) {
41
- if (v === undefined) {
42
- delete childEnv[k];
43
- }
44
- else {
45
- childEnv[k] = v;
46
- }
47
- }
48
- const stdout = execFileSync(process.execPath, ["--import", "tsx/esm", "--input-type=module", "--eval", script], { env: childEnv, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
49
- return JSON.parse(stdout);
50
- }
51
- describe("config.ts — GITLAB_OAUTH_ALLOWED_GROUPS resolution", () => {
52
- test("neither var set — resolved value and raws are null", () => {
53
- const cfg = loadConfig({});
54
- assert.equal(cfg.GITLAB_OAUTH_ALLOWED_GROUPS, null);
55
- assert.equal(cfg.GITLAB_OAUTH_ALLOWED_GROUPS_RAW, null);
56
- assert.equal(cfg.GITLAB_ALLOWED_GROUPS_RAW, null);
57
- });
58
- test("only new var set — resolved correctly, deprecated raw is null", () => {
59
- const cfg = loadConfig({ GITLAB_OAUTH_ALLOWED_GROUPS: "my-org" });
60
- assert.deepEqual(cfg.GITLAB_OAUTH_ALLOWED_GROUPS, ["my-org"]);
61
- assert.equal(cfg.GITLAB_OAUTH_ALLOWED_GROUPS_RAW, "my-org");
62
- assert.equal(cfg.GITLAB_ALLOWED_GROUPS_RAW, null);
63
- });
64
- test("only deprecated var set — resolved via fallback, deprecated raw is set", () => {
65
- const cfg = loadConfig({ GITLAB_ALLOWED_GROUPS: "my-org" });
66
- assert.deepEqual(cfg.GITLAB_OAUTH_ALLOWED_GROUPS, ["my-org"]);
67
- assert.equal(cfg.GITLAB_ALLOWED_GROUPS_RAW, "my-org");
68
- assert.equal(cfg.GITLAB_OAUTH_ALLOWED_GROUPS_RAW, null);
69
- });
70
- test("both vars set — new var wins, both raws are set (triggers 'set but ignored' warning)", () => {
71
- const cfg = loadConfig({
72
- GITLAB_OAUTH_ALLOWED_GROUPS: "new-org",
73
- GITLAB_ALLOWED_GROUPS: "old-org",
74
- });
75
- assert.deepEqual(cfg.GITLAB_OAUTH_ALLOWED_GROUPS, ["new-org"]);
76
- assert.equal(cfg.GITLAB_OAUTH_ALLOWED_GROUPS_RAW, "new-org");
77
- assert.equal(cfg.GITLAB_ALLOWED_GROUPS_RAW, "old-org");
78
- });
79
- test("comma-separated values are split and trimmed", () => {
80
- const cfg = loadConfig({
81
- GITLAB_OAUTH_ALLOWED_GROUPS: "my-org/team-a , my-org/team-b , my-org",
82
- });
83
- assert.deepEqual(cfg.GITLAB_OAUTH_ALLOWED_GROUPS, [
84
- "my-org/team-a",
85
- "my-org/team-b",
86
- "my-org",
87
- ]);
88
- });
89
- test("empty string resolves to null", () => {
90
- const cfg = loadConfig({ GITLAB_OAUTH_ALLOWED_GROUPS: "" });
91
- assert.equal(cfg.GITLAB_OAUTH_ALLOWED_GROUPS, null);
92
- });
93
- test("whitespace-only entries are filtered out", () => {
94
- const cfg = loadConfig({ GITLAB_OAUTH_ALLOWED_GROUPS: " , , " });
95
- assert.equal(cfg.GITLAB_OAUTH_ALLOWED_GROUPS, null);
96
- });
97
- });