
MCP Bash

Overview
基本能力
产品定位
MCP Bash 是一个用于执行 bash 命令的 MCP 服务器,主要用于开发环境中,帮助开发者通过 MCP 接口执行 bash 命令。
核心功能
- 执行任意 bash 命令
- 设置和维护跨命令执行的工作目录
- 通过 Model-Context-Protocol (MCP) 提供简洁的接口
- 易于部署和扩展
适用场景
- 开发环境中自动化执行 bash 命令
- 与 Claude Desktop 集成,用于代码编写和测试
- 需要从客户端应用程序执行 bash 命令的场景
工具列表
set_cwd(path)
: 设置 bash 命令的工作目录execute_bash(cmd)
: 执行 bash 命令并返回 stdout/stderr
常见问题解答
- 安全风险: 该服务器直接执行 bash 命令,可能存在安全风险,如执行
rm -rf /
等危险命令。建议在容器或受限环境中运行,并添加命令验证或允许列表。
使用教程
使用依赖
- Python 3.10 或更高版本
- pip 或其他包管理器
安装教程
-
克隆仓库
bash git clone https://github.com/yourusername/mcp-bash.git cd mcp-bash
-
创建并激活虚拟环境
bash python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate
-
安装依赖
bash pip install -e .
调试方式
-
启动服务器
bash python -m mcp.cli.server --module server
-
使用 API ```python from mcp.client import MCPClient
async def main(): client = MCPClient("http://localhost:8000") await client.set_cwd("/path/to/your/directory") stdout, stderr = await client.execute_bash("ls -la") print(f"Command output: {stdout}") if stderr: print(f"Error output: {stderr}")
if name == "main": import asyncio asyncio.run(main()) ```