netlinq-jenkins-mcp
netlinq-jenkins-mcp
一个小型 Python 服务,用于封装您的私有 Jenkins 控制器,让团队能够通过自然语言触发 NetLinQ EMS Release pipeline 和 Patch Single Repository Pipeline 作业。一套代码库,两种运行模式:
MCP 服务器 (stdio) - 插入笔记本电脑上的 Cursor,然后询问: “build 7.0 release package” 或 “rebuild blinq-ems-charts at tag 7.0.3”。
FastAPI Web 应用 + 聊天 UI - 在内部服务器上使用一条命令
docker compose up,整个团队通过浏览器登录并使用相同的工具。
托管说明:GitHub 托管的运行器无法访问私有 Jenkins。 代码 位于私有 GitHub 仓库中;运行时 运行在任何具有通往 Jenkins 网络路径的地方(带有 VPN 的同事笔记本电脑,或内部 Linux 虚拟机)。
目录
架构
flowchart LR
subgraph github [Private GitHub Repo]
repo[netlinq-jenkins-mcp]
end
subgraph local [Local laptop - DevOps user]
cursor[Cursor IDE]
mcp["FastMCP stdio server<br/>mcp_server.py"]
cursor -->|stdio| mcp
end
subgraph shared [Internal VM - team]
web["FastAPI web app<br/>web.py + Vite UI"]
chat["Chat UI - browser"]
chat -->|HTTPS basic auth| web
end
subgraph core [Shared Python core]
tools["tools.py<br/>5 tool functions"]
llm["llm.py<br/>LiteLLM router"]
jc["jenkins_client.py<br/>httpx + crumb"]
end
repo -.git clone.-> local
repo -.git clone.-> shared
mcp --> tools
web --> llm
web --> tools
llm -->|"tool calls"| tools
tools --> jc
jc -->|REST + basic auth| jenkins[(Jenkins<br/>private network)]tools.py 是单一事实来源。MCP 服务器和 Web 应用中的 LiteLLM 代理都调用相同的五个函数,因此 Cursor 和团队聊天 UI 之间的行为完全一致。
这五个工具:
工具 | 功能 |
| 为版本(如 |
| 为现有标签的一个仓库排队 |
| 最新或特定构建的结果、持续时间和参数 |
| 历史记录(最新优先) |
| 控制台输出的最后 N 行 |
快速入门 - Cursor 中的 MCP
完整指南:docs/CURSOR_MCP.md。简要版本:
在
<JENKINS_URL>/me/configure-> Add new Token 处生成 Jenkins API 令牌。安装
uv:pipx install uv编辑
~/.cursor/mcp.json(Windows:%USERPROFILE%\.cursor\mcp.json):{ "mcpServers": { "netlinq-jenkins": { "command": "uvx", "args": [ "--from", "git+ssh://git@github.com/<your-org>/netlinq-jenkins-mcp.git@main", "netlinq-jenkins-mcp" ], "env": { "JENKINS_URL": "https://jenkins.internal.example.com", "JENKINS_USER": "your-user", "JENKINS_TOKEN": "your-api-token" } } } }重启 Cursor。在 Settings -> MCP 中查找 netlinq-jenkins 旁边的绿点。
在聊天中尝试:“build 7.0 release package”。代理会在实际触发 Jenkins 之前进行确认。
快速入门 - 团队聊天 UI (Docker)
git clone git@github.com:<your-org>/netlinq-jenkins-mcp.git
cd netlinq-jenkins-mcp
cp .env.example .env
# edit .env: JENKINS_*, LLM_*, WEB_USERS
# Create at least one web user. The hash MUST be bcrypt-hashed.
python -c "from passlib.hash import bcrypt; print('alice:' + bcrypt.hash('secret123'))"
# paste the line into WEB_USERS=
docker compose up -d --build
# browse http://<host>:8000 - log in with alice / secret123团队看到的内容:
底部有聊天输入框,中间有对话记录。
右侧有两条流水线的实时“最近构建”面板,每 5 秒轮询一次。
工具调用卡片会在行内展开,以便人们准确看到机器人正在执行的操作。
标题上的“重置”按钮可清除代理的记忆。
本地开发 (无 Docker)
# Python side
python -m venv .venv
.\.venv\Scripts\Activate.ps1 # PowerShell
# or: source .venv/bin/activate # bash
pip install -e ".[dev]"
# Frontend side (only needed for the web mode)
cd ui
npm install
npm run build # writes ui/dist/, which web.py auto-serves
cd ..
# Run the web app
netlinq-jenkins-web
# or, with auto-reload:
uvicorn netlinq_jenkins.web:create_app --factory --reload --port 8000
# Or run as MCP (stdio - the way Cursor will spawn it)
netlinq-jenkins-mcp
# Run tests
pytest配置参考
所有设置均来自环境变量(或 .env 文件)。
请参阅 .env.example 获取规范列表。
变量 | 默认值 | 用途 |
| 必填 | Jenkins 控制器的基础 URL |
| 必填 | 服务账户用户名 |
| 必填 | API 令牌(推荐)或密码 |
| 空 | 自签名 TLS 的 CA 证书包路径,或 |
|
| 如果您的作业名称不同,请覆盖此项 |
|
| 作业的版本参数名称 |
|
| 补丁流水线名称 |
|
| 补丁流水线的仓库参数名称 |
|
| 补丁流水线的标签参数名称 |
|
| 信息性 - LiteLLM 根据 |
|
| |
| - | 提供商密钥(仅限 Web 模式) |
| - | 用于 Azure / Ollama / 自托管端点 |
|
| FastAPI 绑定主机 |
|
| FastAPI 绑定端口 |
| 空 | 用于 Web 基本认证的 |
| - |
|
|
| 记录每个工具调用的 JSONL 文件 |
发现 Jenkins 参数名称
如果 VERSION / REPO / TAG 不是您的真实参数名称,请询问 Jenkins:
curl -s -u "$JENKINS_USER:$JENKINS_TOKEN" \
"$JENKINS_URL/job/NetLinQ%20EMS%20Release%20pipeline/api/json?tree=property[parameterDefinitions[name,type,defaultParameterValue[value]]]" \
| jq然后在 .env 或您的 Cursor mcp.json 中覆盖相关的 *_PARAM 环境变量。
LLM 提供商提示
Web 模式使用 LiteLLM,因此您可以纯粹通过环境变量切换提供商。常见组合:
提供商 |
|
|
|
OpenAI |
|
| - |
Anthropic |
|
| - |
Azure OpenAI |
| Azure 密钥 |
|
Ollama (本地) |
| - |
|
OpenAI 兼容 |
| 密钥 |
|
Cursor 中的 MCP 模式不需要这些 - Cursor 自身的模型驱动对话并仅调用我们的工具。
安全说明
.env已被 git 忽略 - 密钥永远不会离开主机。Web 模式需要 HTTP 基本认证(在
WEB_USERS中进行 bcrypt 哈希处理)。可选的
WEB_API_SHARED_SECRET在/api/*上添加了基于标头的第二重验证,旨在用于“反向代理后”的部署。不需要入站互联网流量 - 应用仅向 Jenkins 发起出站连接。
优先使用 API 令牌而非密码:令牌跳过了 CSRF crumb 验证,且更容易撤销。
在进行任何 HTTP 调用之前,输入会通过严格的正则表达式(
version、repo、tag)进行验证,因此健谈的 LLM 无法注入 shell 元字符。每个工具调用都会追加到审计日志中(见下文)。
审计日志
每次成功的触发都会向 ${AUDIT_LOG_PATH} 写入一行 JSONL:
{"ts": "2026-05-06T20:30:11+00:00", "event": "trigger",
"pipeline": "NetLinQ EMS Release pipeline",
"parameters": {"VERSION": "7.0"},
"queue_url": "https://jenkins.internal.example.com/queue/item/812/"}在 Docker 模式下,该文件被绑定挂载到主机上的 ./logs/audit.jsonl。
项目布局
netlinq-jenkins-mcp/
├── src/netlinq_jenkins/
│ ├── config.py # pydantic-settings
│ ├── jenkins_client.py # async httpx wrapper, crumb handling
│ ├── tools.py # 5 tool functions, used by both modes
│ ├── llm.py # LiteLLM tool-calling agent (web mode only)
│ ├── mcp_server.py # FastMCP stdio entrypoint (Cursor)
│ └── web.py # FastAPI app + serves the bundled UI
├── ui/ # Vite + React + Tailwind chat UI
│ ├── src/App.tsx # main chat layout
│ └── src/components/ # ToolCard, BuildsPanel
├── tests/ # pytest + pytest-httpx
├── docs/CURSOR_MCP.md # detailed Cursor integration guide
├── examples/cursor-mcp.json
├── Dockerfile # multi-stage: builds UI, then Python wheel
├── docker-compose.yml
├── .env.example
└── pyproject.toml路线图 / 下一步
[ ] Web UI 使用 OIDC / SSO 代替 HTTP 基本认证。
[ ] Slack 机器人适配器,将
/build 7.0斜杠命令转发到相同的工具。[ ] 可选的只读模式 (
READ_ONLY=true),禁用触发工具。[ ] UI 中的 WebSocket 日志尾随,而不是轮询侧边栏。
[ ] 每个用户一个审计日志,而不是一个全局文件。
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/RadhaKrishna0018/netlinq-jenkins-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server