
Shell MCP Server

2024.12.12
2
Pythonshell 命令执行LLM 工具开发效率
mcp-server-shell 是一个基于 Model Context Protocol 的服务,提供 shell 命令执行能力。该服务允许 LLMs(大型语言模型)以受控的方式执行 shell 命令并获取输出。
View on GitHub
Overview
基本能力
产品定位
mcp-server-shell 是一个专门为 LLMs 设计的 shell 命令执行服务,旨在提供安全的 shell 命令执行能力。
核心功能
- 提供
execute_command
工具,用于执行 shell 命令并返回输出 - 参数:
command
(string): 要执行的 shell 命令
- 返回:
command
: 执行的命令output
: 合并的 stdout 和 stderr 输出return_code
: 命令执行的返回码
适用场景
- 在 LLMs 中执行 shell 命令
- 获取系统信息(如文件列表、系统日期等)
- 检查软件安装状态
工具列表
execute_command
: 执行 shell 命令并返回输出
常见问题解答
- 安全性问题: 该服务直接执行系统 shell 命令,使用时需谨慎,防止未授权或危险命令的执行
使用教程
使用依赖
- 推荐使用
uv
工具链 - 或使用 Python 环境
安装教程
使用 uv (推荐)
无需单独安装,直接使用 uvx
运行:
uvx mcp-server-shell
使用 PIP
pip install mcp-server-shell
安装后运行:
python -m mcp_server_shell
配置
为 Claude.app 配置
使用 uvx:
"mcpServers": {
"shell": {
"command": "uvx",
"args": ["mcp-server-shell"]
}
}
使用 pip 安装:
"mcpServers": {
"shell": {
"command": "python",
"args": ["-m", "mcp_server_shell"]
}
}
为 Zed 配置
使用 uvx:
"context_servers": {
"mcp-server-shell": {
"command": "uvx",
"args": ["mcp-server-shell"]
}
},
使用 pip 安装:
"context_servers": {
"mcp-server-shell": {
"command": "python",
"args": ["-m", "mcp_server_shell"]
}
},
调试方式
使用 MCP inspector 调试:
npx @modelcontextprotocol/inspector uvx mcp-server-shell
或针对特定目录:
cd path/to/servers/src/shell
npx @modelcontextprotocol/inspector uv run mcp-server-shell
示例交互
执行 shell 命令:
{
"name": "execute_command",
"arguments": {
"command": "ls -la"
}
}
响应:
{
"command": "ls -la",
"output": "total 24\ndrwxr-xr-x 5 user group 160 Jan 1 12:00 .\ndrwxr-xr-x 3 user group 96 Jan 1 12:00 ..",
"return_code": 0
}