[!CAUTION] 项目已弃用 - 不再维护。 请使用 https://github.com/wonderwhy-er/DesktopCommanderMCP 以获得类似功能。
MCP 服务器 用于在 Windows 系统上进行安全的命令行交互,允许通过 PowerShell、CMD、Git Bash 以及通过 SSH 远程系统进行受控访问。它允许 MCP 客户端(如 Claude Desktop)在您的系统上执行操作,类似于 Open Interpreter。
[!IMPORTANT] 此 MCP 服务器提供对系统命令行界面和通过 SSH 访问远程系统的直接访问。启用后,它将授予对您的文件、环境变量、命令执行能力和远程服务器管理的访问权限。
- 审查并限制允许的路径和 SSH 连接
- 启用目录限制
- 配置命令块
- 考虑安全影响
更多详情请参见 配置。
有关服务器提供给 MCP 客户端的工具和资源的更多详情,请参见 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 配置文件来自定义其行为。您可以配置安全控制、Shell 配置和 SSH 连接的设置。
a) 将 config.json.example
复制为 config.json
,或
b) 运行:
npx @simonb97/server-win-cli --init-config ./config.json
--config
标志以指向您的配置文件。服务器在以下位置查找配置(按顺序):
--config
标志指定的路径如果未找到配置文件,服务器将使用默认(受限)配置:
注意:默认配置设计为严格且安全。有关每个设置的更多详情,请参见 配置设置 部分。
{
"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", // 在某些 shell 中执行命令
"-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": {
// 启用/禁用此 shell
"enabled": true,
// Shell 可执行文件的路径
"command": "powershell.exe",
// Shell 的默认参数
"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,
// 发送 keepalive 数据包的间隔时间(毫秒)
"keepaliveInterval": 10000,
// 断开连接前的最大 keepalive 失败尝试次数
"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
(字符串):使用的 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
(对象):连接配置详细信息,包括主机、端口、用户名以及密码或私钥路径read_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://currentdir
CLI 配置
cli://config
以下安全功能已硬编码到服务器中,无法禁用:
这些安全功能可以通过 config.json 文件进行配置:
blockedCommands
数组中指定的命令会被阻止(默认包括 rm、del、format 等危险命令)blockedArguments
数组中指定的参数会被阻止(默认包括潜在危险的标志)enableInjectionProtection: true
启用)restrictWorkingDirectory: true
启用)logCommands: true
启用)这些不是功能,但需要注意的重要安全考虑:
allowedPaths
以防止访问敏感数据本项目根据 MIT 许可证授权 - 详情请参阅 LICENSE 文件。