Secure Shell Executor

Secure Shell Executor

🚀 MCP Shell Server

MCP Shell Server 是一个安全的服务器,用于执行授权的 shell 命令,并支持通过 stdin 传递输入。它实现了模型上下文协议(MCP),允许远程执行经过验证的 shell 命令,为用户提供了安全、高效的命令执行环境。

✨ 主要特性

  • 安全命令执行:仅允许执行受信任的命令,保障系统安全。
  • 标准输入支持:可以通过 stdin 向命令提供输入,增强命令执行的灵活性。
  • 全面输出:返回 stdout、stderr、退出状态码和执行时间,方便用户了解命令执行情况。
  • shell 操作符验证:在使用 shell 操作符(;,&&,||,|)时仍需进行命令验证,确保命令的合法性。
  • 超时控制:为命令设置最大执行时间,避免命令长时间运行占用资源。

📦 安装指南

安装依赖项

pip install -e ".[test]"

启动服务器

uvicorn main:app --reload

验证安装

运行以下命令检查是否成功安装:

mcp-shell-server --version

💻 使用示例

基础用法

示例 1:执行基本命令

请求示例:

{
"command": ["echo", "Hello, World!"],
"stdin": null,
"directory": "/",
"timeout": 30
}

响应示例:

{
"stdout": "Hello, World!\n",
"stderr": "",
"status": 0,
"execution_time": 0.123456
}

示例 2:带有标准输入的命令

请求示例:

{
"command": ["tr", "a-z", "A-Z"],
"stdin": "hello world\n",
"directory": "/tmp",
"timeout": 60
}

📚 详细文档

客户端配置在 Claude.app 中

发布版本

code ~/Library/Application\ Support/Claude/claude.yaml
backend:
class: mcp_shell_server.Backend
config:
server_uri: http://localhost:5000
max_timeout: 3600

本地版本

poetry install
poetry run mcp-shell-server

请求格式

请求参数

参数名 类型 是否必须 描述
command string[] 命令及其参数,作为数组元素
stdin string 提供给命令的标准输入
directory string 执行命令的工作目录
timeout integer 最大执行时间(秒)

响应格式

参数名 类型 描述
stdout string 标准输出
stderr string 错误输出
status integer 退出状态码
execution_time float 执行时间(秒)
error string 错误信息(仅在失败时出现)

🔧 技术细节

开发说明

设置开发环境

  1. 克隆仓库
git clone https://github.com/yourusername/mcp-shell-server.git
cd mcp-shell-server
  1. 安装依赖项(包括测试要求)
pip install -e ".[test]"

执行测试

pytest

API 参考文档

请求参数

参数名 类型 是否必须 描述
command string[] 命令及其参数,作为数组元素
stdin string 提供给命令的标准输入
directory string 执行命令的工作目录
timeout integer 最大执行时间(秒)

响应参数

参数名 类型 描述
stdout string 标准输出
stderr string 错误输出
status integer 退出状态码
execution_time float 执行时间(秒)
error string 错误信息(仅在失败时出现)

系统要求

  • Python 3.11 或更高版本
  • mcp>=1.1.0

📄 许可证

MIT 许可证 - 请参阅 LICENSE 文件以获取详细信息。

  • 0 关注
  • 0 收藏,11 浏览
  • system 提出于 2025-09-30 04:45

相似服务问题