关于 Directadmin
Directadmin 是连接 AI 助手与 DirectAdmin 的 MCP 服务,供管理员通过自然语言查询和执行服务器管理操作。它提供 SSE 接口、命令行客户端及 Docker 部署支持。
主要功能
- 01查询 DirectAdmin 信息
- 02执行系统管理工具
- 03通过 SSE 实时通信
- 04附带命令行客户端
- 05支持 Docker 部署
适用场景
- 01查询 DirectAdmin 版本
- 02检查服务运行状态
- 03查看或执行系统更新
- 04管理 security.txt
MCP 相关
服务将 DirectAdmin API 操作封装为 MCP 工具,并通过 SSE 等方式供客户端连接。
配置
远程服务无需本地安装。选择你使用的客户端,复制配置或使用一键安装。
http://localhost:8888/sseclaude mcp add --transport http directadmin http://localhost:8888/sse{"mcpServers":{"directadmin":{"type":"http","url":"http://localhost:8888/sse"}}}在 Cursor 中打开{"servers":{"directadmin":{"type":"http","url":"http://localhost:8888/sse"}}}在 VS Code 中打开{"mcpServers":{"directadmin":{"type":"http","url":"http://localhost:8888/sse"}}}{"mcpServers":{"directadmin":{"serverUrl":"http://localhost:8888/sse"}}}命令在终端中运行;JSON 粘贴到对应客户端的 MCP 配置后重启。需要授权的服务会在首次连接时提示登录。
工具
详细介绍
DirectAdmin MCP 服务
用于集成 DirectAdmin 的模型上下文协议(MCP)服务,让 AI 助手能够通过自然语言与 DirectAdmin 交互。
功能
- MCP 集成:使用模型上下文协议将 AI 助手连接到 DirectAdmin
- RESTful API:用于管理 DirectAdmin 的综合 API
- 服务器发送事件(SSE):与客户端实时通信
- 基于工具的架构:采用基于工具命令的模块化设计
- 命令行客户端:附带用于测试和编写脚本的客户端
- Docker 支持:通过 Docker 和 Docker Compose 轻松部署
架构
本项目实现了一个充当 AI 助手与 DirectAdmin 之间桥梁的服务:
┌──────────┐ ┌─────────────────┐ ┌────────────┐
│ AI │ │ DirectAdmin │ │ DirectAdmin│
│ Assistant├────►│ MCP Server ├────►│ API │
└──────────┘ └─────────────────┘ └────────────┘
MCP SSE HTTP
该服务通过基于工具的接口提供 DirectAdmin 功能,让 AI 助手能够轻松理解并与 DirectAdmin 操作交互。
前提条件
- Python 3.12+
- 可访问 API 的 DirectAdmin 服务
- DirectAdmin 登录密钥(首选)或用户名/密码
安装
选项 1:标准安装
-
克隆代码库:
git clone https://github.com/omryatia/directadmin-mcp.git cd directadmin-mcp -
创建虚拟环境:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate -
安装依赖:
pip install -r requirements.txt -
创建配置:
cp .gitignore.sample .gitignore cp .env.sample .env # Edit .env with your DirectAdmin settings
选项 2:Docker 安装
-
克隆代码库:
git clone https://github.com/omryatia/directadmin-mcp.git cd directadmin-mcp -
创建配置:
cp .env.sample .env # Edit .env with your DirectAdmin settings -
使用 Docker Compose 构建并启动:
docker-compose up -d
配置
编辑 .env 文件,填入 DirectAdmin 凭据:
# DirectAdmin Settings
DA_URL=https://your-directadmin-server:2222
DA_USERNAME=admin
DA_LOGIN_KEY=your_directadmin_login_key_here/password
# Server Settings
PORT=8888
LOG_LEVEL=INFO
DEBUG=false
# SSL Settings
SSL_VERIFY=true
配置选项
| 变量 | 描述 | 默认值 |
|---|---|---|
DA_URL | DirectAdmin 服务 URL(含端口) | (必填) |
DA_USERNAME | DirectAdmin 用户名 | (必填) |
DA_LOGIN_KEY | DirectAdmin 登录密钥 | (必填) |
PORT | MCP 服务运行端口 | 8888 |
LOG_LEVEL | 日志级别(DEBUG、INFO、WARNING、ERROR) | INFO |
DEBUG | 为开发启用调试模式 | false |
SSL_VERIFY | 验证 DirectAdmin API 调用的 SSL 证书 | true |
使用方法
启动服务
你可以通过以下两种方式启动服务:
-
使用支持 SSE 的 FastAPI(推荐):
python main.py -
使用简单的 MCP 服务:
python server.py
默认情况下,服务将在 8888 端口启动(可在 .env 中配置)。
使用命令行客户端
附带的命令行客户端可让你与 MCP 服务交互:
# Get server info
python client.py --info
# Check server health
python client.py --health
# Send a specific message
python client.py "Show me the version of DirectAdmin"
# Interactive mode
python client.py
客户端选项
| 选项 | 描述 |
|---|---|
--server、-s | MCP 服务 URL |
--key、-k | 用于身份验证的 API 密钥 |
--no-verify | 禁用 SSL 验证 |
--timeout、-t | 请求超时时间(秒) |
--info、-i | 获取服务信息 |
--health | 检查服务运行状况 |
连接 AI 助手
配置 AI 助手以使用 MCP 端点:
http://your-server:8888/sse
这样 AI 助手就可以:
- 查询 DirectAdmin 信息
- 执行 DirectAdmin 命令
- 接收实时更新
可用工具
该服务将以下 DirectAdmin 操作作为工具提供:
系统管理
api_restart:重启 DirectAdminapi_ping:检查 DirectAdmin 是否正在运行
版本控制
api_get_version:获取 DirectAdmin 版本信息api_version_update:将 DirectAdmin 更新到最新版本api_change_update_channel:更改更新频道
系统更新
api_system_packages_updates:获取可用的系统软件包更新api_system_packages_update_test:测试系统软件包更新api_system_packages_update_run:运行系统软件包更新
安全
api_security_txt_status:检查 security.txt 状态api_security_txt_get:获取 security.txt 内容api_security_txt_update:更新 security.txt 内容
API 端点
| 端点 | 方法 | 描述 |
|---|---|---|
/ | GET | 显示 HTML 欢迎消息的根页面 |
/about | GET | 服务信息 |
/health | GET | 健康检查端点 |
/sse | GET | MCP SSE 连接端点 |
/messages | POST | 用于发布 SSE 消息的内部端点 |
开发
项目结构
directadmin-mcp/
├── README.md # Project documentation
├── .env.sample # Environment variables template
├── config.py # Configuration module
├── main.py # FastAPI application with SSE support
├── server.py # Simple MCP server
├── client.py # Command-line client
├── da.py # DirectAdmin API client
├── mcp_instance.py # MCP instance configuration
├── tools/ # Tool modules directory
│ ├── __init__.py # Tool loading mechanism
│ ├── common.py # Common tool utilities
│ ├── misc.py # Misc DirectAdmin operations
│ ├── security_txt.py # Security.txt related tools
│ ├── system_update.py # System update tools
│ └── versioning.py # Versioning and update tools
│ └── and alot more ......
└── requirements.txt # Project dependencies
添加新工具
- 在
tools目录中创建或编辑文件 - 使用
@mcp.tool()装饰器添加新函数:
import logging
from mcp_instance import mcp
from da import call_da_api
from tools.common import log_tool_call, format_response
@mcp.tool()
@log_tool_call
async def my_new_tool(param1, param2):
"""
Tool documentation.
Args:
param1: First parameter description
param2: Second parameter description
Returns:
Description of the return value
"""
# Implementation
response = await call_da_api("/api/endpoint", method="GET")
return format_response(response)
服务器启动时会自动发现并注册该工具。
日志记录
服务器使用完善的日志记录系统:
- 控制台日志:显示在终端中
- 文件日志:写入
logs目录 - 错误日志:单独的文件,用于跟踪错误
可以在 .env 文件中通过 LOG_LEVEL 变量配置日志级别。
Docker 部署
项目支持 Docker,便于部署:
# Build the image
docker build -t directadmin-mcp .
# Run the container
docker run -d \
-p 8888:8888 \
--env-file .env \
--name directadmin-mcp \
directadmin-mcp
也可以使用 Docker Compose 简化操作:
docker-compose up -d
安全注意事项
- 在生产环境中使用带有效 SSL 证书的 HTTPS
- 设置适当的防火墙规则以限制访问
- 使用配置了适当安全标头的反向代理(如 Nginx)
- 妥善保管 DirectAdmin 登录密钥并定期轮换
- 考虑在生产环境中为 MCP 服务添加身份验证
故障排除
连接问题
如果遇到连接问题:
- 确认 DirectAdmin 服务可访问
- 检查 DirectAdmin API 凭据是否正确
- 确保已启用 DirectAdmin API
- 如果使用 HTTPS,请检查 SSL 设置
常见错误消息
- “身份验证失败”:检查 DirectAdmin 凭据
- “SSL 验证失败”:在 .env 中设置
SSL_VERIFY=false,或修复证书 - “未找到工具”:确保已正确加载工具模块
- “连接被拒绝”:检查 DirectAdmin 是否正在运行且可访问
贡献
欢迎贡献!请随时提交 Pull Request。
- Fork 此仓库
- 创建功能分支(
git checkout -b feature/amazing-feature) - 提交更改(
git commit -m 'Add some amazing feature') - 推送到分支(
git push origin feature/amazing-feature) - 创建 Pull Request
许可证
本项目采用 MIT 许可证,详情请参阅 LICENSE 文件。
致谢
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。