mcp-shell-server is an MCP server developed by tumf, designed to execute shell commands in a controlled manner and implement the Model Context Protocol. Its core purpose is to allow MCP clients to run commands within an explicitly configured command allowlist, while reducing risk through multiple server-side mechanisms.
Main capabilities
- argv-based command execution: Allowed commands are run through a subprocess argv array, without shell string interpretation.
- Standard input support: Input can be passed to commands via stdin.
- Full output: Returns stdout, stderr, exit status, and execution time.
- Safe pipelines: Pipelines preserve and validate each argv segment without invoking a shell.
- Execution limits: Enforces server-side default timeout, maximum timeout, and output byte limits. MCP_SHELL_DEFAULT_TIMEOUT_SECONDS defaults to 30 seconds, MCP_SHELL_MAX_TIMEOUT_SECONDS defaults to 300 seconds, and MCP_SHELL_OUTPUT_LIMIT_BYTES defaults to 1 MiB per stdout/stderr stream.
- Controlled redirection: The targets of <, >, and >> must remain within the requested working directory; absolute paths, .. traversal, and symlink escapes are rejected before opening files.
- Minimal child environment: Child processes receive only a small allowlisted environment, rather than inheriting all server secrets. By default, it includes only the POSIX PATH, as well as the applicable Windows startup keys (COMSPEC, PATHEXT, SYSTEMROOT, WINDIR). Additional environment variable names can be explicitly allowed via MCP_SHELL_CHILD_ENV_ALLOWLIST, comma-separated, with exact matching.
- Structured audit logging: Each invocation emits an mcp-shell-server.audit event named shell_execution_audit, covering success, validation rejection, timeout, output limit exceeded, and process errors. Audit metadata includes timestamp, duration, result type, command name, redacted argv, resolved working directory, redirection flags, redacted per-invocation environment override metadata, effective timeout and output limits, stdout_bytes, stderr_bytes, return code when available, and rejection reason or error type. Audit dayLogs do not include the raw stdout/stderr body; argv or environment names/values resembling SECRET, TOKEN, PASSWORD, PASSWD, API_KEY, ACCESS_KEY, PRIVATE_KEY, KEY, CREDENTIAL, AUTH are replaced with [REDACTED], and longer non-numeric values are represented by a short SHA-256 digest.
Usage The server specifies the allowed command names to execute via the environment variable ALLOW_COMMANDS (or its alias ALLOWED_COMMANDS), and multiple commands can be separated by commas. ALLOW_PATTERNS can be used for comma-separated regular expressions that fully match command names; for example, ALLOW_PATTERNS="ls" allows only the command name ls, and does not allow lsof or ls -la. Patterns and command names containing whitespace or shell metacharacters are rejected. A tool call may include the command argv, an optional directory, optional standard input, an optional timeout, and optional per-call environment overrides. The directory parameter is optional; when omitted, the command runs in the MCP server process's current working directory, and a relative directory is also resolved based on that server process CWD, not the MCP client's CWD.
Default argument hardening (best-effort defense in depth) Even if a command name is on the allowlist, the server rejects known executable vectors, such as shell/interpreter launchers, env, xargs, find -exec, awk system(), tar --checkpoint-action=exec, GNU sort's --compress-program, -o/--output, --files0-from, -T/--temporary-directory (including abbreviations and combined forms), as well as Git external program options and all global git -c <name=value> or git -c<name=value> configuration overrides. This hardening is not exhaustive and is not a substitute for external isolation.
Use cases Suitable for controlled environments where AI or automated processes need to execute commands within an explicit allowlist, while also requiring stdin input, pipelines, timeouts, output limits, and audit logs.
Limitations and security contract This package is not a sandbox. Allowing one command delegates the server process's existing operating system permissions: theallowed program can, according to its own logic, read accessible files, consume CPU, spawn child processes, or access the network. The command-name allowlist and patterns only restrict the names of executables that the server directly starts; they do not guarantee coverage of descendant processes spawned by the allowed program, program-specific interpreter/expression languages/plugins, configuration files or dotfiles it reads on its own, filesystem reads and writes it performs outside server-managed redirection, or network access it initiates on its own. Command-specific deny rules are best-effort defense in depth against known dangerous argument forms, are not exhaustive, and do not prove that an allowed program is safe. If any request or server-accessible file may originate from untrusted input (model-provided text, scraped web pages, issue text, repository contents, etc.), the server should be run within an independently enforced operating system boundary, providing a least-privilege identity, filesystem scope, network restrictions, credential exclusion, descendant process containment, and external resource limits.
Development and license Requires Python 3.11 or later and is licensed under the MIT License. For installation, the documentation provides instructions for automatic installation for Claude Desktop via Smithery as well as manual installation, and gives guidance for configuring the MCP client in Claude.app, but the specific command contents are not expanded in this document.