README
🚀 NHN Server MCP
NHN Server MCP 是一个 MCP(Model Context Protocol)服务器,可通过 SSH Gateway 连接到服务器并执行命令。
🚀 快速开始
NHN Server MCP 允许你通过 SSH Gateway 连接服务器并执行命令。下面将为你介绍其主要特性、安装步骤、配置方法等内容。
✨ 主要特性
- 通过 SSH Gateway 连接服务器
- 支持 Kerberos 认证(kinit)
- 使用 macOS 原生对话框确认命令执行
- 提供“始终允许”选项,自动批准相同命令
- 支持查询服务器信息(AI 可查看日志路径等)
- 支持动态重新加载配置
📦 安装指南
npm install
npm run build
📚 详细文档
配置步骤
1. 创建 config.json
{
"gatewayConnection": "user@gateway.example.com:22",
"gatewayPassword": "your-password",
"kinitPassword": "your-kerberos-password",
"allowedHosts": ["server1", "server2"],
"confirmDialog": true,
"serverInfo": {
"서버에 대한 user 정보 필수": "exec 할때 user 를 같이 보냅니다.",
"나머지는": "원하는 내용으로",
"ex - logPaths": {
"app": "/var/log/app.log",
"nginx": "/var/log/nginx/access.log"
}
}
}
2. 客户端配置
Claude Code (CLI)
可以使用 CLI 命令进行注册:
# 项目级(仅在该项目中使用)
claude mcp add --scope project nhn-server -e CONFIG_FILE=/path/to/config.json -e DEBUG=false -- node /path/to/nhn-server-mcp/dist/index.js
# 全局级(在所有项目中使用)
claude mcp add --scope user nhn-server -e CONFIG_FILE=/path/to/config.json -e DEBUG=false -- node /path/to/nhn-server-mcp/dist/index.js
也可以直接编辑配置文件:
- 项目级:在项目根目录下创建
.mcp.json文件:
{
"mcpServers": {
"nhn-server": {
"command": "node",
"args": ["/path/to/nhn-server-mcp/dist/index.js"],
"env": {
"CONFIG_FILE": "/path/to/config.json",
"DEBUG": "false"
}
}
}
}
- 全局级:在
~/.claude.json文件中添加以下内容:
{
"mcpServers": {
"nhn-server": {
"command": "node",
"args": ["/path/to/nhn-server-mcp/dist/index.js"],
"env": {
"CONFIG_FILE": "/path/to/config.json",
"DEBUG": "false"
}
}
}
}
.mcp.json:仅在当前项目中使用。如果提交到 git 仓库,团队成员可以共享(注意:config.json的路径可能因个人而异)。
~/.claude.json:在所有项目中使用,用于个人环境配置。
Claude Desktop
在 ~/Library/Application Support/Claude/claude_desktop_config.json 文件中添加以下内容:
{
"mcpServers": {
"nhn-server": {
"command": "node",
"args": ["/path/to/nhn-server-mcp/dist/index.js"],
"env": {
"CONFIG_FILE": "/path/to/config.json",
"DEBUG": "false"
}
}
}
}
配置选项
| 键 | 说明 | 默认值 |
|---|---|---|
| gatewayConnection | Gateway SSH 连接(user@host:port) | - |
| gatewayPassword | Gateway SSH 密码 | - |
| kinitPassword | Kerberos 认证密码 | - |
| allowedHosts | 允许连接的主机列表 | [](允许所有) |
| confirmDialog | 执行命令前显示确认对话框 | true |
| serverInfo | 向 AI 公开的服务器信息 | {} |
环境变量
| 变量 | 说明 |
|---|---|
| CONFIG_FILE | config.json 文件的路径 |
| DEBUG | 启用调试日志(true/false) |
MCP 工具
exec
在服务器上执行命令:
{
"host": "server-hostname",
"user": "irteam",
"command": "tail -100 /var/log/app.log"
}
如果 confirmDialog 启用,将显示 macOS 原生对话框:
- 取消:不执行命令
- 确认:仅执行本次命令
- 始终允许:执行命令并在后续自动批准相同命令(会话结束时重置)
get_config
查询服务器配置信息(允许的主机、服务器信息)。
reload_config
重新加载配置文件。
disconnect_server
断开 Gateway 连接。
connection_status
检查当前连接状态。
🔧 技术细节
安全措施
- 由于
config.json包含敏感信息(密码),请勿将其提交到 git 仓库。 - 使用
confirmDialog确保在执行命令前获得用户确认。 - 使用
allowedHosts限制可连接的服务器。 - 系统在 5 分钟无操作后自动断开连接。
- 发生异常时自动清理会话。
📄 许可证
本项目采用 MIT 许可证。
微信扫一扫