一个强大的模型上下文协议(MCP)服务器,提供安全的shell命令执行能力给AI助手和其他MCP客户端。换句话说:大脑思考,这个工具执行命令。
🧠💥🖥️ 将
mcp-shell视为您的大语言模型的命令行执行器。 当语言模型在推理世界时,mcp-shell就是让它们接触现实的东西。
此工具通过标准化的MCP协议,在AI系统与您的shell环境之间建立桥梁。它将系统shell暴露为一个结构化的工具,支持自主工作流、工具辅助推理和解决实际问题。
基于官方的Go语言MCP SDK构建:mark3labs/mcp-go。
用Go编写,直接集成mcp-go,提供从想法到执行的清晰路径。我知道存在类似的项目——这个是我的。它以我想要的方式解决问题:最小化、可组合、可审计。
开箱即用,它通过Docker运行隔离,但这只是一个开始。路线图包括对可选监禁机制的支持,如chroot、命名空间和系统调用级别的限制——无需依赖Docker做一切。
git clone https://github.com/sonirico/mcp-shell
cd mcp-shell
make install
# 使用默认配置运行(如果全局安装)
mcp-shell
# 或者本地运行
make run
# 启用安全运行(创建临时配置)
make run-secure
# 使用自定义配置文件运行
MCP_SHELL_SEC_CONFIG_FILE=security.json mcp-shell
# 使用环境变量覆盖运行
MCP_SHELL_LOG_LEVEL=debug mcp-shell
# 构建Docker镜像
make docker-build
# 在安全容器中运行
make docker-run-secure
# 为调试运行带shell访问权限
make docker-shell
通过环境变量进行基本服务和日志配置:
MCP_SHELL_SERVER_NAME:服务器名称(默认:"mcp-shell 🐚")MCP_SHELL_VERSION:服务器版本(编译时设置)MCP_SHELL_LOG_LEVEL:日志级别(debug、info、warn、error、fatal)MCP_S_HELL_LOG_FORMAT:日志格式(json、console)MCP_SHELL_LOG_OUTPUT:日志输出(stdout、stderr、file)MCP_SHELL_SEC_CONFIG_FILE:YAML配置文件路径安全设置仅通过YAML配置文件进行配置:
export MCP_SHELL_SEC_CONFIG_FILE=security.yaml
示例安全配置文件:
security:
enabled: true
allowed_commands:
- ls
- cat
- grep
- find
- echo
blocked_commands:
- rm -rf
- sudo
- chmod
blocked_patterns:
- 'rm\s+.*-rf.*'
- 'sudo\s+.*'
max_execution_time: 30s
working_directory: /tmp/mcp-workspace
max_output_size: 1048576
audit_log: true
command(字符串,必需):要执行的shell命令base64(布尔值,可选):返回标准输出/标准错误作为Base64编码的字符串{
"status": "success|error",
"exit_code": 0,
"stdout": "命令输出",
"stderr": "错误输出",
"command": "执行的命令",
"execution_time": "100ms",
"security_info": {
"security_enabled": true,
"working_dir": "/tmp/mcp-workspace",
"timeout_applied": true
}
}
{
"mcpServers": {
"shell": {
"command": "docker",
"args": ["run", "--rm", "-i", "mcp-shell:latest"],
"env": {
"MCP_SHELL_SECURITY_ENABLED": "true",
"MCP_SHELL_LOG_LEVEL": "info"
}
}
}
}
# 构建并安装
make build
sudo make install-bin
# 设置环境变量进行基本配置
export MCP_SHELL_LOG_LEVEL=info
export MCP_SHELL_LOG_FORMAT=json
export MCP_SHELL_SEC_CONFIG_FILE=/etc/mcp-shell/config.json
# 安全配置仅在JSON文件中进行
# 运行服务
mcp-shell
# 安装依赖和开发工具
make install dev-tools
# 格式化代码
make fmt
# 运行测试
make test
# 运行linter
make lint
# 为发布构建
make release
# 生成配置示例
make config-example
创建security.yaml:
security:
enabled: true
allowed_commands:
- ls
- cat
- head
- tail
- grep
- find
- wc
- sort
- uniq
blocked_patterns:
- 'rm\s+.*-rf.*'
- 'sudo\s+.*'
- 'chmod\s+(777|666)'
- '>/dev/'
- 'curl.*\|.*sh'
max_execution_time: 10s
working_directory: /tmp/mcp-workspace
max_output_size: 524288
audit_log: true
设置环境:
export MCP_SHELL_SEC_CONFIG_FILE=security.yaml
export MCP_SHELL_LOG_LEVEL=info
export MCP_SHELL_LOG_FORMAT=json
git checkout -b feature/amazing-feature)git commit -m '添加惊人的功能')git push origin feature/amazing-feature)确保代码已格式化(make fmt)并通过测试(make test)。
MIT许可证 - 查看LICENSE文件获取详情。