使用说明
win-cli-mcp服务器
硬化 MCP服务器 用于Windows CLI和SSH交互。提供受控访问 PowerShell, 命令提示符, Git Bash,以及 通过SSH远程系统 来自MCP客户,如 克劳德桌面版.
叉子血统
这是一个经过维护的硬化叉子:
SimonB97/win-cli-mcp服务器 (原创,开发停滞) -> delorenj/superwin cli-mcp服务器 (超级胜利cli变体) -> 此回购 (错误修复、强化、依赖更新)
原始项目不再积极维护。这个分支修复了关键的错误,更新了依赖关系,每天都在生产中使用。
这个叉子修复了什么
关键的
- GUI窗口弹出窗口 --已添加
windowsHide: true到child_process.spawn().MCP执行期间,Shell窗口不再在屏幕上闪烁。 - SSH事件侦听器泄漏 --重新连接周期在ssh2上累积了重复的处理程序
Client例如,导致内存泄漏。通过创建一个新的Client每次重新连接和使用.once()用于连接范围的事件。 - SSH stderr已静默删除 --当stdout有内容时,stderr被丢弃(
output || errorOutput).现在,这两条流被合并了。 - BOM上的静默配置回退 --UTF-8 BOM
config.json导致JSON.parse()放弃,默默地回到限制性违约。BOM现在在解析之前被剥离。
高
- 已删除死依赖项 --
@modelcontextprotocol/server-memory-dynamic指向file:../servers/src/memory(作者的本地开发路径)。远离的。 - SSH代理身份验证支持 --需要配置验证
password或privateKeyPath。如果两者都没有指定,则整个配置加载失败。现在可选——ssh2自动回退到ssh代理。 - SIGTERM 交易 --只有信号情报触发了清理。当父进程发送SIGTERM时(Claude Desktop重新启动时很常见),SSH连接现在会优雅地关闭。
- MCP SDK已更新 --从v1.0.1跳到v1.29.0(28个版本的错误修复、安全补丁、协议改进)。零破坏性变化。
- npm审计清理 --所有已知漏洞均已解决。
清理
- 已删除死代码 --
resolveCommandPath,isPathAllowed,validateWorkingDirectory,normalizeWindowsPath(出口但从未进口)。未使用的进口(exec,promisify)也删除了。 @types/ssh2移动到devDependencies --类型包不属于生产仓库。- 输出尺寸上限 --Shell输出现在限制在1MB,以防止对转储大输出的命令进行OOM。截断的输出包括通知。
安装
添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"win-cli": {
"command": "node",
"args": [
"C:/path/to/win-cli-mcp-server/dist/index.js",
"--config",
"C:/path/to/win-cli-mcp-server/config.json"
]
}
}
}
或者克隆并设置:
git clone https://github.com/mhprol/win-cli-mcp-server.git
cd win-cli-mcp-server
npm install
npm run build
配置
复制 config.example.json 到 config.json 并自定义:
{
"security": {
"maxCommandLength": 50000,
"blockedCommands": [],
"blockedArguments": [],
"allowedPaths": [],
"restrictWorkingDirectory": false,
"logCommands": true,
"maxHistorySize": 2000,
"commandTimeout": 600,
"enableInjectionProtection": false
},
"shells": {
"powershell": {
"enabled": true,
"command": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
"args": ["-NoProfile", "-NoLogo", "-NonInteractive", "-Command"],
"blockedOperators": []
},
"cmd": {
"enabled": true,
"command": "cmd.exe",
"args": ["/c"],
"blockedOperators": []
},
"gitbash": {
"enabled": true,
"command": "C:\\Program Files\\Git\\bin\\bash.exe",
"args": ["--norc", "-c"],
"blockedOperators": []
}
},
"ssh": {
"enabled": true,
"defaultTimeout": 30,
"maxConcurrentSessions": 5,
"keepaliveInterval": 10000,
"keepaliveCountMax": 3,
"readyTimeout": 20000,
"connections": {
"my-server": {
"host": "192.168.1.100",
"port": 22,
"username": "user",
"privateKeyPath": "C:\\Users\\you\\.ssh\\id_ed25519"
}
}
}
}
SSH身份验证优先级:显式密钥>密码>ssh代理(自动)。
配置说明:
- 文件必须是没有BOM的有效JSON(UTF-8,没有BOM)。大多数编辑器默认为此设置。
config.json为了保护凭据而忽略。使用config.example.json作为模板。- 外壳
command路径应该指向实际的可执行文件(例如。,pwsh.exePS7没有powershell.exe适用于PS5.1)。
工具
| 工具 | 说明 |
|---|---|
execute_command |
在PowerShell、CMD或Git Bash中运行命令 |
get_command_history |
检索已执行命令的历史记录 |
ssh_execute |
在已配置的远程主机上执行命令 |
ssh_disconnect |
关闭SSH连接 |
安全
此服务器提供 通过SSH直接访问系统的命令行和远程系统默认配置是有意为受信任的单用户环境打开的。对于共享或公开的设置:
- 启用
restrictWorkingDirectory并设置allowedPaths - 填充
blockedCommands和blockedArguments - 启用
enableInjectionProtection - 集
blockedOperators每壳 - 使用基于密钥的SSH身份验证,切勿在配置中存储密码
学分
许可证
麻省理工学院——见 许可证.