ArgoCD-MCP 管理器
一个MCP(模型上下文协议)服务器,它与ArgoCD API集成,使人工智能助手和大型语言模型能够通过自然语言交互来管理ArgoCD应用程序和资源。
服务介绍
ArgoCD MCP 服务器
一个与 ArgoCD API 集成的 MCP(Model Context Protocol)服务器,使 AI 助手和大型语言模型能够通过自然语言交互来管理 ArgoCD 应用程序和资源。
特性
- 认证与会话管理:
- 从 ArgoCD API 获取用户信息
- 使用基于令牌的 ArgoCD 认证
- 访问服务器设置和配置
- 插件信息检索
- 版本信息检索
- 应用程序管理:
- 按项目、名称、命名空间列出和过滤应用程序
- 获取详细的应用程序信息
- 创建、更新和删除应用程序
- 使用可配置选项同步应用程序
- 强大的 API 客户端:
- URL 标准化和智能端点处理
- 全面的错误处理和详细的错误消息
- 可配置的超时和 SSL 验证
- 令牌安全保护和掩码
- 开发者体验:
- 使用 mypy 进行完整的静态类型检查
- 详细的文档和示例
- 基于环境的配置
快速开始
设置
# Clone the repository
git clone https://github.com/yourusername/argocd-mcp.git
cd argocd-mcp
# Create virtual environment and activate it
uv venv
source .venv/bin/activate
# Install dependencies
uv pip install -e .
启动服务器
服务器通过环境变量进行配置。以下是可用的配置选项:
| 环境变量 | 描述 | 默认值 |
|---|---|---|
ARGOCD_TOKEN |
ArgoCD API 令牌 | 无 |
ARGOCD_API_URL |
ArgoCD API 端点 | https://argocd.example.com/api/v1 |
ARGOCD_VERIFY_SSL |
验证 SSL 证书 | true |
您可以以多种方式启动服务器:
# Using MCP dev tools (provides debugging tools)
export ARGOCD_TOKEN=YOUR_ARGOCD_TOKEN
mcp dev server.py
# Using MCP run command
export ARGOCD_TOKEN=YOUR_ARGOCD_TOKEN
mcp run server.py
# Standard method
export ARGOCD_TOKEN=YOUR_ARGOCD_TOKEN
uv run server.py
# Setting multiple environment variables
export ARGOCD_TOKEN=YOUR_ARGOCD_TOKEN
export ARGOCD_API_URL=https://your-argocd-server.com:9000/api/v1
export ARGOCD_VERIFY_SSL=false # Disable SSL verification for self-signed certs
uv run server.py
# Using a .env file
echo "ARGOCD_TOKEN=YOUR_ARGOCD_TOKEN
ARGOCD_API_URL=https://your-argocd-server.com:9000/api/v1
ARGOCD_VERIFY_SSL=false" > .env
uv run server.py
# Run in background
export ARGOCD_TOKEN=YOUR_ARGOCD_TOKEN
uv run server.py > server.log 2>&1 & echo $! > server.pid
当通过环境变量提供令牌时,Claude 可以使用它而无需在每个命令中指定。
与 Claude 连接
使用 Claude Code CLI
# Add the MCP server
claude mcp add argocd-mcp "uv run $(pwd)/server.py"
# With token
claude mcp add argocd-mcp -e ARGOCD_TOKEN=YOUR_ARGOCD_TOKEN -- "uv run $(pwd)/server.py"
# Verify it was added
claude mcp list
# For debugging, you can use MCP Inspector with 'mcp dev' command
使用 Claude Desktop
创建一个 claude_desktop_config.json 配置文件:
{
"mcpServers": {
"argocd-mcp": {
"command": "/path/to/uv",
"args": [
"--directory",
"/path/to/argocd-mcp",
"run",
"server.py"
],
"env": {
"ARGOCD_TOKEN": "your_argocd_token",
"ARGOCD_API_URL": "https://your-argocd-server.com/api/v1",
"ARGOCD_VERIFY_SSL": "true"
}
}
}
}
将路径和配置值替换为您的实际值:
- 使用 uv 可执行文件的完整路径(在 macOS/Linux 上使用
which uv或在 Windows 上使用where uv查找) - 设置正确的 argocd-mcp 安装目录路径
- 添加您的 ArgoCD API 令牌
- 根据需要配置其他环境变量
此配置告诉 Claude Desktop 如何根据您的特定环境设置自动启动 MCP 服务器。
可用工具
会话工具
get_user_info: 通过 api/v1/session/userinfo 获取当前用户的信息
设置工具
get_settings: 获取 ArgoCD 服务器设置,包括 UI、OIDC 和其他配置get_plugins: 获取已配置的 ArgoCD 插件信息
版本工具
get_version: 获取 API 服务器的版本信息
应用程序管理工具
list_applications: 获取所有应用程序并提供过滤选项get_application_details: 获取特定应用程序的详细信息create_application: 创建新应用程序update_application: 更新现有应用程序delete_application: 删除应用程序sync_application: 触发应用程序上的同步操作
示例对话
检查用户信息
User: What's my user information in ArgoCD?
Claude: Let me retrieve your user information.
⏺ argocd-mcp:get_user_info (MCP)
⎿ {"loggedIn": true, "username": "devops-user", "iss": "argocd"}
You are logged in as 'devops-user'.
获取 ArgoCD 版本
User: What version of ArgoCD is running on the server?
Claude: Let me check the ArgoCD version information.
⏺ argocd-mcp:get_version (MCP)
⎿ {
"Version": "v2.9.3+5eaf684",
"BuildDate": "2023-09-15T14:25:11Z",
"GitCommit": "5eaf68452",
"GitTreeState": "clean",
"GoVersion": "go1.20.7",
"Compiler": "gc",
"Platform": "linux/amd64",
"KustomizeVersion": "v5.1.1",
"HelmVersion": "v3.12.3",
"KubectlVersion": "v1.27.4",
"JsonnetVersion": "v0.20.0"
}
You're running ArgoCD v2.9.3, built on September 15, 2023. It's running on Linux (amd64) with Go 1.20.7, and includes Kustomize v5.1.1 and Helm v3.12.3.
获取 ArgoCD 设置
User: Show me the ArgoCD server settings
Claude: Let me retrieve the ArgoCD server settings for you.
⏺ argocd-mcp:get_settings (MCP)
⎿ {
"clusterSettings": {
"appLabelKey": "argocd.argoproj.io/instance",
"controllerNamespace": "argocd",
"execEnabled": true,
"statusBadgeEnabled": true,
"uiBannerContent": "This is a development instance of ArgoCD",
"url": "https://argocd.example.com"
}
}
Here are the key settings for your ArgoCD server:
- URL: https://argocd.example.com
- Controller namespace: argocd
- Exec enabled: Yes
- Status badge enabled: Yes
- UI Banner: "This is a development instance of ArgoCD"
管理应用程序
User: What applications do I have in the "production" project?
Claude: Let me list your applications in the production project.
⏺ argocd-mcp:list_applications (MCP)
⎿ {
"items": [
{
"metadata": {
"name": "frontend-app",
},
"status": {
"sync": {"status": "Synced"},
"health": {"status": "Healthy"},
}
},
{
"metadata": {
"name": "api-service",
},
"status": {
"sync": {"status": "OutOfSync"},
"health": {"status": "Healthy"},
}
},
{
"metadata": {
"name": "database",
},
"status": {
"sync": {"status": "Synced"},
"health": {"status": "Degraded"},
}
}
]
}
You have 3 applications in the production project:
- frontend-app (Synced, Healthy)
- api-service (OutOfSync, Healthy)
- database (Synced, Degraded)
User: Sync the api-service application
Claude: I'll sync the api-service application for you.
⏺ argocd-mcp:sync_application (MCP)
⎿ {
"resourcesResult": {
"updated": ["Deployment/api-service"],
"hooks": []
},
"status": "Syncing"
}
Application sync initiated successfully. The sync operation is now in progress.
开发
需求
- Python 3.12+
- MCP(包括 FastMCP 和开发工具)
- uv 包管理器(推荐)或 pip
- ArgoCD API 令牌
类型检查
此项目使用 mypy 进行静态类型检查,以提高代码质量和及早发现类型相关错误:
# Install mypy
uv pip install mypy
# Run type checking
uv run -m mypy .
类型检查配置在 pyproject.toml 和 mypy.ini 中均可获得。该配置强制执行严格的类型规则,包括:
- 不允许未类型定义
- 对返回 Any 类型发出警告
- 检查函数定义的完整性
- 命名空间包支持
- 模块特定配置
项目结构
代码被组织成模块化结构:
argocd-mcp/
├── api/ # API client and communication
│ ├── __init__.py
│ └── client.py # HTTP client for ArgoCD API
├── models/ # Data models
│ ├── __init__.py
│ └── applications.py # Application data structures
├── tools/ # MCP tools implementation
│ ├── __init__.py
│ ├── session.py # Session tools (user info)
│ ├── applications.py # Application management tools
│ ├── settings.py # Server settings tools
│ └── version.py # Version information tools
├── utils/ # Utility functions
│ ├── __init__.py
├── server.py # Main server entry point
├── pyproject.toml # Project configuration and dependencies
└── mypy.ini # Mypy type checking configuration
扩展服务器
要添加新功能:
- 在
tools目录中适当模块下添加新工具 - 在
server.py中注册新工具 - 遵循现有的参数验证和错误处理模式
- 更新 README.md 中的文档
- 为新功能添加测试
故障排除
如果您遇到问题:
- 检查服务器日志(默认启用信息记录)
- 注意
Processing request of type CallToolRequest是信息性消息,不是错误 - 如果使用
mcp dev server.py,MCP Inspector 将自动在 http://localhost:5173 上打开以便调试 - 使用服务器日志来调试 API 调用和响应
- 对于自签名证书的 SSL 证书问题:
# Disable SSL verification
export ARGOCD_VERIFY_SSL=false
uv run server.py
- 检查是否正确设置了所有必需的环境变量:
# Show all current ArgoCD environment variables
env | grep ARGOCD
贡献
欢迎贡献!如果您希望为该项目做贡献,请打开一个 issue 或 pull request。
当贡献时,请遵循以下指南:
- 确保所有代码包含适当的类型提示
- 在提交 PR 之前运行 mypy 类型检查
- 为新功能添加测试
- 更新任何新特性或更改的文档