Jenkins MCP服务器企业版
Jenkins MCP服务器,用于多实例路由、构建诊断和可选的向量搜索。
Jenkins的模型上下文协议(MCP)服务器,提供构建管理、日志检查、故障诊断和多实例配置。此存储库中维护的安装路径是源代码安装和Docker/Compose。
它做什么
- 触发器同步或异步构建
- 在触发或检查工作之前找到工作
- 检查作业定义和来源位置
- 检索日志并运行目标日志搜索工具
- 发现下游和子构建层次结构
- 检查最近的版本或特定版本的窗口
- 使用可配置的建议诊断构建失败
- 根据以下内容将每个工具调用路由到正确的Jenkins实例
jenkins_url - 暴露
semantic_search仅当启用矢量搜索时 - 暴露
apply_job_edit仅当启用服务器端作业编辑时
快速开始
先决条件
- Python 3.10+
- Jenkins API访问
- Jenkins用户名和API令牌
- 如果你想部署容器,可以使用Docker和Docker Compose
- Qdrant如果你愿意
semantic_search
从源代码安装
git clone https://github.com/Jordan-Jarvis/jenkins-mcp-enterprise
cd jenkins-mcp-enterprise
python3 -m pip install -e .了解两个配置层
服务器使用两个配置层:
- 主服务器配置:
config/mcp-config.yml - 诊断配置:从以下位置之一加载:
- --diagnostic-config /path/to/file.yml - JENKINS_MCP_DIAGNOSTIC_CONFIG=/path/to/file.yml - config/diagnostic-parameters.yml - 捆绑默认值 jenkins_mcp_enterprise/diagnostic_config/diagnostic-parameters.yml
您始终需要主服务器配置。如果你想覆盖捆绑的诊断默认值,你只需要一个项目本地诊断配置文件。
创建主服务器配置
mkdir -p config
cp config/mcp-config.example.yml config/mcp-config.yml编辑 config/mcp-config.yml 使用您的Jenkins URL和凭据。
如果你想为非SCM支持的作业设置可选的Jenkins管理的作业编辑工作流,还可以设置:
settings:
enable_job_editing: true
job_edit_workspace_dir: "/tmp/mcp-jenkins/job-definitions"可选项目本地诊断覆盖
仅当您想调整时才创建此项 diagnose_build_failure:
cat > config/diagnostic-parameters.yml << 'ENDDIAG'
semantic_search:
min_diagnostic_score: 0.65
max_total_highlights: 4
recommendations:
max_recommendations: 5
ENDDIAG如果要进行语义搜索,请启动本地向量堆栈并设置 disable_vector_search: false 和 vector.host: "http://localhost:6333":
./scripts/start_dev_environment.shDocker和Compose
cp config/mcp-config.example.yml config/mcp-config.yml
./start-jenkins_mcp_enterprise.sh看 用于容器部署流程。
启动服务器
jenkins_mcp_enterprise --config config/mcp-config.yml连接到克劳德桌面
添加 ~/.claude_desktop_config.json:
{
"mcpServers": {
"jenkins": {
"command": "jenkins_mcp_enterprise",
"args": ["--config", "config/mcp-config.yml"]
}
}
}使用说明
- 当工具或提示依赖于以下内容时,传递完整的Jenkins构建URL
jenkins_url. - 在多Jenkins设置中,每个工具调用从以下位置解析一个已配置的实例
jenkins_url服务器不会在一次调用中遍历所有配置的Jenkins实例。 semantic_search仅在启用矢量搜索时可用。apply_job_edit仅在以下情况下可用settings.enable_job_editing: true.get_job_definition返回SCM支持的管道的SCM位置详细信息。对于内联管道,它会暂存一个本地Groovy文件进行补丁/编辑/上传。对于其他Jenkins管理的作业,它分阶段config.xml.diagnose_build_failure始终使用诊断配置层。如果不提供项目本地覆盖,则使用捆绑的默认值。- Docker镜像包括
ripgrep,所以ripgrep_search和navigate_log在容器部署中工作。
常见使用模式
Analyze this failed build: https://jenkins.company.com/job/api-service/456/
Find the root cause in this nested pipeline: https://jenkins.company.com/job/monorepo/job/main/789/
Show me the test failure section from this build: https://jenkins.company.com/job/tests/321/
Find similar authentication failures in recent builds可用工具
| 工具 | 目的 |
|---|---|
trigger_build | 启动构建并等待完成 |
trigger_build_async | 排队生成而不等待完成 |
trigger_build_with_subs | 触发构建并跟踪下游/子构建执行 |
get_jenkins_job_parameters | 在触发构建之前检查作业参数 |
find_jobs | 在一个已解析的Jenkins实例上按名称、路径或URL搜索作业 |
list_job_builds | 列出作业的最新版本,或围绕目标版本号的小窗口 |
get_build_info | 获取特定版本的元数据或 lastBuild |
get_job_definition | 检查作业是SCM支持的、内联的、多分支的还是XML支持的 |
ripgrep_search | 使用正则表达式和上下文窗口搜索日志 |
filter_errors_grep | 使用常见的面向错误的模式过滤日志 |
navigate_log | 跳转到日志中的部分或事件 |
get_log_context | 获取目标日志范围或块 |
diagnose_build_failure | 使用日志、层次结构数据和配置的建议进行人工智能辅助故障诊断 |
semantic_search | 启用向量搜索时,跨日志块进行向量支持的相似性搜索 |
apply_job_edit | 启用作业编辑后,将本地编辑的暂存作业定义上传回Jenkins |
配置文档
发展
# Start local supporting services when vector search is enabled
./scripts/start_dev_environment.sh
# Run tests
python3 -m pytest tests/ -v
# Format code
python3 -m black .许可证
GPL v3
