@zereight/mcp-gitlab 2.0.11 â 2.0.18
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.md +2 -0
- package/build/gitlab-client-pool.js +113 -0
- package/build/index.js +450 -356
- package/build/test/client-pool-test.js +109 -0
- package/build/test/dynamic-api-url-test.js +304 -0
- package/build/test/dynamic-routing-tests.js +442 -0
- package/build/test/multi-server-test.js +182 -0
- package/build/test/remote-auth-simple-test.js +2 -0
- package/build/test/utils/mock-gitlab-server.js +73 -4
- package/build/test/utils/server-launcher.js +25 -9
- package/package.json +9 -5
|
@@ -0,0 +1,109 @@
|
|
|
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(MOCK_GITLAB_PORT_BASE);
|
|
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
|
+
});
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic GitLab API URL Test Suite
|
|
3
|
+
* Tests the ability to connect to multiple GitLab instances via custom headers
|
|
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_1 = 'glpat-mock-token-instance-1';
|
|
12
|
+
const MOCK_TOKEN_2 = 'glpat-mock-token-instance-2';
|
|
13
|
+
// Port ranges
|
|
14
|
+
const MOCK_GITLAB_PORT_BASE_1 = 9100;
|
|
15
|
+
const MOCK_GITLAB_PORT_BASE_2 = 9200;
|
|
16
|
+
const MCP_SERVER_PORT_BASE = 3100;
|
|
17
|
+
console.log('đ Dynamic GitLab API URL Test Suite');
|
|
18
|
+
console.log('');
|
|
19
|
+
describe('Dynamic API URL - Multiple GitLab Instances', () => {
|
|
20
|
+
let mcpUrl;
|
|
21
|
+
let mockGitLab1;
|
|
22
|
+
let mockGitLab2;
|
|
23
|
+
let mockGitLabUrl1;
|
|
24
|
+
let mockGitLabUrl2;
|
|
25
|
+
let servers = [];
|
|
26
|
+
before(async () => {
|
|
27
|
+
// Start first mock GitLab server
|
|
28
|
+
const mockPort1 = await findMockServerPort(MOCK_GITLAB_PORT_BASE_1);
|
|
29
|
+
mockGitLab1 = new MockGitLabServer({
|
|
30
|
+
port: mockPort1,
|
|
31
|
+
validTokens: [MOCK_TOKEN_1]
|
|
32
|
+
});
|
|
33
|
+
await mockGitLab1.start();
|
|
34
|
+
mockGitLabUrl1 = mockGitLab1.getUrl();
|
|
35
|
+
// Start second mock GitLab server
|
|
36
|
+
const mockPort2 = await findMockServerPort(MOCK_GITLAB_PORT_BASE_2);
|
|
37
|
+
mockGitLab2 = new MockGitLabServer({
|
|
38
|
+
port: mockPort2,
|
|
39
|
+
validTokens: [MOCK_TOKEN_2]
|
|
40
|
+
});
|
|
41
|
+
await mockGitLab2.start();
|
|
42
|
+
mockGitLabUrl2 = mockGitLab2.getUrl();
|
|
43
|
+
// Start MCP server with dynamic API URL enabled
|
|
44
|
+
const mcpPort = await findAvailablePort(MCP_SERVER_PORT_BASE);
|
|
45
|
+
const server = await launchServer({
|
|
46
|
+
mode: TransportMode.STREAMABLE_HTTP,
|
|
47
|
+
port: mcpPort,
|
|
48
|
+
timeout: 5000,
|
|
49
|
+
env: {
|
|
50
|
+
STREAMABLE_HTTP: 'true',
|
|
51
|
+
REMOTE_AUTHORIZATION: 'true',
|
|
52
|
+
ENABLE_DYNAMIC_API_URL: 'true',
|
|
53
|
+
GITLAB_READ_ONLY_MODE: 'true',
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
servers.push(server);
|
|
57
|
+
mcpUrl = `http://${HOST}:${mcpPort}/mcp`;
|
|
58
|
+
console.log(`Mock GitLab Instance 1: ${mockGitLabUrl1}`);
|
|
59
|
+
console.log(`Mock GitLab Instance 2: ${mockGitLabUrl2}`);
|
|
60
|
+
console.log(`MCP Server: ${mcpUrl}`);
|
|
61
|
+
});
|
|
62
|
+
after(async () => {
|
|
63
|
+
cleanupServers(servers);
|
|
64
|
+
if (mockGitLab1) {
|
|
65
|
+
await mockGitLab1.stop();
|
|
66
|
+
}
|
|
67
|
+
if (mockGitLab2) {
|
|
68
|
+
await mockGitLab2.stop();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
test('should connect to first GitLab instance with custom API URL', async () => {
|
|
72
|
+
const client = new CustomHeaderClient({
|
|
73
|
+
'authorization': `Bearer ${MOCK_TOKEN_1}`,
|
|
74
|
+
'x-gitlab-api-url': mockGitLabUrl1
|
|
75
|
+
});
|
|
76
|
+
await client.connect(mcpUrl);
|
|
77
|
+
const tools = await client.listTools();
|
|
78
|
+
assert.ok(tools.tools.length > 0, 'Should have tools');
|
|
79
|
+
console.log(` â Connected to instance 1, got ${tools.tools.length} tools`);
|
|
80
|
+
await client.disconnect();
|
|
81
|
+
});
|
|
82
|
+
test('should connect to second GitLab instance with different API URL', async () => {
|
|
83
|
+
const client = new CustomHeaderClient({
|
|
84
|
+
'authorization': `Bearer ${MOCK_TOKEN_2}`,
|
|
85
|
+
'x-gitlab-api-url': mockGitLabUrl2
|
|
86
|
+
});
|
|
87
|
+
await client.connect(mcpUrl);
|
|
88
|
+
const tools = await client.listTools();
|
|
89
|
+
assert.ok(tools.tools.length > 0, 'Should have tools');
|
|
90
|
+
console.log(` â Connected to instance 2, got ${tools.tools.length} tools`);
|
|
91
|
+
await client.disconnect();
|
|
92
|
+
});
|
|
93
|
+
test('should handle multiple concurrent connections to different instances', async () => {
|
|
94
|
+
const client1 = new CustomHeaderClient({
|
|
95
|
+
'authorization': `Bearer ${MOCK_TOKEN_1}`,
|
|
96
|
+
'x-gitlab-api-url': mockGitLabUrl1
|
|
97
|
+
});
|
|
98
|
+
const client2 = new CustomHeaderClient({
|
|
99
|
+
'authorization': `Bearer ${MOCK_TOKEN_2}`,
|
|
100
|
+
'x-gitlab-api-url': mockGitLabUrl2
|
|
101
|
+
});
|
|
102
|
+
// Connect both clients
|
|
103
|
+
await Promise.all([
|
|
104
|
+
client1.connect(mcpUrl),
|
|
105
|
+
client2.connect(mcpUrl)
|
|
106
|
+
]);
|
|
107
|
+
// List tools from both
|
|
108
|
+
const [tools1, tools2] = await Promise.all([
|
|
109
|
+
client1.listTools(),
|
|
110
|
+
client2.listTools()
|
|
111
|
+
]);
|
|
112
|
+
assert.ok(tools1.tools.length > 0, 'Instance 1 should have tools');
|
|
113
|
+
assert.ok(tools2.tools.length > 0, 'Instance 2 should have tools');
|
|
114
|
+
console.log(' â Both instances accessible concurrently');
|
|
115
|
+
// Disconnect both
|
|
116
|
+
await Promise.all([
|
|
117
|
+
client1.disconnect(),
|
|
118
|
+
client2.disconnect()
|
|
119
|
+
]);
|
|
120
|
+
});
|
|
121
|
+
test('should reject invalid API URL format', async () => {
|
|
122
|
+
const client = new CustomHeaderClient({
|
|
123
|
+
'authorization': `Bearer ${MOCK_TOKEN_1}`,
|
|
124
|
+
'x-gitlab-api-url': 'not-a-valid-url'
|
|
125
|
+
});
|
|
126
|
+
try {
|
|
127
|
+
await client.connect(mcpUrl);
|
|
128
|
+
await client.listTools();
|
|
129
|
+
await client.disconnect();
|
|
130
|
+
assert.fail('Should have rejected invalid URL');
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
assert.ok(error instanceof Error);
|
|
134
|
+
console.log(' â Correctly rejected invalid URL format');
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
test('should reject connection with wrong token for instance', async () => {
|
|
138
|
+
const client = new CustomHeaderClient({
|
|
139
|
+
'authorization': `Bearer ${MOCK_TOKEN_1}`, // Token for instance 1
|
|
140
|
+
'x-gitlab-api-url': mockGitLabUrl2 // But connecting to instance 2
|
|
141
|
+
});
|
|
142
|
+
try {
|
|
143
|
+
await client.connect(mcpUrl);
|
|
144
|
+
await client.listTools();
|
|
145
|
+
await client.disconnect();
|
|
146
|
+
assert.fail('Should have rejected wrong token');
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
assert.ok(error instanceof Error);
|
|
150
|
+
console.log(' â Correctly rejected wrong token for instance');
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
test('should maintain separate sessions for different API URLs', async () => {
|
|
154
|
+
const client1 = new CustomHeaderClient({
|
|
155
|
+
'authorization': `Bearer ${MOCK_TOKEN_1}`,
|
|
156
|
+
'x-gitlab-api-url': mockGitLabUrl1
|
|
157
|
+
});
|
|
158
|
+
const client2 = new CustomHeaderClient({
|
|
159
|
+
'authorization': `Bearer ${MOCK_TOKEN_2}`,
|
|
160
|
+
'x-gitlab-api-url': mockGitLabUrl2
|
|
161
|
+
});
|
|
162
|
+
// Connect both
|
|
163
|
+
await client1.connect(mcpUrl);
|
|
164
|
+
await client2.connect(mcpUrl);
|
|
165
|
+
// Get session IDs
|
|
166
|
+
const sessionId1 = client1.getSessionId();
|
|
167
|
+
const sessionId2 = client2.getSessionId();
|
|
168
|
+
assert.ok(sessionId1, 'Session 1 should exist');
|
|
169
|
+
assert.ok(sessionId2, 'Session 2 should exist');
|
|
170
|
+
assert.notStrictEqual(sessionId1, sessionId2, 'Sessions should be different');
|
|
171
|
+
console.log(' â Separate sessions maintained for different instances');
|
|
172
|
+
// Make requests from both sessions
|
|
173
|
+
const [tools1, tools2] = await Promise.all([
|
|
174
|
+
client1.listTools(),
|
|
175
|
+
client2.listTools()
|
|
176
|
+
]);
|
|
177
|
+
assert.ok(tools1.tools.length > 0, 'Instance 1 should work');
|
|
178
|
+
assert.ok(tools2.tools.length > 0, 'Instance 2 should work');
|
|
179
|
+
console.log(' â Both sessions work independently');
|
|
180
|
+
await client1.disconnect();
|
|
181
|
+
await client2.disconnect();
|
|
182
|
+
});
|
|
183
|
+
test('should normalize API URLs correctly', async () => {
|
|
184
|
+
// Test with URL that needs normalization (no /api/v4)
|
|
185
|
+
const client = new CustomHeaderClient({
|
|
186
|
+
'authorization': `Bearer ${MOCK_TOKEN_1}`,
|
|
187
|
+
'x-gitlab-api-url': mockGitLabUrl1 // Without /api/v4
|
|
188
|
+
});
|
|
189
|
+
await client.connect(mcpUrl);
|
|
190
|
+
const tools = await client.listTools();
|
|
191
|
+
assert.ok(tools.tools.length > 0, 'Should work with normalized URL');
|
|
192
|
+
console.log(' â URL normalization works correctly');
|
|
193
|
+
await client.disconnect();
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
describe('Dynamic API URL - Connection Pool', () => {
|
|
197
|
+
let mcpUrl;
|
|
198
|
+
let metricsUrl;
|
|
199
|
+
let mockGitLab1;
|
|
200
|
+
let mockGitLab2;
|
|
201
|
+
let mockGitLabUrl1;
|
|
202
|
+
let mockGitLabUrl2;
|
|
203
|
+
let servers = [];
|
|
204
|
+
before(async () => {
|
|
205
|
+
// Start mock GitLab servers
|
|
206
|
+
const mockPort1 = await findMockServerPort(MOCK_GITLAB_PORT_BASE_1 + 50);
|
|
207
|
+
mockGitLab1 = new MockGitLabServer({
|
|
208
|
+
port: mockPort1,
|
|
209
|
+
validTokens: [MOCK_TOKEN_1]
|
|
210
|
+
});
|
|
211
|
+
await mockGitLab1.start();
|
|
212
|
+
mockGitLabUrl1 = mockGitLab1.getUrl();
|
|
213
|
+
const mockPort2 = await findMockServerPort(MOCK_GITLAB_PORT_BASE_2 + 50);
|
|
214
|
+
mockGitLab2 = new MockGitLabServer({
|
|
215
|
+
port: mockPort2,
|
|
216
|
+
validTokens: [MOCK_TOKEN_2]
|
|
217
|
+
});
|
|
218
|
+
await mockGitLab2.start();
|
|
219
|
+
mockGitLabUrl2 = mockGitLab2.getUrl();
|
|
220
|
+
// Start MCP server
|
|
221
|
+
const mcpPort = await findAvailablePort(MCP_SERVER_PORT_BASE + 50);
|
|
222
|
+
const server = await launchServer({
|
|
223
|
+
mode: TransportMode.STREAMABLE_HTTP,
|
|
224
|
+
port: mcpPort,
|
|
225
|
+
timeout: 5000,
|
|
226
|
+
env: {
|
|
227
|
+
STREAMABLE_HTTP: 'true',
|
|
228
|
+
REMOTE_AUTHORIZATION: 'true',
|
|
229
|
+
ENABLE_DYNAMIC_API_URL: 'true',
|
|
230
|
+
GITLAB_CLIENT_POOL_SIZE: '5',
|
|
231
|
+
GITLAB_CLIENT_IDLE_TIMEOUT: '30000',
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
servers.push(server);
|
|
235
|
+
mcpUrl = `http://${HOST}:${mcpPort}/mcp`;
|
|
236
|
+
metricsUrl = `http://${HOST}:${mcpPort}/metrics`;
|
|
237
|
+
console.log(`MCP Server: ${mcpUrl}`);
|
|
238
|
+
console.log(`Metrics URL: ${metricsUrl}`);
|
|
239
|
+
});
|
|
240
|
+
after(async () => {
|
|
241
|
+
cleanupServers(servers);
|
|
242
|
+
if (mockGitLab1) {
|
|
243
|
+
await mockGitLab1.stop();
|
|
244
|
+
}
|
|
245
|
+
if (mockGitLab2) {
|
|
246
|
+
await mockGitLab2.stop();
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
test('should track pool statistics via metrics endpoint', async () => {
|
|
250
|
+
// Make some connections first
|
|
251
|
+
const client1 = new CustomHeaderClient({
|
|
252
|
+
'authorization': `Bearer ${MOCK_TOKEN_1}`,
|
|
253
|
+
'x-gitlab-api-url': mockGitLabUrl1
|
|
254
|
+
});
|
|
255
|
+
const client2 = new CustomHeaderClient({
|
|
256
|
+
'authorization': `Bearer ${MOCK_TOKEN_2}`,
|
|
257
|
+
'x-gitlab-api-url': mockGitLabUrl2
|
|
258
|
+
});
|
|
259
|
+
await client1.connect(mcpUrl);
|
|
260
|
+
await client2.connect(mcpUrl);
|
|
261
|
+
await client1.listTools();
|
|
262
|
+
await client2.listTools();
|
|
263
|
+
// Check metrics
|
|
264
|
+
const response = await fetch(metricsUrl);
|
|
265
|
+
assert.ok(response.ok, 'Metrics endpoint should be accessible');
|
|
266
|
+
const metrics = await response.json();
|
|
267
|
+
assert.ok(metrics.gitlabClientPool, 'Should have pool metrics');
|
|
268
|
+
assert.ok(typeof metrics.gitlabClientPool.size === 'number', 'Should have pool size');
|
|
269
|
+
assert.ok(typeof metrics.gitlabClientPool.maxSize === 'number', 'Should have max size');
|
|
270
|
+
console.log(' â Pool metrics available');
|
|
271
|
+
console.log(` âšī¸ Pool size: ${metrics.gitlabClientPool.size}/${metrics.gitlabClientPool.maxSize}`);
|
|
272
|
+
await client1.disconnect();
|
|
273
|
+
await client2.disconnect();
|
|
274
|
+
});
|
|
275
|
+
test('should reuse connections for same API URL', async () => {
|
|
276
|
+
// Get initial metrics
|
|
277
|
+
const response1 = await fetch(metricsUrl);
|
|
278
|
+
const metrics1 = await response1.json();
|
|
279
|
+
const initialSize = metrics1.gitlabClientPool?.size || 0;
|
|
280
|
+
// Create multiple clients to same instance
|
|
281
|
+
const clients = [];
|
|
282
|
+
for (let i = 0; i < 3; i++) {
|
|
283
|
+
const client = new CustomHeaderClient({
|
|
284
|
+
'authorization': `Bearer ${MOCK_TOKEN_1}`,
|
|
285
|
+
'x-gitlab-api-url': mockGitLabUrl1
|
|
286
|
+
});
|
|
287
|
+
await client.connect(mcpUrl);
|
|
288
|
+
await client.listTools();
|
|
289
|
+
clients.push(client);
|
|
290
|
+
}
|
|
291
|
+
// Check metrics - should not have created 3 new pool entries
|
|
292
|
+
const response2 = await fetch(metricsUrl);
|
|
293
|
+
const metrics2 = await response2.json();
|
|
294
|
+
const finalSize = metrics2.gitlabClientPool?.size || 0;
|
|
295
|
+
// Pool size should increase by at most 1 (for the shared URL)
|
|
296
|
+
assert.ok(finalSize - initialSize <= 1, 'Should reuse connection for same URL');
|
|
297
|
+
console.log(' â Connection reuse working');
|
|
298
|
+
console.log(` âšī¸ Pool size change: ${initialSize} â ${finalSize}`);
|
|
299
|
+
// Cleanup
|
|
300
|
+
for (const client of clients) {
|
|
301
|
+
await client.disconnect();
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
});
|