Secure Shell Executor

by diegofornalha

Not rated
GitHub

About

Provides a secure way to execute shell commands with robust validation, whitelisting, and timeout handling through an asyncio-powered Python implementation.

Details

Author
diegofornalha
Repository
diegofornalha/mcp-shell-server
Categories
Productivity, Design, Developer Tools, AI, Security, Automation, Frontend, API

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Secure Shell Executor
    Command (node, npx, python, etc.) uv
    Arguments
    • Argument 1 --directory
    • Argument 2 .
    • Argument 3 run
    • Argument 4 mcp-shell-server
    Environment
    • ALLOW_COMMANDS ls,cat,pwd,grep,wc,touch,find

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

code ~/Library/Application\ Support/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "shell": {
      "command": "uv",
      "args": [
        "--directory",
        ".",
        "run",
        "mcp-shell-server"
      ],
      "env": {
        "ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
      }
    },
  }
}

1. Clone o repositório

git clone https://github.com/yourusername/mcp-shell-server.git
cd mcp-shell-server

2. Instale dependências incluindo requisitos de teste

pip install -e ".[test]"

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "secure shell executor": {
            "env": {
                "ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
            },
            "args": [
                "--directory",
                ".",
                "run",
                "mcp-shell-server"
            ],
            "command": "uv"
        }
    }
}

Linux

{
    "env": {
        "ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
    },
    "args": [
        "--directory",
        ".",
        "run",
        "mcp-shell-server"
    ],
    "command": "uv"
}

Macos

{
    "env": {
        "ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
    },
    "args": [
        "--directory",
        ".",
        "run",
        "mcp-shell-server"
    ],
    "command": "uv"
}

Windows

{
    "env": {
        "ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
    },
    "args": [
        "/c",
        "uv",
        "--directory",
        ".",
        "run",
        "mcp-shell-server"
    ],
    "command": "cmd"
}

MCP Shell Server

codecov
smithery badge

Um servidor seguro para execução de comandos shell que implementa o Protocolo de Contexto de Modelo (MCP). Este servidor permite a execução remota de comandos shell autorizados com suporte para entrada via stdin.

Funcionalidades

Execução Segura de Comandos: Apenas comandos autorizados podem ser executados
Suporte para Entrada Padrão: Passa entrada para comandos via stdin
Saída Abrangente: Retorna stdout, stderr, código de saída e tempo de execução
Segurança com Operadores Shell: Valida comandos após operadores shell (;, &&, ||, |)
Controle de Timeout: Define tempo máximo de execução para comandos

Configuração do cliente MCP no seu Claude.app

Versão publicada

code ~/Library/Application\ Support/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "shell": {
      "command": "uvx",
      "args": [
        "mcp-shell-server"
      ],
      "env": {
        "ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
      }
    },
  }
}

Versão local

Configuração

code ~/Library/Application\ Support/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "shell": {
      "command": "uv",
      "args": [
        "--directory",
        ".",
        "run",
        "mcp-shell-server"
      ],
      "env": {
        "ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
      }
    },
  }
}

Instalação

pip install mcp-shell-server

Uso

Iniciando o Servidor

ALLOW_COMMANDS="ls,cat,echo" uvx mcp-shell-server

Ou usando o alias

ALLOWED_COMMANDS="ls,cat,echo" uvx mcp-shell-server

A variável de ambiente ALLOW_COMMANDS (ou seu alias ALLOWED_COMMANDS) especifica quais comandos podem ser executados. Comandos podem ser separados por vírgulas com espaços opcionais ao redor deles.

Formatos válidos para ALLOW_COMMANDS ou ALLOWED_COMMANDS:

ALLOW_COMMANDS="ls,cat,echo"          # Formato básico
ALLOWED_COMMANDS="ls ,echo, cat"      # Com espaços (usando alias)
ALLOW_COMMANDS="ls,  cat  , echo"     # Múltiplos espaços

Formato da Requisição

# Execução básica de comando
{
    "command": ["ls", "-l", "/tmp"]
}

Comando com entrada stdin

{ "command": ["cat"], "stdin": "Hello, World!" }

Comando com timeout

{ "command": ["long-running-process"], "timeout": 30 # Tempo máximo de execução em segundos }

Comando com diretório de trabalho e timeout

{ "command": ["grep", "-r", "pattern"], "directory": "/path/to/search", "timeout": 60 }

Formato da Resposta

Resposta de sucesso:

{
    "stdout": "saída do comando",
    "stderr": "",
    "status": 0,
    "execution_time": 0.123
}

Resposta de erro:

{
    "error": "Comando não permitido: rm",
    "status": 1,
    "stdout": "",
    "stderr": "Comando não permitido: rm",
    "execution_time": 0
}

Segurança

O servidor implementa várias medidas de segurança:

1. Lista Branca de Comandos: Apenas comandos explicitamente permitidos podem ser executados
2. Validação de Operadores Shell: Comandos após operadores shell (;, &&, ||, |) também são validados contra a lista branca
3. Sem Injeção de Shell: Comandos são executados diretamente sem interpretação do shell

Desenvolvimento

Configurando o Ambiente de Desenvolvimento

1. Clone o repositório

git clone https://github.com/yourusername/mcp-shell-server.git
cd mcp-shell-server

2. Instale dependências incluindo requisitos de teste

pip install -e ".[test]"

Executando Testes

pytest

Referência da API

Argumentos da Requisição

| Campo | Tipo | Obrigatório | Descrição |
|-----------|------------|-------------|----------------------------------------------|
| command | string[] | Sim | Comando e seus argumentos como elementos de array |
| stdin | string | Não | Entrada a ser passada para o comando |
| directory | string | Não | Diretório de trabalho para execução do comando |
| timeout | integer | Não | Tempo máximo de execução em segundos |

Campos da Resposta

| Campo | Tipo | Descrição |
|----------------|---------|---------------------------------------------|
| stdout | string | Saída padrão do comando |
| stderr | string | Saída de erro do comando |
| status | integer | Código de status de saída |
| execution_time | float | Tempo gasto para executar (em segundos) |
| error | string | Mensagem de erro (presente apenas se falhou) |

Requisitos

Python 3.11 ou superior

  • mcp>=1.1.0


Licença

Licença MIT - Veja o arquivo LICENSE para detalhes

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.