Jenkins MCP Server

Jenkins MCP Server

Enables comprehensive Jenkins automation through MCP interface, allowing users to manage builds, jobs, artifacts, and queues with natural language commands. Supports build triggering, monitoring, artifact retrieval, and system status checks with automatic CSRF protection and authentication.

Category
访问服务器

README

Jenkins MCP Server

A comprehensive Jenkins Model Context Protocol (MCP) server that provides tools for managing Jenkins builds, jobs, artifacts, and queue operations through the MCP interface.

📋 Table of Contents

🚀 Features

  • Build Management: Trigger, stop, schedule, and update Jenkins builds
  • Job Information: Retrieve comprehensive job and build information
  • System Monitoring: Get Jenkins instance status and health information
  • Artifact Management: List and read build artifacts
  • Queue Operations: Manage and monitor build queues
  • CSRF Protection: Automatic handling of Jenkins CSRF tokens
  • Authentication: Support for Jenkins API tokens and basic auth

🏗️ Architecture

The codebase is organized into a modular, scalable structure:

src/
├── index.js                 # Main entry point
├── client/
│   └── jenkins-client.js    # Jenkins HTTP client with auth & CSRF
├── server/
│   └── mcp-server.js        # MCP server implementation
├── tools/
│   ├── index.js             # Tool registry and management
│   ├── build-management.js  # Build-related operations
│   ├── job-info.js          # Job information retrieval
│   ├── system-info.js       # System status and user info
│   ├── artifact-management.js # Artifact operations
│   └── queue-management.js  # Queue operations
├── config/
│   └── index.js             # Configuration management
└── utils/
    └── jenkins.js           # Utility functions

📦 Installation

  1. Clone the repository:

    git clone <repository-url>
    cd jenkins-mcp
    
  2. Install dependencies:

    npm install
    
  3. Configure environment variables (see Configuration)

  4. Start the server:

    npm start
    

    Or for development with auto-restart:

    npm run dev
    

⚙️ Configuration

Configure the server using environment variables:

# Required: Jenkins instance URL
export JENKINS_URL="http://your-jenkins-instance:8080"

# Required: Jenkins username
export JENKINS_USER="your-username"

# Required: Jenkins API token (recommended)
export JENKINS_API_TOKEN="your-api-token"

Getting a Jenkins API Token

  1. Log into your Jenkins instance
  2. Click on your username (top right) → Configure
  3. Under "API Token", click "Add new Token"
  4. Give it a name and click "Generate"
  5. Copy the generated token and use it as JENKINS_API_TOKEN

MCP Client Configuration

This Jenkins MCP Server can be integrated with various MCP clients. Here's how to configure it with popular clients:

🤖 GitHub Copilot (VS Code)

  1. Install the MCP extension in VS Code
  2. Add to your mcp.json:
    {
    	"servers": {
    		"jenkins": {
    			"command": "node",
    			"args": ["path/to/jenkins-mcp/src/index.js"],
    			"env": {
    				"JENKINS_URL": "http://your-jenkins-instance:8080",
    				"JENKINS_USER": "your-username",
    				"JENKINS_API_TOKEN": "your-api-token"
    			}
    		}
    	}
    }
    

🧠 Claude Desktop

  1. Edit Claude's config file (~/.config/claude-desktop/claude_desktop_config.json):
    {
    	"mcpServers": {
    		"jenkins": {
    			"command": "node",
    			"args": ["path/to/jenkins-mcp/src/index.js"],
    			"env": {
    				"JENKINS_URL": "http://your-jenkins-instance:8080",
    				"JENKINS_USER": "your-username",
    				"JENKINS_API_TOKEN": "your-api-token"
    			}
    		}
    	}
    }
    

EliteA MCP Client

  1. Add to EliteA configuration(config.json):
    {
    	"servers": {
    		"jenkins-mcp": {
    			"type": "stdio",
    			"command": "node",
    			"args": ["path/to/jenkins-mcp/src/index.js"],
    			"environment": {
    				"JENKINS_URL": "http://your-jenkins-instance:8080",
    				"JENKINS_USER": "your-username",
    				"JENKINS_API_TOKEN": "your-api-token"
    			}
    		}
    	}
    }
    

Important Notes:

  • Replace path/to/jenkins-mcp/src/index.js with the actual absolute path to your installation
  • Ensure Node.js is in your system PATH
  • The server communicates via stdin/stdout following the MCP protocol
  • All Jenkins tools will be available once configured

🛠️ Available Tools

Build Management

triggerBuild

Trigger a build for a Jenkins job.

  • jobFullName (string, required): Full path of the Jenkins job
  • parameters (object, optional): Build parameters

stopBuild

Stop or kill a running Jenkins build.

  • jobFullName (string, required): Full path of the Jenkins job
  • buildNumber (integer, optional): Build number to stop (defaults to last build)

scheduleBuild

Schedule a Jenkins build to run at a specific time.

  • jobFullName (string, required): Full path of the Jenkins job
  • scheduleTime (string, required): Time to schedule (e.g., '22:15', '10:30 PM')
  • parameters (object, optional): Build parameters

updateBuild

Update build display name and/or description.

  • jobFullName (string, required): Full path of the Jenkins job
  • buildNumber (integer, optional): Build number (defaults to last build)
  • displayName (string, optional): New display name
  • description (string, optional): New description

Job Information

getJob

Get information about a Jenkins job.

  • jobFullName (string, required): Full path of the Jenkins job

getBuild

Get information about a specific build or the last build.

  • jobFullName (string, required): Full path of the Jenkins job
  • buildNumber (integer, optional): Build number (defaults to last build)

getJobs

Get a paginated list of Jenkins jobs.

  • parentFullName (string, optional): Full path of the parent folder
  • skip (integer, optional): Number of items to skip (default: 0)
  • limit (integer, optional): Maximum items to return (default: 10, max: 10)

System Information

whoAmI

Get information about the current authenticated user.

getStatus

Get Jenkins instance status and health information.

Artifact Management

listBuildArtifacts

List all artifacts from a specific build or the last build.

  • jobFullName (string, required): Full path of the Jenkins job
  • buildNumber (integer, optional): Build number (defaults to last build)

readBuildArtifact

Read the content of a specific build artifact.

  • jobFullName (string, required): Full path of the Jenkins job
  • artifactPath (string, required): Relative path to the artifact
  • buildNumber (integer, optional): Build number (defaults to last build)
  • format (string, optional): Format for binary files ('text' or 'base64')

Queue Management

cancelQueuedBuild

Cancel a pending/queued Jenkins build that hasn't started yet.

  • jobFullName (string, required): Full path of the Jenkins job
  • queueId (integer, optional): Specific queue item ID to cancel

getQueueInfo

Get information about queued builds.

  • jobFullName (string, optional): Full path of the Jenkins job (returns all if not provided)

💡 Usage Examples

Triggering a Build

{
	"tool": "triggerBuild",
	"arguments": {
		"jobFullName": "my-project/main-build",
		"parameters": {
			"BRANCH": "main",
			"ENVIRONMENT": "staging"
		}
	}
}

Getting Build Information

{
	"tool": "getBuild",
	"arguments": {
		"jobFullName": "my-project/main-build",
		"buildNumber": 123
	}
}

Reading an Artifact

{
	"tool": "readBuildArtifact",
	"arguments": {
		"jobFullName": "my-project/main-build",
		"artifactPath": "target/test-results.xml",
		"format": "text"
	}
}

Scheduling a Build

{
	"tool": "scheduleBuild",
	"arguments": {
		"jobFullName": "my-project/nightly-build",
		"scheduleTime": "22:30",
		"parameters": {
			"FULL_TEST": "true"
		}
	}
}

🔧 Development

Adding New Tools

  1. Create the tool function in the appropriate file under src/tools/
  2. Add the tool definition to src/tools/index.js in the toolRegistry
  3. Update the README with the new tool documentation

Example tool structure:

export async function myNewTool(client, param1, param2) {
	try {
		// Tool implementation
		const result = await client.get("/some/endpoint");
		return {
			success: true,
			data: result.data,
		};
	} catch (error) {
		return formatError(error, "my operation");
	}
}

Project Structure Explained

  • src/client/: HTTP client for Jenkins API communication
  • src/server/: MCP server implementation and request handling
  • src/tools/: Individual tool implementations organized by functionality
  • src/config/: Configuration management and environment variables
  • src/utils/: Shared utility functions

Code Style

  • Use ES6+ features and async/await
  • Follow consistent error handling patterns
  • Include JSDoc comments for functions
  • Use descriptive variable and function names
  • Maintain modular structure for scalability

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


🆘 Troubleshooting

Common Issues

Authentication Errors

  • Ensure JENKINS_API_TOKEN is correctly set
  • Verify the token has appropriate permissions
  • Check if the Jenkins user has access to the jobs

CSRF Token Issues

  • The server automatically handles CSRF tokens
  • Ensure Jenkins CSRF protection is enabled
  • For older Jenkins versions, you may need to disable CSRF protection

Connection Issues

  • Verify JENKINS_URL is accessible
  • Check firewall settings
  • Ensure Jenkins is running and responding

Tool Execution Errors

  • Check job names and paths are correct
  • Verify build numbers exist
  • Ensure proper permissions for the requested operations

For more specific issues, enable debug logging by setting:

export DEBUG=jenkins-mcp:*

Made with ❤️ by Utkarsh Mishra

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选