mcp-shell
mcp-shell
MCP 服务器,用于运行 shell 命令。你的 LLM 获得一个工具;你则控制运行什么以及如何运行。
基于 mark3labs/mcp-go 构建。使用 Go 编写。
运行它
Docker(最简单):
docker run -it --rm -v /tmp/mcp-workspace:/tmp/mcp-workspace sonirico/mcp-shell:latest从源码构建:
git clone https://github.com/sonirico/mcp-shell && cd mcp-shell
make install
mcp-shellRelated MCP server: MCP Shell Server
配置它
安全模式是默认模式。 在没有配置文件的情况下,mcp-shell 以安全模式启动,仅限于一组狭窄的只读工具白名单(ls、cat、grep、find、head、tail 等)。你只需要一个配置文件来扩大或更改该策略。要完全不受限制地运行,你必须明确选择加入:
MCP_SHELL_ALLOW_UNSAFE=true mcp-shell # disables all validation - do not use in production要自定义策略,请指向一个 YAML 配置:
export MCP_SHELL_SEC_CONFIG_FILE=/path/to/security.yaml
mcp-shell安全模式(推荐)——不进行 shell 解释,仅允许可执行文件白名单:
security:
enabled: true
use_shell_execution: false
allowed_executables:
- ls
- cat
- grep
- find
- echo
# WARNING: never add shell/language interpreters (bash, sh, python, perl,
# ruby, node) or alias-capable tools (git) here - the interpreter executes
# whatever it is handed, bypassing secure mode entirely. mcp-shell warns at
# startup if it finds one.
blocked_patterns: # optional: restrict args on allowed commands
- '(^|\s)remote\s+(-v|--verbose)(\s|$)'
max_execution_time: 30s
max_output_size: 1048576
working_directory: /tmp/mcp-workspace
audit_log: true旧版模式——shell 执行,按命令字符串进行白名单/黑名单(如果不小心,容易受到注入攻击):
security:
enabled: true
use_shell_execution: true
allowed_commands: [ls, cat, grep, echo]
blocked_patterns: ['rm\s+-rf', 'sudo\s+']
max_execution_time: 30s
audit_log: true连接它
Claude Desktop——添加到你的 MCP 配置中:
{
"mcpServers": {
"shell": {
"command": "docker",
"args": ["run", "--rm", "-i", "sonirico/mcp-shell:latest"],
"env": { "MCP_SHELL_LOG_LEVEL": "info" }
}
}
}对于自定义配置,挂载文件并设置环境变量:
{
"command": "docker",
"args": ["run", "--rm", "-i", "-v", "/path/to/security.yaml:/etc/mcp-shell/security.yaml", "-e", "MCP_SHELL_SEC_CONFIG_FILE=/etc/mcp-shell/security.yaml", "sonirico/mcp-shell:latest"]
}工具 API
参数 | 类型 | 描述 |
| string | 要运行的 shell 命令(必需) |
| boolean | 将 stdout/stderr 编码为 base64(默认:false) |
响应包含 status、exit_code、stdout、stderr、command、execution_time 以及可选的 security_info。
环境变量
变量 | 描述 |
| 安全 YAML 的路径(覆盖内置的安全默认值) |
| 设置为 |
| 服务器名称(默认:"mcp-shell 🐚") |
| debug、info、warn、error、fatal |
| json、console |
| stdout、stderr、file |
开发
make install dev-tools # deps + goimports, golines
make fmt test lint
make docker-build # build image locally
make release # binary + docker image安全性
默认:安全模式,仅限于一组狭窄的只读工具白名单。没有解释器。
安全模式(
use_shell_execution: false):命令被解析为 shell AST,并且只接受单个、完全字面量的简单命令(不允许管道、列表、替换、重定向或通配符);其可执行文件必须在白名单中。解释器(bash/sh/python)即使被列入白名单也会被硬性拒绝,并且每个工具的策略默认拒绝:对于受管制的二进制文件(git、find、sort、tar),只接受明确安全的标志,其他所有内容,包括未知或未来的逃生舱标志,都会被拒绝(git -c/config、find -exec/-fls、sort -o/--compress-program、tar -I/-C)。Git 仅限于只读子命令。这是一个早期拒绝层,不是沙箱。不受限制:仅通过
MCP_SHELL_ALLOW_UNSAFE=true。完全访问;适合本地开发,否则很危险。Docker:以非 root 用户运行,基于 Alpine。在生产环境中使用它。最好与操作系统沙箱(只读文件系统、删除能力)配合使用,作为纵深防御。
贡献
Fork、分支、make fmt test,然后提交 PR。
This server cannot be deployed
Maintenance
Related MCP Connectors
Remote MCP server exposing your Node Command fleet (files, shell, processes, browser) to AI hosts.
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
Remote MCP server for supportsheep: run AI interviews and manage support content for your blog.
MCP server for mandates, delegation, policy-gated execution, credential grants, and audit.
Related MCP Servers
- FlicenseNot gradedqualityNot gradedmaintenanceA secure and pluggable MCP server to run terminal commands on your local machine or cloud server — remotely, safely, and with LLMs or agentic clients.-
- AlicenseBqualityAmaintenanceA secure MCP server for shell operations, terminal management, and process control, enabling AI assistants to safely execute commands and manage interactive sessions.13172 npm6MIT
- AlicenseNot gradedqualityCmaintenanceUniversal MCP server that wraps any CLI tool, enabling AI assistants to run commands via natural language.1MIT
- AlicenseAqualityDmaintenanceAn MCP server that enables AI clients to execute shell, Python, and Node commands on the local machine across platforms.31MIT