@rishibhushan/jenkins-mcp-server 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,575 @@
1
+ # 🧠 Jenkins MCP Server
2
+
3
+ **Jenkins MCP Server** is an AI-enabled Model Context Protocol (MCP) server that exposes Jenkins automation through natural-language commands.
4
+
5
+ Designed to work seamlessly with automation clients such as:
6
+ - πŸ–₯️ **VS Code MCP** - Direct integration with Claude in VS Code
7
+ - πŸ”Œ **Any MCP-compatible client** - Universal compatibility
8
+
9
+ ## ✨ About codebase
10
+
11
+ - βœ… **Codebase** - cleaner, more maintainable
12
+ - βœ… **Error messages** - Know exactly what's wrong and how to fix it
13
+ - βœ… **Flexible configuration** - Multiple ways to configure (VS Code, .env, environment)
14
+ - βœ… **Cross-platform** - Seamless support for Windows, macOS, and Linux
15
+ - βœ… **Logging** - Professional logging with `--verbose` flag
16
+ - βœ… **Dependency management** - Automatic detection and installation
17
+
18
+ ---
19
+
20
+ ## πŸ“¦ Features
21
+
22
+ This project includes:
23
+ - 🐍 Python backend powered by `python-jenkins`
24
+ - πŸ“¦ Node.js `npx` wrapper for zero-install execution
25
+ - πŸ”„ Automatic virtual environment creation + dependency installation
26
+ - 🌐 Corporate proxy/certificate auto-detection support
27
+ - πŸͺŸ Windows, macOS, and Linux support
28
+ - πŸ› οΈ **20 Jenkins management tools**
29
+
30
+ ### 🧩 Build Operations
31
+ | Tool Name | Description | Required Fields | Optional Fields |
32
+ |---|---|---|---|
33
+ | `trigger-build` | Trigger a Jenkins job build with optional parameters | `job_name` | `parameters` |
34
+ | `stop-build` | Stop a running Jenkins build | `job_name`, `build_number` | *(none)* |
35
+
36
+ ### πŸ“Š Job Information
37
+ | Tool Name | Description | Required Fields | Optional Fields |
38
+ |---|---|---|---|
39
+ | `list-jobs` | List all Jenkins jobs with optional filtering | *(none)* | `filter` |
40
+ | `get-job-details` | Get detailed information about a Jenkins job | `job_name` | *(none)* |
41
+
42
+ ### πŸ› οΈ Build Information
43
+ | Tool Name | Description | Required Fields | Optional Fields |
44
+ |---|---|---|---|
45
+ | `get-build-info` | Get information about a specific build | `job_name`, `build_number` | *(none)* |
46
+ | `get-build-console` | Get console output from a build | `job_name`, `build_number` | *(none)* |
47
+ | `get-last-build-number` | Get the last build number for a job | `job_name` | *(none)* |
48
+ | `get-last-build-timestamp` | Get the timestamp of the last build | `job_name` | *(none)* |
49
+
50
+ ### 🧩 Job Management
51
+ | Tool Name | Description | Required Fields | Optional Fields |
52
+ |---|---|---|---|
53
+ | `create-job` | Create a new Jenkins job with XML configuration | `job_name`, `config_xml` | *(none)* |
54
+ | `create-job-from-copy` | Create a new job by copying an existing one | `new_job_name`, `source_job_name` | *(none)* |
55
+ | `create-job-from-data` | Create a job from structured data (auto-generated XML) | `job_name`, `config_data` | `root_tag` |
56
+ | `delete-job` | Delete an existing job | `job_name` | *(none)* |
57
+ | `enable-job` | Enable a disabled Jenkins job | `job_name` | *(none)* |
58
+ | `disable-job` | Disable a Jenkins job | `job_name` | *(none)* |
59
+ | `rename-job` | Rename an existing Jenkins job | `job_name`, `new_name` | *(none)* |
60
+
61
+ ### βš™οΈ Job Configuration
62
+ | Tool Name | Description | Required Fields | Optional Fields |
63
+ |---|---|---|---|
64
+ | `get-job-config` | Fetch job XML configuration | `job_name` | *(none)* |
65
+ | `update-job-config` | Update job XML configuration | `job_name`, `config_xml` | *(none)* |
66
+
67
+ ### πŸ–₯️ System Information
68
+ | Tool Name | Description | Required Fields | Optional Fields |
69
+ |---|---|---|---|
70
+ | `get-queue-info` | Get Jenkins build queue info | *(none)* | *(none)* |
71
+ | `list-nodes` | List all Jenkins nodes | *(none)* | *(none)* |
72
+ | `get-node-info` | Get information about a Jenkins node | `node_name` | *(none)* |
73
+
74
+ ---
75
+
76
+ ## πŸš€ Quick Start
77
+
78
+ ### Prerequisites
79
+
80
+ **Node.js** (v14 or higher) is required for the npx wrapper.
81
+
82
+ <details>
83
+ <summary><b>Windows Installation</b></summary>
84
+
85
+ ```powershell
86
+ # Using winget (recommended)
87
+ winget install OpenJS.NodeJS.LTS
88
+
89
+ # Verify installation
90
+ node -v
91
+ npm -v
92
+ ```
93
+
94
+ Or download manually from https://nodejs.org/
95
+ </details>
96
+
97
+ <details>
98
+ <summary><b>macOS Installation</b></summary>
99
+
100
+ ```bash
101
+ # Install nvm (Node Version Manager)
102
+ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
103
+
104
+ # Reload shell
105
+ source ~/.nvm/nvm.sh
106
+
107
+ # Install Node LTS
108
+ nvm install --lts
109
+ nvm use --lts
110
+
111
+ # Verify installation
112
+ node -v
113
+ npm -v
114
+ ```
115
+ </details>
116
+
117
+ <details>
118
+ <summary><b>Linux Installation</b></summary>
119
+
120
+ ```bash
121
+ # Ubuntu/Debian
122
+ curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
123
+ sudo apt-get install -y nodejs
124
+
125
+ # Fedora/RHEL
126
+ curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
127
+ sudo dnf install -y nodejs
128
+
129
+ # Verify installation
130
+ node -v
131
+ npm -v
132
+ ```
133
+ </details>
134
+
135
+ ---
136
+
137
+ ## βš™οΈ Configuration
138
+
139
+ Jenkins MCP Server supports multiple configuration methods. Choose the one that works best for you:
140
+
141
+ ### Option 1: VS Code Settings (Recommended)
142
+
143
+ Add to your VS Code `settings.json`:
144
+
145
+ ```json
146
+ {
147
+ "jenkins-mcp-server": {
148
+ "jenkins": {
149
+ "url": "http://jenkins.example.com:8080",
150
+ "username": "your-username",
151
+ "token": "your-api-token"
152
+ }
153
+ }
154
+ }
155
+ ```
156
+
157
+ **Where to find settings.json:**
158
+ - **Windows**: `%APPDATA%\Code\User\settings.json`
159
+ - **macOS**: `~/Library/Application Support/Code/User/settings.json`
160
+ - **Linux**: `~/.config/Code/User/settings.json`
161
+
162
+ ### Option 2: Environment File (.env)
163
+
164
+ Rename `.env.template` to `.env`
165
+ ```bash
166
+ cp .env.template .env
167
+ ```
168
+
169
+ In the `.env` file in your project directory:
170
+
171
+ ```bash
172
+ JENKINS_URL=http://jenkins.example.com:8080
173
+ JENKINS_USERNAME=your-username
174
+ JENKINS_TOKEN=your-api-token
175
+ ```
176
+
177
+ **Note**: Use API token instead of password for better security.
178
+
179
+ ### Option 3: Environment Variables
180
+
181
+ ```bash
182
+ # Linux/macOS
183
+ export JENKINS_URL=http://jenkins.example.com:8080
184
+ export JENKINS_USERNAME=your-username
185
+ export JENKINS_TOKEN=your-api-token
186
+
187
+ # Windows (PowerShell)
188
+ $env:JENKINS_URL="http://jenkins.example.com:8080"
189
+ $env:JENKINS_USERNAME="your-username"
190
+ $env:JENKINS_TOKEN="your-api-token"
191
+ ```
192
+
193
+ ### Configuration Priority
194
+
195
+ Settings are loaded in this order (later overrides earlier):
196
+ 1. Default `.env` file
197
+ 2. Environment variables
198
+ 3. Custom `.env` file (via `--env-file`)
199
+ 4. VS Code settings
200
+ 5. Direct parameters
201
+
202
+ ### Getting Your Jenkins API Token
203
+
204
+ 1. Log into Jenkins
205
+ 2. Click your name (top right) β†’ **Configure**
206
+ 3. Scroll to **API Token** section
207
+ 4. Click **Add new Token**
208
+ 5. Give it a name and click **Generate**
209
+ 6. Copy the token (⚠️ it won't be shown again!)
210
+
211
+ ---
212
+
213
+ ## 🎯 Running the Server
214
+
215
+ ### Method 1: Using npx (Recommended - Zero Setup)
216
+
217
+ **With VS Code settings:**
218
+ ```bash
219
+ npx github:rishibhushan/jenkins_mcp_server
220
+ ```
221
+
222
+ **With custom .env file:**
223
+ ```bash
224
+ npx github:rishibhushan/jenkins_mcp_server --env-file /path/to/.env
225
+ ```
226
+
227
+ **With verbose logging:**
228
+ ```bash
229
+ npx github:rishibhushan/jenkins_mcp_server --verbose
230
+ ```
231
+
232
+ **Skip VS Code settings:**
233
+ ```bash
234
+ npx github:rishibhushan/jenkins_mcp_server --no-vscode
235
+ ```
236
+
237
+ This automatically:
238
+ - βœ… Detects Python 3 installation
239
+ - βœ… Creates isolated virtual environment (`.venv`)
240
+ - βœ… Installs all dependencies
241
+ - βœ… Starts the MCP server
242
+
243
+ ### Method 2: Direct Python Execution
244
+
245
+ ```bash
246
+ # Create virtual environment
247
+ python3 -m venv .venv
248
+
249
+ # Activate virtual environment
250
+ # Linux/macOS:
251
+ source .venv/bin/activate
252
+ # Windows:
253
+ .venv\Scripts\activate
254
+
255
+ # Install dependencies
256
+ pip install -r requirements.txt
257
+
258
+ # Run the server
259
+ python -m jenkins_mcp_server --env-file /path/to/.env
260
+ ```
261
+
262
+ ### Command-Line Options
263
+
264
+ ```
265
+ jenkins-mcp-server [options]
266
+
267
+ Options:
268
+ --env-file PATH Path to custom .env file
269
+ --verbose, -v Enable verbose/debug logging
270
+ --no-vscode Skip loading VS Code settings
271
+ --version Show version information
272
+ --help, -h Show help message
273
+ ```
274
+
275
+ ---
276
+
277
+ ## πŸ”Œ Integration Examples
278
+
279
+ ### VS Code MCP Client
280
+
281
+ Add to your VS Code `mcp.json`:
282
+
283
+ ```json
284
+ {
285
+ "servers": {
286
+ "jenkins": {
287
+ "type": "stdio",
288
+ "command": "npx",
289
+ "args": [
290
+ "github:rishibhushan/jenkins_mcp_server"
291
+ ]
292
+ }
293
+ }
294
+ }
295
+ ```
296
+
297
+ Or `setting.json` with `.env` file and proxy settings:
298
+ ```json
299
+ {
300
+ "mcp": {
301
+ "servers": {
302
+ "jenkins": {
303
+ "type": "stdio",
304
+ "command": "npx",
305
+ "args": [
306
+ "github:rishibhushan/jenkins_mcp_server",
307
+ "--verbose",
308
+ "--env-file",
309
+ "/path/to/.env"
310
+ ],
311
+ "env": {
312
+ "HTTP_PROXY": "http://proxy.example.com:8080",
313
+ "HTTPS_PROXY": "http://proxy.example.com:8080",
314
+ "NO_PROXY": "localhost,127.0.0.1,.example.com"
315
+ }
316
+ }
317
+ }
318
+ }
319
+ }
320
+ ```
321
+
322
+ ### Claude Desktop
323
+
324
+ Add to `claude_desktop_config.json`:
325
+
326
+ ```json
327
+ {
328
+ "mcpServers": {
329
+ "jenkins": {
330
+ "command": "npx",
331
+ "args": [
332
+ "github:rishibhushan/jenkins_mcp_server",
333
+ "--env-file",
334
+ "/path/to/.env"
335
+ ]
336
+ }
337
+ }
338
+ }
339
+ ```
340
+
341
+ **Where to find claude_desktop_config.json:**
342
+ - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
343
+ - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
344
+ - **Linux**: `~/.config/Claude/claude_desktop_config.json`
345
+
346
+ ---
347
+
348
+ ## πŸ’‘ Usage Examples
349
+
350
+ ### Natural Language Commands
351
+
352
+ Once configured, you can use natural language with your MCP client:
353
+
354
+ ```
355
+ "List all Jenkins jobs"
356
+ "List jobs with 'backend' in the name" - # Filter jobs containing "backend"
357
+ "Show me all production jobs" - # Filter jobs containing "prod"
358
+ "Show me the last build of my-project"
359
+ "Trigger a build for deploy-prod with parameter env=production"
360
+ "What's in the build queue?"
361
+ "Show me the console output of build #42 for backend-service"
362
+ "Create a new job called test-job by copying prod-job"
363
+ "Disable the old-job"
364
+ ```
365
+
366
+ ### Programmatic Usage (Python)
367
+
368
+ ```python
369
+ from config import get_settings
370
+ from jenkins_client import get_jenkins_client
371
+
372
+ # Load settings
373
+ settings = get_settings()
374
+
375
+ # Create client
376
+ client = get_jenkins_client(settings)
377
+
378
+ # List jobs
379
+ all_jobs = client.get_jobs()
380
+ for job in all_jobs:
381
+ print(f"Job: {job['name']} - Status: {job['color']}")
382
+
383
+ # Filter in Python
384
+ backend_jobs = [job for job in all_jobs if 'backend' in job['name'].lower()]
385
+
386
+ # Trigger a build
387
+ result = client.build_job(
388
+ "my-job",
389
+ parameters={"BRANCH": "main", "ENV": "staging"}
390
+ )
391
+ print(f"Build queued: {result['queue_id']}")
392
+ print(f"Build number: {result['build_number']}")
393
+
394
+ # Get console output
395
+ if result['build_number']:
396
+ output = client.get_build_console_output(
397
+ "my-job",
398
+ result['build_number']
399
+ )
400
+ print(output)
401
+ ```
402
+
403
+ ---
404
+
405
+ ## πŸ”§ Troubleshooting
406
+
407
+ ### Python Not Found
408
+ ```
409
+ Error: Python 3 is required but not found.
410
+ ```
411
+ **Solution**: Install Python 3.8+ from https://www.python.org/downloads/
412
+
413
+ ### Configuration Issues
414
+ ```
415
+ ERROR: Jenkins configuration is incomplete!
416
+ ```
417
+ **Solution**: Verify you have set `JENKINS_URL`, `JENKINS_USERNAME`, and `JENKINS_TOKEN`
418
+
419
+ Check your configuration:
420
+ ```bash
421
+ # View .env file
422
+ cat .env
423
+
424
+ # Check environment variables
425
+ env | grep JENKINS
426
+
427
+ # Check VS Code settings
428
+ cat ~/.config/Code/User/settings.json | grep jenkins
429
+ ```
430
+
431
+ ### Connection Failed
432
+ ```
433
+ Failed to connect to Jenkins at http://localhost:8080
434
+ ```
435
+ **Solution**:
436
+ 1. Verify Jenkins is running: `curl http://localhost:8080/api/json`
437
+ 2. Check firewall settings
438
+ 3. Verify URL is correct (include port if needed)
439
+ 4. Test authentication credentials
440
+
441
+ ### Dependency Installation Failed
442
+ ```
443
+ Failed to install dependencies
444
+ ```
445
+ **Solution**:
446
+ 1. Check internet connection
447
+ 2. If behind a proxy, set `HTTP_PROXY` and `HTTPS_PROXY` environment variables
448
+ 3. Try manual installation: `.venv/bin/pip install -r requirements.txt`
449
+
450
+ ### Enable Debug Logging
451
+
452
+ Run with verbose flag to see detailed logs:
453
+ ```bash
454
+ jenkins-mcp-server --verbose
455
+ ```
456
+
457
+ ---
458
+
459
+ ## πŸ§ͺ Development & Testing
460
+
461
+ ### Run Tests
462
+ ```bash
463
+ # Install test dependencies
464
+ pip install pytest pytest-asyncio
465
+
466
+ # Run tests
467
+ pytest tests/ -v
468
+ ```
469
+
470
+ ### Build Package
471
+ ```bash
472
+ # Install build tools
473
+ pip install build
474
+
475
+ # Build distribution
476
+ python -m build
477
+
478
+ # This creates:
479
+ # - dist/jenkins_mcp_server-1.0.0.tar.gz
480
+ # - dist/jenkins_mcp_server-1.0.0-py3-none-any.whl
481
+ ```
482
+
483
+ ### Local Development
484
+ ```bash
485
+ # Clone repository
486
+ git clone https://github.com/rishibhushan/jenkins_mcp_server.git
487
+ cd jenkins_mcp_server
488
+
489
+ # Install in editable mode
490
+ pip install -e .
491
+
492
+ # Make changes, then test
493
+ jenkins-mcp-server --verbose
494
+ ```
495
+
496
+ ---
497
+
498
+ ## πŸ“š Project Structure
499
+
500
+ ```
501
+ jenkins_mcp_server/
502
+ β”œβ”€β”€ bin/
503
+ β”‚ └── jenkins-mcp.js # Node.js wrapper script
504
+ β”œβ”€β”€ src/
505
+ β”‚ └── jenkins_mcp_server/
506
+ β”‚ β”œβ”€β”€ __init__.py # Package initialization & main()
507
+ β”‚ β”œβ”€β”€ __main__.py # Entry point for python -m
508
+ β”‚ β”œβ”€β”€ config.py # Configuration management
509
+ β”‚ β”œβ”€β”€ jenkins_client.py # Jenkins API client
510
+ β”‚ └── server.py # MCP server implementation
511
+ β”œβ”€β”€ tests/ # Test suite
512
+ β”œβ”€β”€ requirements.txt # Python dependencies
513
+ β”œβ”€β”€ package.json # Node.js configuration
514
+ └── README.md # This file
515
+ ```
516
+
517
+ ---
518
+
519
+ ## πŸ”’ Security Best Practices
520
+
521
+ 1. **Never commit `.env` files** - Add to `.gitignore`
522
+ 2. **Use API tokens**, not passwords - More secure and revocable
523
+ 3. **Rotate tokens regularly** - Generate new tokens periodically
524
+ 4. **Use environment-specific configs** - Separate dev/staging/prod credentials
525
+ 5. **Review permissions** - Only grant necessary Jenkins permissions
526
+ 6. **Keep dependencies updated** - Run `pip install --upgrade -r requirements.txt`
527
+
528
+ ---
529
+
530
+ ## 🀝 Contributing
531
+
532
+ Contributions are welcome! Please feel free to submit a Pull Request.
533
+
534
+ 1. Fork the repository
535
+ 2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
536
+ 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
537
+ 4. Push to the branch (`git push origin feature/AmazingFeature`)
538
+ 5. Open a Pull Request
539
+
540
+ ---
541
+
542
+ ## πŸ“ License
543
+
544
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
545
+
546
+ ---
547
+
548
+ ## πŸ™ Acknowledgments
549
+
550
+ - Built on the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/)
551
+ - Powered by [python-jenkins](https://python-jenkins.readthedocs.io/)
552
+ - Inspired by the need for AI-powered DevOps automation
553
+
554
+ ---
555
+
556
+ ## πŸ“ž Support
557
+
558
+ - **Issues**: https://github.com/rishibhushan/jenkins_mcp_server/issues
559
+ - **Discussions**: https://github.com/rishibhushan/jenkins_mcp_server/discussions
560
+
561
+ ---
562
+
563
+ ## πŸ—ΊοΈ Roadmap
564
+
565
+ - [ ] Add pipeline support
566
+ - [ ] Multi-Jenkins instance management
567
+ - [ ] Build artifact management
568
+ - [ ] Advanced filtering and search
569
+ - [ ] Real-time build monitoring
570
+ - [ ] Webhook integration
571
+ - [ ] Docker container support
572
+
573
+ ---
574
+
575
+ **Made with ❀️ by [Rishi Bhushan](https://github.com/rishibhushan)**