Skip to main content
Glama

MCP Shell Server

by mkusaka

MCP Shell 服务器

使用模型上下文协议 (MCP) 执行 Shell 命令的服务器。它充当桥梁,使 AI 代理能够安全地执行 Shell 命令。

特征

  • 执行shell命令(单行和多行支持)
  • 支持各种shell(bash、zsh、fish、powershell、cmd等)
  • 详细的错误处理和日志记录
  • 兼容 MCP Inspector

安装

从 npm(作为用户)

# Using npm npm install -g @mkusaka/mcp-shell-server # Using yarn yarn global add @mkusaka/mcp-shell-server # Using pnpm pnpm add -g @mkusaka/mcp-shell-server

从源头(用于开发)

# Clone the repository git clone https://github.com/mkusaka/mcp-shell-server.git cd mcp-shell-server # Install dependencies pnpm install # Build the project pnpm build

MCP 配置

游标配置

将以下内容添加到您的 Cursor 配置文件( ~/.cursor/config.json ):

{ "mcpServers": { "shell": { "command": "npx", "args": ["-y", "@mkusaka/mcp-shell-server"] } } }

克莱恩积分

Cline是一个 VS Code 扩展,允许您将 MCP 服务器与 Claude AI 结合使用。要使用 Cline 设置此 MCP shell 服务器,请执行以下操作:

  1. 打开您的 Cline MCP 设置文件:
    • macOS: ~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
    • Windows: %APPDATA%/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
    • Linux: ~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
  2. 添加shell服务器MCP配置:
    { "mcpServers": { "shell": { "command": "npx", "args": ["-y", "@mkusaka/mcp-shell-server"], "disabled": false, "autoApprove": [] } } }
    或者,如果您想使用本地安装的包:
    { "mcpServers": { "shell": { "command": "node", "args": ["/path/to/mcp-shell-server/dist/index.js"], "disabled": false, "autoApprove": [] } } }

规则配置

将以下内容添加到您的 AI 助手的规则或提示中:

You have MCP Shell tools at your disposal. Follow these rules regarding Shell tool usage: 1. ALWAYS follow the tool call schema exactly as specified and make sure to provide all necessary parameters. 2. **NEVER refer to tool names when speaking to me.** For example, instead of saying 'I need to use the shell_exec tool to run this command', just say 'I'll run that command for you'. 3. Only use Shell tools when they are necessary. If my task is general or you already know the answer, just respond without calling tools. 4. When I ask you to execute shell commands, use the appropriate tool to: - Run single-line commands - Run multi-line commands (using heredoc syntax when appropriate) - Execute file operations, git commands, or system utilities - Provide system information when relevant 5. Always be careful with shell commands that might modify the system, and explain what the command will do before executing it. 6. If a shell command produces an error, explain what went wrong in simple terms and suggest ways to fix it.

用法

直接执行

node dist/index.js # or as an executable ./dist/index.js

开发模式

pnpm dev

使用 MCP Inspector 进行测试

pnpm inspect

命令行参数

-s, --shell <shell> Specify the path to the shell to use -w, --working-dir <directory> Specify the working directory for command execution -h, --help Display help message -V, --version Display version information

工具参考

shell_exec

在指定的 shell 中执行命令。

参数:

  • command (字符串,必需):要执行的 shell 命令
  • workingDir (字符串,可选):执行命令的工作目录。必须在 $HOME 下。

资源参考

服务器提供以下系统信息作为资源:

主机名

返回系统的主机名。

URI: hostname://

平台

返回操作系统平台。

URI: platform://

返回服务器正在使用的 shell 路径。

URI: shell://

用户名

返回当前用户名。

URI: username://

系统信息

以 JSON 格式返回全面的系统信息,包括:

  • 主机名
  • 平台
  • 用户名
  • CPU 数量
  • 总内存
  • 释放内存
  • 系统正常运行时间

使用示例

基本命令执行
{ "name": "shell_exec", "parameters": { "command": "echo Hello, World!" } }
多行命令(Heredoc)执行
{ "name": "shell_exec", "parameters": { "command": "cat << EOF | grep 'example'\nThis is an example text.\nAnother line without the keyword.\nEOF" } }

发展

项目结构

src/ ├── index.ts # Main entry point └── shell-server/ ├── index.ts # Shell server implementation └── lib/ └── logger.ts # Logging configuration

日志记录

日志写入mcp-shell.log文件。

执照

麻省理工学院

Install Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

local-only server

The server can only run on the client's local machine because it depends on local resources.

使用模型上下文协议 (MCP) 的服务器允许 AI 代理在主机系统上安全地执行 shell 命令。

  1. 特征
    1. 安装
      1. 从 npm(作为用户)
      2. 从源头(用于开发)
    2. MCP 配置
      1. 游标配置
      2. 克莱恩积分
      3. 规则配置
    3. 用法
      1. 直接执行
      2. 开发模式
      3. 使用 MCP Inspector 进行测试
    4. 命令行参数
      1. 工具参考
        1. shell\_exec
      2. 资源参考
        1. 主机名
        2. 平台
        3. 用户名
        4. 系统信息
        5. 使用示例
      3. 发展
        1. 项目结构
        2. 日志记录
      4. 执照

        Related MCP Servers

        • A
          security
          A
          license
          A
          quality
          A secure shell command execution server implementing the Model Context Protocol (MCP). This server allows remote execution of whitelisted shell commands with support for stdin input.
          Last updated -
          1
          74
          Python
          MIT License
          • Apple
        • -
          security
          A
          license
          -
          quality
          A Model Context Protocol (MCP) server that allows AI models to safely access and interact with local file systems, enabling reading file contents, listing directories, and retrieving file metadata.
          Last updated -
          47
          1
          JavaScript
          MIT License
          • Linux
        • -
          security
          A
          license
          -
          quality
          A secure, container-based implementation of the Model Context Protocol (MCP) that provides sandboxed environments for AI systems to safely execute code, run commands, access files, and perform web operations.
          Last updated -
          9
          Python
          Apache 2.0
          • Linux
        • A
          security
          A
          license
          A
          quality
          A server that enables AI assistants to execute terminal commands and retrieve outputs via the Model Context Protocol (MCP).
          Last updated -
          3
          6
          Python
          MIT License
          • Apple
          • Linux

        View all related MCP servers

        MCP directory API

        We provide all the information about MCP servers via our MCP API.

        curl -X GET 'https://glama.ai/api/mcp/v1/servers/mkusaka/mcp-shell-server'

        If you have feedback or need assistance with the MCP directory API, please join our Discord server