Skip to main content
Glama

mcp-shell-sudo

MCP-Server für Linux, geschrieben in Python, der lokale Befehle über argv ausführt, nicht-interaktives sudo über PASSWORD_SUDO unterstützt, eine optionale Befehls-Whitelist über ALLOW_COMMANDS bereitstellt und Dateisystem-Schreibvorgänge mit Bubblewrap auf WORK_DIR beschränken kann.

Requirements

  • Linux.

  • Python 3.11+.

  • uv empfohlen.

  • MCP Python SDK 2.0.0.

  • sudo, wenn erhöhte Befehle ausgeführt werden sollen.

  • bubblewrap, wenn WORK_DIR konfiguriert ist.

Auf Debian/Ubuntu:

sudo apt update
sudo apt install -y bubblewrap

Related MCP server: mcp-shell

Environment Variables

PASSWORD_SUDO

Passwort des Benutzers, der den MCP-Server ausführt.

  • Leer oder nicht gesetzt: Der Server erfindet niemals ein Passwort und fragt auch nicht interaktiv danach. Befehle mit dem Präfix sudo werden mit sudo -n ausgeführt und funktionieren nur, wenn bereits eine gültige zwischengespeicherte Anmeldeinformation vorhanden ist oder eine NOPASSWD-Regel konfiguriert ist.

  • Gesetzt: sudo wird mit -S ausgeführt, und das Passwort wird über stdin bereitgestellt, niemals über argv oder Protokolle.

Beispiel:

"PASSWORD_SUDO": "my-password"

Die unterstützte Form ist:

["sudo", "id"]

Benutzerdefinierte sudo-Flags wie sudo -u postgres ... werden nicht akzeptiert. Dadurch muss die Richtlinienebene nicht die vollständige sudo-Befehlsgrammatik interpretieren.

WORK_DIR

Optionales Arbeitsverzeichnis.

  • Leer oder nicht gesetzt: Der MCP-Server kann von jedem vorhandenen Verzeichnis aus arbeiten, das im Tool-Aufruf angegeben ist.

  • Gesetzt: Der Server wechselt in den strikten Modus. directory muss innerhalb von WORK_DIR aufgelöst werden, und jeder Prozess läuft in einem Bubblewrap-Mount-Namespace, in dem / schreibgeschützt ist, WORK_DIR lesend-schreibend eingehängt ist und /tmp und /run temporär sind.

Die alleinige Verwendung von cwd wäre nicht ausreichend, um diese Isolation zu gewährleisten. Ein Prozess könnte weiterhin in /etc, /home/... schreiben oder Symlinks außerhalb des Projekts folgen. Aus diesem Grund startet der Server nicht, wenn WORK_DIR konfiguriert ist, aber bwrap nicht verfügbar ist.

In diesem Modus wird sudo abgelehnt, da eine Rechteausweitung auf Host-Ebene mit der Garantie, dass Dateisystem-Schreibvorgänge auf den Arbeitsbereich beschränkt bleiben, nicht vereinbar wäre.

ALLOW_COMMANDS

Kommagetrennte Liste von ausführbaren Dateinamen.

"ALLOW_COMMANDS": "git,ls,cat,grep,python,node,pnpm"
  • Leer oder nicht gesetzt: Alle ausführbaren Dateien sind erlaubt.

  • Gesetzt: Nur exakte ausführbare Dateinamen aus der Liste sind erlaubt, und sie müssen über ihren Namen aufgerufen werden, nicht über Pfade wie /usr/bin/git.

  • Wenn der Befehl mit sudo beginnt, wird die tatsächliche ausführbare Datei nach sudo validiert.

Die Whitelist gilt für ausführbare Dateien, nicht für Argumente. Das Zulassen von bash, python, node, env oder einem anderen Werkzeug, das Prozesse ausführen kann, erweitert die Möglichkeiten des MCP-Clients erheblich.

Installation

uv sync

Für die Entwicklung:

uv sync --extra dev

Manuelle Ausführung

uv run mcp-shell-sudo

Der Transport ist stdio. Protokollierung wird niemals auf stdout geschrieben, um JSON-RPC-Nachrichten nicht zu beschädigen; Protokolle werden stattdessen auf stderr geschrieben.

MCP-Konfiguration

Beispiel mit uneingeschränkten Befehlen und aktiviertem sudo:

{
  "mcpServers": {
    "shell": {
      "command": "uv",
      "args": [
        "--directory",
        "/ABSOLUTE/PATH/mcp-shell-sudo",
        "run",
        "mcp-shell-sudo"
      ],
      "env": {
        "PASSWORD_SUDO": "YOUR_PASSWORD",
        "WORK_DIR": "",
        "ALLOW_COMMANDS": ""
      }
    }
  }
}

Beispiel beschränkt auf ein bestimmtes Projekt:

{
  "mcpServers": {
    "shell-project": {
      "command": "uv",
      "args": [
        "--directory",
        "/ABSOLUTE/PATH/mcp-shell-sudo",
        "run",
        "mcp-shell-sudo"
      ],
      "env": {
        "PASSWORD_SUDO": "",
        "WORK_DIR": "/home/user/projects/app",
        "ALLOW_COMMANDS": "git,ls,cat,grep,find,python,node,pnpm"
      }
    }
  }
}

shell_execute Tool

Grundlegende Eingabe:

{
  "command": ["ls", "-la"]
}

Mit einem Arbeitsverzeichnis:

{
  "command": ["git", "status"],
  "directory": "backend"
}

Mit stdin:

{
  "command": ["cat"],
  "stdin": "hello\n"
}

Mit sudo:

{
  "command": ["sudo", "id"]
}

Antwort:

{
  "stdout": "uid=0(root) gid=0(root) groups=0(root)\n",
  "stderr": "",
  "status": 0,
  "execution_time": 0.031,
  "timed_out": false,
  "output_limited": false
}

shell_config Tool

Gibt die effektive nicht-geheime Konfiguration zurück.

Es gibt niemals PASSWORD_SUDO zurück; es zeigt nur an, ob ein sudo-Passwort konfiguriert wurde.

Implementierte Sicherheitsmaßnahmen

  • Verwendet create_subprocess_exec; es verwendet nicht shell=True.

  • command wird als explizites argv-Array übergeben.

  • Das sudo-Passwort erscheint niemals in argv, Protokollen oder der Umgebung des Kindprozesses.

  • Wenn PASSWORD_SUDO nicht konfiguriert ist, verhindert sudo -n, dass der Prozess hängt, während er auf eine interaktive Passworteingabe wartet.

  • ALLOW_COMMANDS validiert die tatsächliche ausführbare Datei nach einem einfachen sudo-Aufruf.

  • Verwendet einen festen und reduzierten PATH, um die Auflösung von ausführbaren Dateien aus . oder beliebigen geerbten Pfaden zu vermeiden.

  • Verwendet eine reduzierte Kindumgebung, anstatt die gesamte MCP-Server-Umgebung zu erben.

  • Zeitlimit pro Aufruf: 60 Sekunden standardmäßig, mit einem Maximum von 600 Sekunden.

  • Ausgabelimit: 2 MiB pro Stream. Wenn das Limit überschritten wird, wird die gesamte Prozessgruppe beendet.

  • Prozesse laufen in einer neuen Sitzung, und die gesamte Prozessgruppe wird bei Zeitüberschreitung beendet.

  • WORK_DIR verwendet Bubblewrap und schlägt fehl, wenn die Isolation nicht bereitgestellt werden kann.

Wichtige Einschränkungen

  1. ALLOW_COMMANDS="" bedeutet die Ausführung beliebiger Befehle mit den Berechtigungen des Benutzers, der den MCP-Server ausführt. Wenn PASSWORD_SUDO ebenfalls konfiguriert ist, kann der MCP-Client Aktionen als root anfordern. Verwenden Sie diese Konfiguration nur mit einem Client und Modell, den Sie kontrollieren.

  2. Eine Whitelist für ausführbare Dateien validiert Befehlsparameter nicht semantisch. python, node, bash, sh, perl und ähnliche Werkzeuge sind praktisch gleichbedeutend mit der Erlaubnis beliebiger Codeausführung.

  3. WORK_DIR beschränkt die beschreibbaren Dateisystempfade, ist aber nicht als VM- oder Netzwerk-Sandbox gedacht. Ein Befehl mit Netzwerkzugriff kann weiterhin entfernte Ressourcen ändern, für die er gültige Anmeldeinformationen besitzt.

  4. PASSWORD_SUDO, das in der MCP-Client-Konfiguration gespeichert ist, bleibt ein Geheimnis in dieser Datei. Beschränken Sie die Dateiberechtigungen mit chmod 600 und committen Sie es niemals in die Versionskontrolle.

Tests

uv run --extra dev pytest
uv run --extra dev ruff check .

Available Tools

2 tools
shell_configA

Return the effective non-secret shell policy configuration.

NameRequiredDescriptionDefault

No parameters

Output Schema

NameRequiredDescription

No output parameters

TDQS

A3.5/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description serves as the only behavioral disclosure. It implies a read-only operation ('Return') but does not explicitly state that it has no side effects or that it is safe. It does clarify that secrets are excluded, which is a useful constraint. However, it does not mention any authentication or permission requirements, which could be relevant.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, concise sentence that front-loads the action ('Return') and specifies the resource. There is no wasted verbiage.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given that there are no parameters, the description sufficiently conveys the tool's function. The existence of an output schema covers return details, so the description need not elaborate. It does not mention usage context, but that is already addressed in usage_guidelines; for a simple config retrieval, this is complete enough.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

There are zero parameters, so the description is not required to explain parameter syntax. The phrase 'non-secret' adds context about the output scope but does not relate to parameters. For a parameterless tool, this is adequate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb ('Return') and a clear resource ('effective non-secret shell policy configuration'). It distinguishes itself from the sibling tool by nature (configuration retrieval vs. execution), though it does not explicitly name the alternative. The purpose is unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is given for when to use this tool versus the sibling shell_execute. An agent must infer that this is for reading configuration, not executing commands. The description does not mention any prerequisites, alternatives, or context for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

shell_executeA

Execute one command as an argv array.

Args: command: Executable and arguments, for example ["ls", "-la"] or ["sudo", "systemctl", "status", "ssh"]. Shell syntax is not interpreted. stdin: Optional text sent to the command's standard input. directory: Optional working directory. With WORK_DIR configured, this path must resolve inside WORK_DIR. Without WORK_DIR, any existing directory may be used. timeout: Execution timeout in seconds. Values above 600 seconds are capped at 600.

Returns: stdout, stderr, exit status, execution time, timeout flag, and output-limit flag.

NameRequiredDescriptionDefault
stdinNo
commandYes
timeoutNo
directoryNo

Output Schema

NameRequiredDescription

No output parameters

TDQS

A4.2/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of disclosing behavioral traits. It mentions that shell syntax is not interpreted, that the timeout is capped at 600 seconds, and that directory paths must resolve inside WORK_DIR if configured. However, it does not warn about the potentially destructive nature of executing arbitrary commands or the side effects of the executed process, which is a notable omission for a command execution tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is structured with a clear one-line summary, a detailed 'Args' section, and a 'Returns' section. It is appropriately detailed for a tool with multiple parameters but remains readable. The example for the command parameter adds clarity without bloat.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers the essential invocation details: command format, directory constraints, timeout cap, and the return fields (stdout, stderr, exit status, etc.). It does not explain prerequisites such as the meaning of WORK_DIR, but this is likely a global configuration rather than tool-specific. Given the presence of an output schema (though not shown), the return-field listing is sufficient. Overall, it provides enough for an agent to call the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema provides no descriptions for any of the four parameters (schema coverage 0%), so the description must fully compensate. It does so thoroughly by explaining each parameter: the command array with examples, optional stdin, directory restrictions relative to WORK_DIR, and timeout cap. This adds substantial meaning beyond the schema's type definitions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb and resource: 'Execute one command as an argv array.' It clearly distinguishes from the sibling tool 'shell_config' by implying execution vs. configuration, and provides a concrete example to clarify the argv format.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It provides clear guidance on how to invoke the tool, including the requirement to pass an argv array rather than shell syntax, and clarifies timeout and directory constraints. However, it does not explicitly state when to prefer this tool over shell_config, though the purpose difference is evident from the name and description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 2 tool updatesv0.1.0
    • First observedshell_config
    • First observedshell_execute

TDQS

A3.9/5.0

Scored across 2 tools

Disambiguation5/5

The two tools have completely distinct purposes: one executes commands and the other returns configuration. There is no overlap or potential for misselection between them.

Naming Consistency5/5

Both tools follow the same snake_case verb_noun pattern (shell_execute, shell_config). The naming is clear, predictable, and consistent.

Tool Count3/5

With only two tools, this server feels thin, but the narrow scope (shell execution and configuration) justifies the limited surface. It is at the lower edge of what is reasonable, as stated in the calibration.

Completeness4/5

The tool surface covers the core functionality of executing shell commands and retrieving configuration. There is no obvious missing operation for the stated purpose; the only minor gap might be a way to list allowed commands or test, but that is not essential.

Maintenance

ActivityStale
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides a secure, token-authenticated command execution tool over MCP Streamable HTTP, with a default-deny allowlist and shell metacharacter rejection.
    11 npm
    1
    Apache 2.0