WSL Exec MCP server

Provides secure command execution in WSL with built-in safety features like path validation, timeouts, and error handling.
Back to servers
Provider
Scott Spence
Release date
Jan 23, 2025
Language
TypeScript
Package
Stats
317 downloads
9 stars

This MCP server allows you to securely execute commands in Windows Subsystem for Linux (WSL) environments through the Model Context Protocol. It provides comprehensive safety features including dangerous command detection, command confirmation systems, and protection against shell injection.

Installation

You can easily install and use the MCP-WSL-Exec server through the NPX package runner. No separate installation is required as the configuration uses NPX to run the server on demand.

Configuration

Cline Configuration

Add this to your Cline MCP settings:

{
    "mcpServers": {
        "mcp-wsl-exec": {
            "command": "npx",
            "args": ["-y", "mcp-wsl-exec"]
        }
    }
}

Claude Desktop Configuration

Add this to your Claude Desktop configuration:

{
    "mcpServers": {
        "mcp-wsl-exec": {
            "command": "npx",
            "args": ["-y", "mcp-wsl-exec"]
        }
    }
}

Using the Server

The MCP-WSL-Exec server provides two main tools for command execution:

execute_command

This tool allows you to execute commands in WSL with built-in safety checks.

Parameters:

  • command (string, required): The command you want to execute
  • working_dir (string, optional): Working directory for command execution
  • timeout (number, optional): Timeout in milliseconds

Example usage:

// Basic command execution
execute_command({ command: "ls -la" })

// With working directory
execute_command({ command: "ls -la", working_dir: "/home/user/projects" })

// With timeout
execute_command({ command: "sleep 10", timeout: 5000 })

confirm_command

If a command is flagged as potentially dangerous, you'll need to use this tool to confirm execution.

Parameters:

  • confirmation_id (string, required): Confirmation ID received from execute_command
  • confirm (boolean, required): Whether to proceed with the command execution

Example usage:

// Confirm a dangerous command
confirm_command({ confirmation_id: "abc123", confirm: true })

// Reject a dangerous command
confirm_command({ confirmation_id: "abc123", confirm: false })

Safety Features

Dangerous Command Detection

The server automatically flags potentially dangerous commands that require explicit confirmation, including:

  • File system operations (rm, rmdir, mv)
  • System commands (shutdown, reboot)
  • Package management (apt, yum, dnf)
  • File redirections (>, >>)
  • Permission changes (chmod, chown)

Command Sanitization

All commands undergo sanitization to prevent:

  • Shell metacharacter injection
  • Path traversal attempts
  • Home directory references
  • Dangerous command chaining

Additional Safety Measures

  • Working Directory Control: Execute commands in specific directories
  • Command Timeout: Set timeouts to prevent long-running commands
  • Detailed Output Formatting: Clear output with proper error messages
  • Error Handling: Robust validation and error reporting

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