[!CAUTION] 项目已废弃 - 不再维护。 使用 https://github.com/wonderwhy-er/DesktopCommanderMCP 替代以获得类似功能。
用于 Windows 系统安全命令行交互的 MCP 服务器,支持对 PowerShell、CMD、Git Bash 命令行以及通过 SSH 远程系统的受控访问。它允许 MCP 客户端(如 Claude Desktop)在您的系统上执行操作,类似于 Open Interpreter。
[!IMPORTANT] 此 MCP 服务器提供对您系统命令行界面及通过 SSH 的远程系统直接访问。启用后,它将授予对您的文件、环境变量、命令执行能力和远程服务器管理的访问权限。
- 审查并限制允许的路径和 SSH 连接
- 启用目录限制
- 配置命令阻塞
- 考虑安全影响
详情见 配置。
详见 API 部分,了解服务器提供的工具和资源详情。
注意:服务器仅允许在配置目录内、使用允许命令以及在配置的 SSH 连接上进行操作。
在您的 claude_desktop_config.json 中添加以下内容:
{
"mcpServers": {
"windows-cli": {
"command": "npx",
"args": ["-y", "@simonb97/server-win-cli"]
}
}
}
若要使用特定配置文件,请添加 --config 标志:
{
"mcpServers": {
"windows-cli": {
"command": "npx",
"args": [
"-y",
"@simonb97/server-win-cli",
"--config",
"path/to/your/config.json"
]
}
}
}
配置完成后,您可以:
服务器使用一个 JSON 配置文件来自定义其行为。您可以指定安全控制、命令行配置和 SSH 连接的设置。
a) 将 config.json.example 复制为 config.json,或
b) 运行:
npx @simonb97/server-win-cli --init-config ./config.json
--config 标志指向您的配置文件,具体方法参见 与 Claude Desktop 的使用 部分。服务器按以下顺序查找配置:
--config 标志指定的路径./config.json~/.win-cli-mcp/config.json如果未找到配置文件,服务器将使用默认(受限)配置:
注意:默认配置旨在严格且安全。更多关于每个设置的详情,请参阅 配置设置 部分。
{
"security": {
"maxCommandLength": 2000,
"blockedCommands": [
"rm",
"del",
"rmdir",
"format",
"shutdown",
"restart",
"reg",
"regedit",
"net",
"netsh",
"takeown",
"icacls"
],
"blockedArguments": [
"--exec",
"-e",
"/c",
"-enc",
"-encodedcommand",
"-command",
"--interactive",
"-i",
"--login",
"--system"
],
"allowedPaths": ["用户主目录", "当前工作目录"],
"restrictWorkingDirectory": true,
"logCommands": true,
"maxHistorySize": 1000,
"commandTimeout": 30,
"enableInjectionProtection": true
},
"shells": {
"powershell": {
"enabled": true,
"command": "powershell.exe",
"args": ["-NoProfile", "-NonInteractive", "-Command"],
"blockedOperators": ["&", "|", ";", "`"]
},
"cmd": {
"enabled": true,
"command": "cmd.exe",
"args": ["/c"],
"blockedOperators": ["&", "|", ";", "`"]
},
"gitbash": {
"enabled": true,
"command": "C:\\Program Files\\Git\\bin\\bash.exe",
"args": ["-c"],
"blockedOperators": ["&", "|", ";", "`"]
}
},
"ssh": {
"enabled": false,
"defaultTimeout": 30,
"maxConcurrentSessions": 5,
"keepaliveInterval": 10000,
"keepaliveCountMax": 3,
"readyTimeout": 20000,
"connections": {}
}
}
配置文件分为三个主要部分:security、shells 和 ssh。
{
"security": {
// 允许的最大命令长度
"maxCommandLength": 1000,
// 阻止的命令 - 阻止直接使用和全路径
// 示例:"rm" 阻止 "rm" 和 "C:\\Windows\\System32\\rm.exe"
// 大小写不敏感:"del" 阻止 "DEL.EXE"、"del.cmd" 等
"blockedCommands": [
"rm", // 删除文件
"del", // 删除文件
"rmdir", // 删除目录
"format", // 格式化磁盘
"shutdown", // 关闭系统
"restart", // 重启系统
"reg", // 注册表编辑器
"regedit", // 注册表编辑器
"net", // 网络命令
"netsh", // 网络命令
"takeown", // 获取文件所有权
"icacls" // 更改文件权限
],
// 与任何命令一起使用的将被阻止的参数
// 注意:独立检查每个参数 - "cd warm_dir" 不会被阻止,即使 "rm" 在 blockedCommands 中
"blockedArguments": [
"--exec", // 执行标志
"-e", // 短执行标志
"/c", // 某些命令行中的命令执行
"-enc", // PowerShell 编码命令
"-encodedcommand", // PowerShell 编码命令
"-command", // 直接执行 PowerShell 命令
"--interactive", // 可能绕过限制的交互模式
"-i", // 交互模式的短形式
"--login", // 登录 shell 可能有不同的权限
"--system" // 系统级操作
],
// 命令可以执行的目录列表
"allowedPaths": ["C:\\Users\\YourUsername", "C:\\Projects"],
// 如果为 true,则命令只能在 allowedPaths 中运行
"restrictWorkingDirectory": true,
// 如果为 true,则保存命令历史
"logCommands": true,
// 历史中保留的最大命令数
"maxHistorySize": 1000,
// 命令执行超时时间(秒,默认:30)
"commandTimeout": 30,
// 启用或禁用防止命令注入的保护(涵盖 ;, &, |, \`)
"enableInjectionProtection": true
}
}
{
"shells": {
"powershell": {
// 启用/禁用此命令行
"enabled": true,
// 命令行可执行文件路径
"command": "powershell.exe",
// 命令行默认参数
"args": ["-NoProfile", "-NonInteractive", "-Command"],
// 可选:指定要阻止的命令操作符
"blockedOperators": ["&", "|", ";", "`"] // 阻止所有命令链
},
"cmd": {
"enabled": true,
"command": "cmd.exe",
"args": ["/c"],
"blockedOperators": ["&", "|", ";", "`"] // 阻止所有命令链
},
"gitbash": {
"enabled": true,
"command": "C:\\Program Files\\Git\\bin\\bash.exe",
"args": ["-c"],
"blockedOperators": ["&", "|", ";", "`"] // 阻止所有命令链
}
}
}
{
"ssh": {
// 启用/禁用 SSH 功能
"enabled": false,
// SSH 命令的默认超时时间(秒)
"defaultTimeout": 30,
// 最大并发 SSH 会话数
"maxConcurrentSessions": 5,
// 发送保活数据包的时间间隔(毫秒)
"keepaliveInterval": 10000,
// 在断开连接之前失败的保活尝试的最大次数
"keepaliveCountMax": 3,
// 建立 SSH 连接的超时时间(毫秒)
"readyTimeout": 20000,
// SSH 连接配置文件
"connections": {
// 注意:这些示例不在默认配置中!
// 示例:本地 Raspberry Pi
"raspberry-pi": {
"host": "raspberrypi.local", // 主机名或 IP 地址
"port": 22, // SSH 端口
"username": "pi", // SSH 用户名
"password": "raspberry", // 密码认证(如果不使用密钥)
"keepaliveInterval": 10000, // 覆盖全局 keepaliveInterval
"keepaliveCountMax": 3, // 覆盖全局 keepaliveCountMax
"readyTimeout": 20000 // 覆盖全局 readyTimeout
},
// 示例:使用密钥认证的远程服务器
"dev-server": {
"host": "dev.example.com",
"port": 22,
"username": "admin",
"privateKeyPath": "C:\\Users\\YourUsername\\.ssh\\id_rsa", // 私钥路径
"keepaliveInterval": 10000,
"keepaliveCountMax": 3,
"readyTimeout": 20000
}
}
}
}
execute_command
shell(字符串):要使用的命令行("powershell"、"cmd" 或 "gitbash")command(字符串):要执行的命令workingDir(可选字符串):工作目录get_command_history
limit(可选数字)ssh_execute
connectionId(字符串):要使用的 SSH 连接的 IDcommand(字符串):要执行的命令ssh_disconnect
connectionId(字符串):要断开的 SSH 连接的 IDcreate_ssh_connection
connectionId(字符串):新 SSH 连接的 IDconnectionConfig(对象):连接配置详情,包括主机、端口、用户名以及密码或 privateKeyPathread_ssh_connections
update_ssh_connection
connectionId(字符串):要更新的 SSH 连接的 IDconnectionConfig(对象):新的连接配置详情delete_ssh_connection
connectionId(字符串):要删除的 SSH 连接的 IDget_current_directory
SSH 连接
ssh://{connectionId}ssh://raspberry-pi 显示 "raspberry-pi" 连接的配置SSH 配置
ssh://config当前目录
cli://currentdirCLI 配置
cli://config以下安全功能是硬编码到服务器中且无法禁用的:
这些安全功能可以通过 config.json 文件进行配置:
blockedCommands 数组中指定的命令被阻止(默认包括危险命令如 rm、del、format)blockedArguments 数组中指定的参数被阻止(默认包括潜在危险标志)enableInjectionProtection: true 激活)restrictWorkingDirectory: true 激活)logCommands: true 激活)这些不是功能,而是重要的安全注意事项:
allowedPaths 以防止访问敏感数据本项目根据