
Shell MCP Server

2024.12.27
0
Pythonshell 命令执行系统交互开发效率
Shell MCP Server 是一个提供 shell 命令执行能力的 Model Context Protocol 服务器。它允许 LLMs(大型语言模型)以受控的方式执行 shell 命令并获取输出。该服务器主要用于通过 shell 命令与系统交互,适用于需要自动化执行 shell 命令的场景。
View on GitHub
Overview
基本能力
产品定位
Shell MCP Server 是一个用于执行 shell 命令的 MCP 服务器,旨在为 LLMs 提供与系统交互的能力。
核心功能
- 提供
execute_command
工具,用于执行 shell 命令并返回输出。 - 参数:
command
(string): 要执行的 shell 命令
- 返回:
command
: 执行的命令output
: 标准输出和标准错误的组合return_code
: 命令执行的返回码
适用场景
- 自动化执行 shell 命令
- 系统管理和维护
- 开发环境中的任务自动化
工具列表
execute_command
: 执行 shell 命令并返回输出
常见问题解答
- 安全性问题: 该服务器直接执行 shell 命令,需谨慎使用以防止未授权或危险命令的执行。
使用教程
使用依赖
- 推荐使用
uv
工具链,无需额外安装。 - 也可以使用
pip
进行安装。
安装教程
使用 uv (推荐)
无需安装,直接使用 uvx
运行:
uvx mcp-server-shell
使用 PIP
pip install mcp-server-shell
运行服务器:
python -m mcp_server_shell
配置
配置 Claude.app
"mcpServers": {
"shell": {
"command": "uvx",
"args": ["mcp-server-shell"]
}
}
或使用 pip 安装:
"mcpServers": {
"shell": {
"command": "python",
"args": ["-m", "mcp_server_shell"]
}
}
配置 Zed
"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
}
示例问题
- "What files are in the current directory?"
- "Show me the contents of the README.md file"
- "What's the current system date?"
- "Check if Python is installed and show its version"