使用说明
MCP詹金斯
模型上下文协议(MCP)是一个开源实现,它将Jenkins与遵循Anthropic MCP规范的AI语言模型连接起来。该项目实现了与Jenkins工具的安全、上下文AI交互,同时维护了数据隐私和安全。
GitHub存储库: https://github.com/huixin2022/jenkins-mcp
光标演示
安装指南
安装
选择以下安装方法之一:
# Using uv (recommended)
pip install uv
uvx mcp-jenkins
# Using pip
pip install mcp-jenkins
Docker安装
从GitHub容器注册表中提取最新图像:
docker pull ghcr.io/huixin2022/jenkins-mcp:latest
配置和使用
光标
- 打开光标设置
- 导航到MCP
- 点击+添加新的全局MCP服务器
这将使用您的mcp服务器配置创建或编辑~/.cursor/mcp.json文件。
{
"mcpServers": {
"mcp-jenkins": {
"command": "uvx",
"args": [
"mcp-jenkins",
"--jenkins-url=xxx",
"--jenkins-username=xxx",
"--jenkins-password=xxx"
]
}
}
}
注意:您也可以将Jenkins令牌设置为密码!
VSCode副驾驶聊天
- 创建
.vscode文件夹与mcp.json工作区中的文件,用于本地设置或编辑settings.json槽设置男人。 - 插入以下配置:
选项1:使用HTTP标头(推荐)
通过mcp.json配置中的HTTP标头直接传递Jenkins凭据。此方法利用FastMCP的ASGI中间件从HTTP请求标头中安全地提取凭据。
- SSE模式
{
"servers": {
"jenkins": {
"url": "http://localhost:3000/sse",
"type": "sse",
"headers": {
"x-jenkins-url": "https://your-jenkins-server.com",
"x-jenkins-username": "your-username",
"x-jenkins-password": "your-api-token"
}
}
}
}
- 流式Http模式(推荐)
{
"servers": {
"mcp-jenkins": {
"autoApprove": [],
"disabled": false,
"timeout": 60,
"type": "streamableHttp",
"url": "http://localhost:3000/mcp",
"headers": {
"x-jenkins-url": "https://your-jenkins-server.com",
"x-jenkins-username": "your-username",
"x-jenkins-password": "your-api-token"
}
}
}
}
然后在没有凭据的情况下启动MCP服务器(它们将自动从标头中提取):
# For SSE transport
uvx mcp-jenkins --transport sse --port 3000
# For streamable-http transport
uvx mcp-jenkins --transport streamable-http --port 3000
选项2:使用CLI参数(传统方法)
启动服务器时传递凭据:
- SSE模式
{
"servers": {
"jenkins": {
"url": "http://localhost:9887/sse",
"type": "sse"
}
}
}
- 流式Http模式
{
"servers": {
"mcp-jenkins": {
"autoApprove": [],
"disabled": false,
"timeout": 60,
"type": "streamableHttp",
"url": "http://localhost:9887/mcp"
}
}
}
启动服务器(将从环境变量中读取凭据):
uvx mcp-jenkins --transport sse --port 3000
# or
uvx mcp-jenkins --transport streamable-http --port 3000
选项3:使用CLI参数(设置环境变量)
将凭据作为命令行参数传递。这些将被设置为服务器进程的环境变量:
uvx mcp-jenkins \
--jenkins-url https://your-jenkins-server.com \
--jenkins-username your_username \
--jenkins-password your_password_or_token \
--transport sse --port 9887
行参数
# Stdio Mode
uvx mcp-jenkins --jenkins-url xxx --jenkins-username xxx --jenkins-password xxx --read-only
# SSE Mode
uvx mcp-jenkins --jenkins-url xxx --jenkins-username xxx --jenkins-password xxx --transport sse --port 9887
# Streamable-Http Mode
uvx mcp-jenkins --jenkins-url xxx --jenkins-username xxx --jenkins-password xxx --transport streamable-http --port 9887
自动生成
Install and exec
安装autogen:
pip install "autogen-ext[azure,ollama,openai,mcp]" autogen-chat
运行python脚本:
import asyncio
from autogen_ext.tools.mcp import StdioMcpToolAdapter, StdioServerParams
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.ui import Console
from autogen_core import CancellationToken
async def main() -> None:
# Create server params for the remote MCP service
server_params = StdioServerParams(
command='uvx',
args=[
'mcp-jenkins',
'--jenkins-username',
'xxx',
'--jenkins-password',
'xxx',
'--jenkins-url',
'xxx'
],
)
# Get the translation tool from the server
adapter = await StdioMcpToolAdapter.from_server_params(server_params, 'get_all_jobs')
# Create an agent that can use the translation tool
agent = AssistantAgent(
name='jenkins_assistant',
model_client=[Replace_with_your_model_client],
tools=[adapter],
)
# Let the agent translate some text
await Console(
agent.run_stream(task='Get all jobs', cancellation_token=CancellationToken())
)
if __name__ == "__main__":
asyncio.run(main())
可用工具
| 工具 | 说明 |
|---|---|
| get_all_jobs | 获取所有作业 |
| get_job_config | 获取作业配置 |
| search_jobs | 按特定字段搜索作业 |
| get_runing_builds | 获取正在运行的构建 |
| stop_build | 停止运行构建 |
| get_build_info | 获取构建信息 |
| get_build_sourcecode | 获取Jenkins中特定构建的管道源代码 |
| get_job_info | 获取工作信息 |
| build_job | 使用参数构建作业 |
| get_build_logs | 获取构建日志 |
| get_test_results | 获取特定版本的测试结果 |
| get_all_nodes | 获取节点 |
| get_node_config | 获取节点的配置 |
| get_all_queue_items | 获取所有队列项 |
| get_queue_item | 获取队列项目信息 |
| cancel_queue_item | 取消队列项目 |
| get_multibranch_jobs | 从Jenkins获取所有多分支管道作业,可选择按模式过滤 |
| get_multibranch_branches | 获取特定多分支管道作业的所有分支 |
| scan_multibranch_pipeline | 触发对多分支管道的扫描以发现新分支 |
开发与调试
# Using MCP Inspector
# For installed package
npx @modelcontextprotocol/inspector uvx mcp-jenkins --jenkins-url xxx --jenkins-username xxx --jenkins-password xxx
# For local development version
npx @modelcontextprotocol/inspector uv --directory /path/to/your/mcp-jenkins run mcp-jenkins --jenkins-url xxx --jenkins-username xxx --jenkins-password xxx
预提交挂钩
# Install Dependency
uv sync --all-extras --dev
pre-commit install
# Manually execute
pre-commit run --all-files
UT
# Install Dependency
uv sync --all-extras --dev
# Execute UT
uv run pytest --cov=mcp_jenkins
许可证
麻省理工学院授权-见 许可证 文件。这不是Jenkins的官方产品。
