Windows CLI MCP server

Control Windows command-line interfaces securely.
Back to servers
Provider
Simon B
Release date
Dec 04, 2024
Language
TypeScript
Package
Stats
5.1K downloads
170 stars

This MCP server enables secure command-line interactions on Windows systems, providing controlled access to PowerShell, CMD, Git Bash shells, and remote systems via SSH. It allows MCP clients like Claude Desktop to perform operations on your system with configurable security restrictions.

Installation

Using with Claude Desktop

To configure Claude Desktop to use this MCP server, add the following to your claude_desktop_config.json:

{
  "mcpServers": {
    "windows-cli": {
      "command": "npx",
      "args": ["-y", "@simonb97/server-win-cli"]
    }
  }
}

To use a specific configuration file, include the --config flag:

{
  "mcpServers": {
    "windows-cli": {
      "command": "npx",
      "args": [
        "-y",
        "@simonb97/server-win-cli",
        "--config",
        "path/to/your/config.json"
      ]
    }
  }
}

Configuration

The server uses a JSON configuration file to customize its behavior. You can specify settings for security controls, shell configurations, and SSH connections.

Creating a Configuration File

Create a default configuration file using one of these methods:

  1. Run this command to initialize a config file:
npx @simonb97/server-win-cli --init-config ./config.json
  1. After creating your configuration, specify it with the --config flag as shown in the installation section.

Configuration Locations

The server looks for configuration in the following locations (in order):

  1. Path specified by --config flag
  2. ./config.json in current directory
  3. ~/.win-cli-mcp/config.json in user's home directory

If no configuration file is found, the server will use a default (restrictive) configuration.

Configuration Settings

The configuration file is divided into three main sections:

Security Settings

{
  "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": ["C:\\Users\\YourUsername", "C:\\Projects"],
    "restrictWorkingDirectory": true,
    "logCommands": true,
    "maxHistorySize": 1000,
    "commandTimeout": 30,
    "enableInjectionProtection": true
  }
}

Shell Configuration

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

{
  "ssh": {
    "enabled": false,
    "defaultTimeout": 30,
    "maxConcurrentSessions": 5,
    "keepaliveInterval": 10000,
    "keepaliveCountMax": 3,
    "readyTimeout": 20000,
    "connections": {
      "raspberry-pi": {
        "host": "raspberrypi.local",
        "port": 22,
        "username": "pi",
        "password": "raspberry"
      },
      "dev-server": {
        "host": "dev.example.com",
        "port": 22,
        "username": "admin",
        "privateKeyPath": "C:\\Users\\YourUsername\\.ssh\\id_rsa"
      }
    }
  }
}

Usage

Once configured, you can use the MCP server through Claude Desktop or other MCP clients. The server provides the following tools and resources:

Available Tools

Basic Command Execution

Execute commands in different shells:

  • execute_command: Run commands in PowerShell, CMD, or Git Bash
    • Parameters: shell (powershell/cmd/gitbash), command, optional workingDir
// Example using execute_command
execute_command("powershell", "Get-Process", "C:\\Users\\username\\Documents")

Command History

  • get_command_history: Retrieve previously executed commands
    • Parameters: optional limit (number of commands to return)

SSH Management

  • ssh_execute: Run commands on remote systems via SSH
    • Parameters: connectionId, command
  • ssh_disconnect: Disconnect from an SSH server
    • Parameters: connectionId
  • create_ssh_connection: Set up a new SSH connection
    • Parameters: connectionId, connectionConfig object
  • read_ssh_connections: Get all configured SSH connections
  • update_ssh_connection: Modify an existing SSH connection
    • Parameters: connectionId, connectionConfig object
  • delete_ssh_connection: Remove an SSH connection
    • Parameters: connectionId

Directory Management

  • get_current_directory: Get the server's current working directory

Available Resources

The server provides access to the following resources:

  • SSH Connections: ssh://{connectionId} - Shows details for specific SSH connections
  • SSH Configuration: ssh://config - Shows overall SSH configuration
  • Current Directory: cli://currentdir - Shows current working directory
  • CLI Configuration: cli://config - Shows server configuration

Security Considerations

The server implements multiple security measures:

  • Case-insensitive command blocking
  • Working directory restrictions
  • Command length limits and timeouts
  • Command injection protection
  • Blocked commands and arguments
  • Command logging and history tracking

Always review your configuration to ensure:

  • Allowed paths are limited to necessary directories
  • Dangerous commands are blocked
  • SSH connections only have necessary privileges
  • Command injection protection is enabled

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later