Windows CLI MCP Server

Windows CLI MCP Server

一个模型上下文协议(Model Context Protocol,MCP)服务器,它提供对 Windows 系统的安全命令行访问。该服务器允许像 Claude Desktop 这样的 MCP 客户端,通过可配置的安全控制,安全地在 PowerShell、CMD 和 Git Bash shell 中执行命令。

操作系统自动化
文件系统
开发者工具
本地
JavaScript
访问服务器

Tools

delete_ssh_connection

Delete an existing SSH connection

get_current_directory

Get the current working directory

execute_command

Execute a command in the specified shell (powershell, cmd, or gitbash) Example usage (PowerShell): ```json { "shell": "powershell", "command": "Get-Process | Select-Object -First 5", "workingDir": "C:\Users\username" } ``` Example usage (CMD): ```json { "shell": "cmd", "command": "dir /b", "workingDir": "C:\Projects" } ``` Example usage (Git Bash): ```json { "shell": "gitbash", "command": "ls -la", "workingDir": "/c/Users/username" } ```

get_command_history

Get the history of executed commands Example usage: ```json { "limit": 5 } ``` Example response: ```json [ { "command": "Get-Process", "output": "...", "timestamp": "2024-03-20T10:30:00Z", "exitCode": 0 } ] ```

ssh_execute

Execute a command on a remote host via SSH Example usage: ```json { "connectionId": "raspberry-pi", "command": "uname -a" } ``` Configuration required in config.json: ```json { "ssh": { "enabled": true, "connections": { "raspberry-pi": { "host": "raspberrypi.local", "port": 22, "username": "pi", "password": "raspberry" } } } } ```

ssh_disconnect

Disconnect from an SSH server Example usage: ```json { "connectionId": "raspberry-pi" } ``` Use this to cleanly close SSH connections when they're no longer needed.

create_ssh_connection

Create a new SSH connection

read_ssh_connections

Read all SSH connections

update_ssh_connection

Update an existing SSH connection

README

Windows CLI MCP 服务器

NPM 下载量 NPM 版本 smithery badge

MCP 服务器,用于在 Windows 系统上进行安全的命令行交互,从而能够控制对 PowerShell、CMD、Git Bash shell 以及通过 SSH 连接的远程系统的访问。它允许 MCP 客户端(如 Claude Desktop)在您的系统上执行操作,类似于 Open Interpreter

[!IMPORTANT] 此 MCP 服务器提供对您系统命令行界面以及通过 SSH 连接的远程系统的直接访问。启用后,它将授予对您的文件、环境变量、命令执行功能和远程服务器管理的访问权限。

  • 审查并限制允许的路径和 SSH 连接
  • 启用目录限制
  • 配置命令阻止
  • 考虑安全影响

有关更多详细信息,请参见 配置

特性

  • 多 Shell 支持:在 PowerShell、命令提示符 (CMD) 和 Git Bash 中执行命令
  • SSH 支持:通过 SSH 在远程系统上执行命令
  • 资源暴露:将 SSH 连接、当前目录和配置作为 MCP 资源查看
  • 安全控制
    • 命令和 SSH 命令阻止(完整路径,大小写变体)
    • 工作目录验证
    • 最大命令长度限制
    • 命令日志记录和历史跟踪
    • 智能参数验证
  • 可配置
    • 自定义安全规则
    • Shell 特定的设置
    • SSH 连接配置文件
    • 路径限制
    • 阻止的命令列表

有关服务器提供给 MCP 客户端的工具和资源的更多详细信息,请参见 API 部分。

注意:服务器仅允许在配置的目录中、使用允许的命令以及在配置的 SSH 连接上执行操作。

与 Claude Desktop 一起使用

将以下内容添加到您的 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"
      ]
    }
  }
}

配置完成后,您可以:

  • 使用可用的工具直接执行命令
  • 在“资源”部分中查看配置的 SSH 连接和服务器配置
  • 通过提供的工具管理 SSH 连接

配置

服务器使用 JSON 配置文件来自定义其行为。您可以指定安全控制、shell 配置和 SSH 连接的设置。

  1. 要创建默认配置文件,请执行以下操作之一:

a)config.json.example 复制到 config.json,或者

b) 运行:

npx @simonb97/server-win-cli --init-config ./config.json
  1. 然后设置 --config 标志以指向您的配置文件,如 与 Claude Desktop 一起使用 部分所述。

配置位置

服务器在以下位置查找配置(按顺序):

  1. --config 标志指定的路径
  2. 当前目录中的 ./config.json
  3. 用户主目录中的 ~/.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": ["User's home directory", "Current working directory"],
    "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": {}
  }
}

配置设置

配置文件分为三个主要部分:securityshellsssh

安全设置

{
  "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
  }
}

Shell 配置

{
  "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": {
    // 启用/禁用 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
      }
    }
  }
}

API

工具

  • execute_command

    • 在指定的 shell 中执行命令
    • 输入:
      • shell (string): 要使用的 Shell ("powershell", "cmd", 或 "gitbash")
      • command (string): 要执行的命令
      • workingDir (可选 string): 工作目录
    • 返回命令输出作为文本,如果执行失败,则返回错误消息
  • get_command_history

    • 获取已执行命令的历史记录
    • 输入:limit (可选 number)
    • 返回带有时间戳的命令历史记录和输出
  • ssh_execute

    • 通过 SSH 在远程系统上执行命令
    • 输入:
      • connectionId (string): 要使用的 SSH 连接的 ID
      • command (string): 要执行的命令
    • 返回命令输出作为文本,如果执行失败,则返回错误消息
  • ssh_disconnect

    • 断开与 SSH 服务器的连接
    • 输入:
      • connectionId (string): 要断开连接的 SSH 连接的 ID
    • 返回确认消息
  • create_ssh_connection

    • 创建新的 SSH 连接
    • 输入:
      • connectionId (string): 新 SSH 连接的 ID
      • connectionConfig (object): 连接配置详细信息,包括主机、端口、用户名以及密码或 privateKeyPath
    • 返回确认消息
  • read_ssh_connections

    • 读取所有配置的 SSH 连接
    • 返回配置中所有 SSH 连接的列表
  • update_ssh_connection

    • 更新现有的 SSH 连接
    • 输入:
      • connectionId (string): 要更新的 SSH 连接的 ID
      • connectionConfig (object): 新的连接配置详细信息
    • 返回确认消息
  • delete_ssh_connection

    • 删除 SSH 连接
    • 输入:
      • connectionId (string): 要删除的 SSH 连接的 ID
    • 返回确认消息
  • get_current_directory

    • 获取服务器的当前工作目录
    • 返回当前工作目录路径

资源

  • SSH 连接

    • URI 格式:ssh://{connectionId}
    • 包含连接详细信息,其中敏感信息被屏蔽
    • 每个配置的 SSH 连接一个资源
    • 示例:ssh://raspberry-pi 显示 "raspberry-pi" 连接的配置
  • SSH 配置

    • URI:ssh://config
    • 包含总体 SSH 配置和所有连接(密码已屏蔽)
    • 显示诸如 defaultTimeout、maxConcurrentSessions 和连接列表之类的设置
  • 当前目录

    • URI:cli://currentdir
    • 包含 CLI 服务器的当前工作目录
    • 显示默认情况下将执行命令的路径
  • CLI 配置

    • URI:cli://config
    • 包含 CLI 服务器配置(不包括敏感数据)
    • 显示安全设置、shell 配置和 SSH 设置

安全注意事项

内置安全功能(始终处于活动状态)

以下安全功能已硬编码到服务器中,无法禁用:

  • 不区分大小写的命令阻止:所有命令阻止都不区分大小写(例如,如果 "del" 在 blockedCommands 中,则 "DEL.EXE"、"del.cmd" 等都被阻止)
  • 智能路径解析:服务器解析完整的命令路径以防止绕过尝试(如果 "rm" 被阻止,则阻止 "C:\Windows\System32\rm.exe")
  • 命令解析智能:避免误报(例如,"warm_dir" 不会因为 "rm" 在 blockedCommands 中而被阻止)
  • 输入验证:在执行之前验证所有用户输入
  • Shell 进程管理:在执行或超时后正确终止进程
  • 敏感数据屏蔽:密码在资源中自动屏蔽(替换为 ********)

可配置的安全功能(默认情况下处于活动状态)

这些安全功能可以通过 config.json 文件进行配置:

  • 命令阻止:阻止在 blockedCommands 数组中指定的命令(默认包括危险命令,如 rm、del、format)
  • 参数阻止:阻止在 blockedArguments 数组中指定的参数(默认包括潜在的危险标志)
  • 命令注入保护:防止命令链接(默认情况下通过 enableInjectionProtection: true 启用)
  • 工作目录限制:将命令执行限制为指定的目录(默认情况下通过 restrictWorkingDirectory: true 启用)
  • 命令长度限制:限制最大命令长度(默认值:2000 个字符)
  • 命令超时:终止运行时间过长的命令(默认值:30 秒)
  • 命令日志记录:记录命令历史记录(默认情况下通过 logCommands: true 启用)

重要安全警告

这些不是功能,而是需要注意的重要安全注意事项:

  • 环境访问:命令可能可以访问环境变量,其中可能包含敏感信息
  • 文件系统访问:命令可以在允许的路径内读取/写入文件 - 仔细配置 allowedPaths 以防止访问敏感数据

许可证

此项目已获得 MIT 许可证的许可 - 有关详细信息,请参见 LICENSE 文件。

推荐服务器

Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
Excel MCP Server

Excel MCP Server

一个模型上下文协议服务器,使 AI 助手能够读取和写入 Microsoft Excel 文件,支持诸如 xlsx、xlsm、xltx 和 xltm 等格式。

精选
本地
Go
Playwright MCP Server

Playwright MCP Server

提供一个利用模型上下文协议的服务器,以实现类人浏览器的自动化,该服务器使用 Playwright,允许控制浏览器行为,例如导航、元素交互和滚动。

精选
本地
TypeScript
MCP Package Docs Server

MCP Package Docs Server

促进大型语言模型高效访问和获取 Go、Python 和 NPM 包的结构化文档,通过多语言支持和性能优化来增强软件开发。

精选
本地
TypeScript
Claude Code MCP

Claude Code MCP

一个实现了 Claude Code 作为模型上下文协议(Model Context Protocol, MCP)服务器的方案,它可以通过标准化的 MCP 接口来使用 Claude 的软件工程能力(代码生成、编辑、审查和文件操作)。

精选
本地
JavaScript
@kazuph/mcp-taskmanager

@kazuph/mcp-taskmanager

用于任务管理的模型上下文协议服务器。它允许 Claude Desktop(或任何 MCP 客户端)在基于队列的系统中管理和执行任务。

精选
本地
JavaScript
Apple MCP Server

Apple MCP Server

通过 MCP 协议与 Apple 应用(如“信息”、“备忘录”和“通讯录”)进行交互,从而使用自然语言发送消息、搜索和打开应用内容。

精选
本地
TypeScript
Supabase MCP Server

Supabase MCP Server

一个模型上下文协议(MCP)服务器,它提供对 Supabase 管理 API 的编程访问。该服务器允许 AI 模型和其他客户端通过标准化的接口来管理 Supabase 项目和组织。

精选
JavaScript