@rishibhushan/jenkins-mcp-server 1.1.0 → 1.1.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.
@@ -5,7 +5,8 @@
5
5
  * This wrapper handles:
6
6
  * - Python version detection (cross-platform)
7
7
  * - Virtual environment creation
8
- * - Dependency installation
8
+ * - Smart proxy detection and handling (auto-detects corporate vs public networks)
9
+ * - Dependency installation with retry logic
9
10
  * - Server execution
10
11
  *
11
12
  * Supports: Windows, macOS, Linux
@@ -26,7 +27,9 @@ const colors = {
26
27
  green: '\x1b[32m',
27
28
  yellow: '\x1b[33m',
28
29
  red: '\x1b[31m',
29
- blue: '\x1b[34m'
30
+ blue: '\x1b[34m',
31
+ cyan: '\x1b[36m',
32
+ bold: '\x1b[1m'
30
33
  };
31
34
 
32
35
  function log(message, color = 'reset') {
@@ -40,6 +43,93 @@ function error(message) {
40
43
  console.error(`${colors.red}ERROR: ${message}${colors.reset}`);
41
44
  }
42
45
 
46
+ function warning(message) {
47
+ console.error(`${colors.yellow}WARNING: ${message}${colors.reset}`);
48
+ }
49
+
50
+ function info(message) {
51
+ console.error(`${colors.cyan}ℹ ${message}${colors.reset}`);
52
+ }
53
+
54
+ /**
55
+ * Detect and display proxy configuration
56
+ * @returns {Object} Proxy configuration details
57
+ */
58
+ function detectProxyConfig() {
59
+ const proxyVars = [
60
+ 'HTTP_PROXY', 'http_proxy',
61
+ 'HTTPS_PROXY', 'https_proxy',
62
+ 'ALL_PROXY', 'all_proxy',
63
+ 'NO_PROXY', 'no_proxy'
64
+ ];
65
+
66
+ const activeProxies = {};
67
+ for (const varName of proxyVars) {
68
+ if (process.env[varName]) {
69
+ activeProxies[varName] = process.env[varName];
70
+ }
71
+ }
72
+
73
+ return activeProxies;
74
+ }
75
+
76
+ /**
77
+ * Test if proxy is reachable
78
+ * @param {string} proxyUrl - Proxy URL to test
79
+ * @returns {boolean} True if proxy is reachable
80
+ */
81
+ function testProxyConnectivity(proxyUrl) {
82
+ try {
83
+ // Try to parse proxy URL
84
+ const url = new URL(proxyUrl);
85
+
86
+ // Use curl to test proxy connectivity (cross-platform)
87
+ const testCmd = isWindows
88
+ ? `curl -s -o NUL -w "%{http_code}" --proxy ${proxyUrl} --max-time 5 https://pypi.org/simple/`
89
+ : `curl -s -o /dev/null -w "%{http_code}" --proxy ${proxyUrl} --max-time 5 https://pypi.org/simple/`;
90
+
91
+ const result = spawnSync(isWindows ? 'cmd' : 'sh',
92
+ isWindows ? ['/c', testCmd] : ['-c', testCmd],
93
+ {
94
+ stdio: 'pipe',
95
+ encoding: 'utf-8',
96
+ timeout: 6000
97
+ }
98
+ );
99
+
100
+ const httpCode = result.stdout?.trim();
101
+ return httpCode === '200' || httpCode === '301' || httpCode === '302';
102
+ } catch (e) {
103
+ return false;
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Test if PyPI is directly accessible (without proxy)
109
+ * @returns {boolean} True if PyPI is accessible
110
+ */
111
+ function testDirectPyPIAccess() {
112
+ try {
113
+ const testCmd = isWindows
114
+ ? 'curl -s -o NUL -w "%{http_code}" --max-time 5 https://pypi.org/simple/'
115
+ : 'curl -s -o /dev/null -w "%{http_code}" --max-time 5 https://pypi.org/simple/';
116
+
117
+ const result = spawnSync(isWindows ? 'cmd' : 'sh',
118
+ isWindows ? ['/c', testCmd] : ['-c', testCmd],
119
+ {
120
+ stdio: 'pipe',
121
+ encoding: 'utf-8',
122
+ timeout: 6000
123
+ }
124
+ );
125
+
126
+ const httpCode = result.stdout?.trim();
127
+ return httpCode === '200' || httpCode === '301' || httpCode === '302';
128
+ } catch (e) {
129
+ return false;
130
+ }
131
+ }
132
+
43
133
  /**
44
134
  * Check for Python 3 installation
45
135
  * @returns {string} Python command name
@@ -157,7 +247,89 @@ function dependenciesInstalled(pipPath) {
157
247
  }
158
248
 
159
249
  /**
160
- * Install Python dependencies
250
+ * Show helpful guidance for proxy-related installation failures
251
+ */
252
+ function showProxyTroubleshooting(activeProxies, canAccessDirectly, proxyWorks) {
253
+ console.error('\n' + '='.repeat(70));
254
+ console.error(colors.bold + colors.yellow + 'INSTALLATION FAILED - NETWORK CONFIGURATION ISSUE' + colors.reset);
255
+ console.error('='.repeat(70));
256
+
257
+ if (Object.keys(activeProxies).length > 0) {
258
+ console.error('\nšŸ“” Active proxy environment variables found:');
259
+ for (const [key, value] of Object.entries(activeProxies)) {
260
+ console.error(` ${colors.cyan}${key}${colors.reset} = ${value}`);
261
+ }
262
+
263
+ if (!proxyWorks && canAccessDirectly) {
264
+ // Proxy is set but doesn't work, and direct access works
265
+ console.error('\n' + colors.red + 'āŒ Proxy is NOT reachable' + colors.reset);
266
+ console.error(colors.green + 'āœ“ Direct internet access IS available' + colors.reset);
267
+ console.error('\n' + colors.yellow + 'āš ļø You\'re on a PUBLIC network but have proxy settings from a corporate/VPN network!' + colors.reset);
268
+ console.error('\nšŸ’” SOLUTION:\n');
269
+ console.error(colors.bold + 'Remove the proxy settings:' + colors.reset);
270
+ console.error(colors.cyan + ' unset HTTP_PROXY HTTPS_PROXY http_proxy https_proxy ALL_PROXY all_proxy' + colors.reset);
271
+ console.error(' Then run the command again.\n');
272
+
273
+ } else if (proxyWorks && !canAccessDirectly) {
274
+ // Proxy works, direct access doesn't
275
+ console.error('\n' + colors.green + 'āœ“ Proxy IS reachable' + colors.reset);
276
+ console.error(colors.red + 'āŒ Direct internet access is NOT available' + colors.reset);
277
+ console.error('\n' + colors.blue + 'You\'re on a CORPORATE network - proxy is required.' + colors.reset);
278
+ console.error('\nšŸ’” SOLUTION:\n');
279
+ console.error('The proxy should work. The error may be due to:');
280
+ console.error('1. SSL certificate issues - contact your IT department');
281
+ console.error('2. Authentication required - check if proxy needs username/password');
282
+ console.error('3. Specific packages blocked - contact your IT department\n');
283
+
284
+ } else if (!proxyWorks && !canAccessDirectly) {
285
+ // Neither works
286
+ console.error('\n' + colors.red + 'āŒ Proxy is NOT reachable' + colors.reset);
287
+ console.error(colors.red + 'āŒ Direct internet access is NOT available' + colors.reset);
288
+ console.error('\nšŸ’” SOLUTIONS:\n');
289
+ console.error('1. Check your internet connection');
290
+ console.error('2. If on corporate network, verify proxy settings with IT');
291
+ console.error('3. Try a different network (mobile hotspot, home WiFi)');
292
+ console.error('4. Check firewall/antivirus settings\n');
293
+
294
+ } else {
295
+ // Both work (unusual case)
296
+ console.error('\n' + colors.green + 'āœ“ Proxy IS reachable' + colors.reset);
297
+ console.error(colors.green + 'āœ“ Direct internet access IS available' + colors.reset);
298
+ console.error('\nThe issue may be:');
299
+ console.error('1. SSL certificate problems');
300
+ console.error('2. Intermittent connectivity');
301
+ console.error('3. Package-specific blocking\n');
302
+ }
303
+
304
+ console.error(colors.bold + 'Additional options:' + colors.reset);
305
+ console.error('• Check system proxy settings:');
306
+ if (!isWindows) {
307
+ console.error(' macOS: System Settings → Network → Advanced → Proxies');
308
+ } else {
309
+ console.error(' Windows: Settings → Network & Internet → Proxy');
310
+ }
311
+ console.error('• Try manual installation (see TROUBLESHOOTING.md)');
312
+
313
+ } else {
314
+ console.error('\nšŸ’” No proxy environment variables detected.\n');
315
+ console.error('POSSIBLE CAUSES:');
316
+ console.error('• Network connectivity issues');
317
+ console.error('• Firewall blocking PyPI access');
318
+ console.error('• DNS resolution problems');
319
+ console.error('• System-level proxy (not in environment variables)\n');
320
+
321
+ console.error('SOLUTIONS TO TRY:');
322
+ console.error('1. Check your internet connection');
323
+ console.error('2. Try: curl https://pypi.org/simple/');
324
+ console.error('3. Check firewall/antivirus settings');
325
+ console.error('4. Check system proxy settings (not environment variables)\n');
326
+ }
327
+
328
+ console.error('='.repeat(70) + '\n');
329
+ }
330
+
331
+ /**
332
+ * Install Python dependencies with smart proxy detection
161
333
  * @param {string} venvPath - Path to virtual environment
162
334
  */
163
335
  function installDependencies(venvPath) {
@@ -171,11 +343,10 @@ function installDependencies(venvPath) {
171
343
  if (fs.existsSync(wheelsPath)) {
172
344
  console.error('Using pre-packaged wheels (no internet required)...');
173
345
 
174
- // Install from local wheels (fast, no network needed)
175
346
  const installReqs = spawnSync(pip, [
176
347
  'install',
177
- '--no-index', // Don't use PyPI
178
- '--find-links', wheelsPath, // Use local wheels
348
+ '--no-index',
349
+ '--find-links', wheelsPath,
179
350
  '-r', requirementsPath
180
351
  ], {
181
352
  cwd: projectRoot,
@@ -186,35 +357,96 @@ function installDependencies(venvPath) {
186
357
  error('Failed to install from wheels');
187
358
  process.exit(1);
188
359
  }
360
+
361
+ log('āœ“ Requirements installed', 'green');
189
362
  } else {
190
- // Fallback to normal install with proxy support
363
+ // Need network - detect proxy configuration intelligently
191
364
  console.error('Downloading from PyPI...');
365
+
366
+ const activeProxies = detectProxyConfig();
367
+ const hasProxyVars = Object.keys(activeProxies).length > 0;
368
+
369
+ let proxyToUse = null;
370
+ let useNoProxy = false;
371
+
372
+ if (hasProxyVars) {
373
+ const proxyUrl = process.env.HTTP_PROXY || process.env.http_proxy ||
374
+ process.env.HTTPS_PROXY || process.env.https_proxy;
375
+
376
+ info('Proxy environment variables detected. Testing connectivity...');
377
+
378
+ // Test proxy connectivity
379
+ const proxyWorks = proxyUrl && proxyUrl.startsWith('http') && testProxyConnectivity(proxyUrl);
380
+ const directWorks = testDirectPyPIAccess();
381
+
382
+ if (proxyWorks && !directWorks) {
383
+ // Corporate network - use proxy
384
+ info('Corporate network detected. Using proxy.');
385
+ proxyToUse = proxyUrl;
386
+ } else if (!proxyWorks && directWorks) {
387
+ // Public network with stale proxy vars - ignore proxy
388
+ warning('Proxy unreachable but direct access available. Ignoring proxy settings.');
389
+ useNoProxy = true;
390
+ } else if (proxyWorks && directWorks) {
391
+ // Both work - prefer direct
392
+ info('Both proxy and direct access available. Using direct connection.');
393
+ useNoProxy = true;
394
+ } else {
395
+ // Neither works - will fail but try direct
396
+ warning('Neither proxy nor direct access working. Attempting direct connection...');
397
+ useNoProxy = true;
398
+ }
399
+ }
400
+
401
+ // Build pip arguments
192
402
  const pipArgs = ['install', '-r', requirementsPath];
193
403
 
194
- const proxyFriendlyArgs = [
404
+ // Trusted hosts for SSL-friendly installation
405
+ const trustedHostArgs = [
195
406
  '--trusted-host', 'pypi.org',
196
407
  '--trusted-host', 'pypi.python.org',
197
408
  '--trusted-host', 'files.pythonhosted.org'
198
409
  ];
410
+ pipArgs.push(...trustedHostArgs);
411
+
412
+ // Add proxy if needed
413
+ if (proxyToUse && !useNoProxy) {
414
+ info(`Using proxy: ${proxyToUse}`);
415
+ pipArgs.push('--proxy', proxyToUse);
416
+ }
199
417
 
200
- const proxy = process.env.HTTP_PROXY || process.env.http_proxy;
201
- if (proxy) {
202
- pipArgs.push('--proxy', proxy);
418
+ // Set up environment (potentially removing proxy vars)
419
+ const pipEnv = { ...process.env };
420
+ if (useNoProxy) {
421
+ // Remove proxy environment variables for this pip call
422
+ delete pipEnv.HTTP_PROXY;
423
+ delete pipEnv.HTTPS_PROXY;
424
+ delete pipEnv.http_proxy;
425
+ delete pipEnv.https_proxy;
426
+ delete pipEnv.ALL_PROXY;
427
+ delete pipEnv.all_proxy;
203
428
  }
204
- pipArgs.push(...proxyFriendlyArgs);
205
429
 
206
430
  const installReqs = spawnSync(pip, pipArgs, {
207
431
  cwd: projectRoot,
208
- stdio: 'inherit'
432
+ stdio: 'inherit',
433
+ env: pipEnv
209
434
  });
210
435
 
211
436
  if (installReqs.status !== 0) {
212
- error('Failed to install dependencies');
437
+ error('Failed to install dependencies from PyPI');
438
+
439
+ // Show intelligent troubleshooting
440
+ const proxyUrl = process.env.HTTP_PROXY || process.env.http_proxy;
441
+ const proxyWorks = proxyUrl ? testProxyConnectivity(proxyUrl) : false;
442
+ const directWorks = testDirectPyPIAccess();
443
+
444
+ showProxyTroubleshooting(activeProxies, directWorks, proxyWorks);
213
445
  process.exit(1);
214
446
  }
215
- }
216
447
 
217
- console.error('āœ“ Requirements installed');
448
+ log('āœ“ Requirements installed', 'green');
449
+ }
218
450
 
219
451
  // Install package itself
220
452
  console.error('Installing jenkins-mcp-server package...');
@@ -230,7 +462,7 @@ function installDependencies(venvPath) {
230
462
  process.exit(1);
231
463
  }
232
464
 
233
- console.error('āœ“ Package installed');
465
+ log('āœ“ Package installed successfully', 'green');
234
466
  }
235
467
 
236
468
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rishibhushan/jenkins-mcp-server",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "AI-enabled Jenkins automation via Model Context Protocol (MCP)",
5
5
  "main": "bin/jenkins-mcp.js",
6
6
  "bin": {