ArgoCD-MCP 管理器添加福利群:解决AI开发者的「MCP实战痛点」一个与 ArgoCD API 集成的 MCP(Model Context Protocol)服务器,使 AI 助手和大型语言模型能够通过自然语言交互来管理 ArgoCD 应用程序和资源。
# 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 可以使用它而无需在每个命令中指定。
# 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_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"
}
}
}
}

将路径和配置值替换为您的实际值:
which uv 或在 Windows 上使用 where uv 查找)此配置告诉 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'.
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.
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.
此项目使用 mypy 进行静态类型检查,以提高代码质量和及早发现类型相关错误:
# Install mypy
uv pip install mypy
# Run type checking
uv run -m mypy .

类型检查配置在 pyproject.toml 和 mypy.ini 中均可获得。该配置强制执行严格的类型规则,包括:
代码被组织成模块化结构:
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 中注册新工具如果您遇到问题:
Processing request of type CallToolRequest 是信息性消息,不是错误mcp dev server.py,MCP Inspector 将自动在 http://localhost:5173 上打开以便调试# Disable SSL verification
export ARGOCD_VERIFY_SSL=false
uv run server.py

# Show all current ArgoCD environment variables
env | grep ARGOCD

欢迎贡献!如果您希望为该项目做贡献,请打开一个 issue 或 pull request。
当贡献时,请遵循以下指南: