Skip to main content
Glama

Shell MCP Server

by hdresearch

Shell MCP 服务器

模型上下文协议 (MCP) 的 Node.js 实现,提供安全的 Shell 命令执行功能。该服务器允许 AI 模型在受控环境中执行 Shell 命令,并内置安全措施。可轻松与Claude Desktop集成,将 Claude 与您的 Shell 连接起来。

特征

  • 符合 MCP 标准的服务器实现
  • 通过黑名单保护来确保命令执行的安全
  • 命令存在验证
  • 基于标准 I/O 的传输
  • 错误处理和正常关闭

安装

运行npx mcp-shell

要将其添加到 Claude Desktop,请运行npx mcp-shell config 。或者手动将npx -y mcp-shell添加到您的配置中。

启动(或重新启动) Claude Desktop ,您应该会看到登录页面上列出的 MCP 工具。

安全功能

该服务器实施了多项安全措施:

  1. 命令黑名单
    • 防止执行危险的系统命令
    • 阻止访问关键系统修改
    • 防止文件系统被破坏
    • 防止权限提升
  2. 命令验证
    • 执行前验证命令是否存在
    • 验证黑名单
    • 返回无效命令的明确错误消息

可用工具

服务器提供了一个工具:

运行命令

执行 shell 命令并返回其输出。

输入模式:

{ "type": "object", "properties": { "command": { "type": "string" } } }

回复:

  • 成功:命令以纯文本形式输出
  • 错误:错误消息为纯文本

黑名单命令

出于安全考虑,以下命令类别被阻止:

  • 文件系统销毁命令(rm、rmdir、del)
  • 磁盘/文件系统命令(format、mkfs、dd)
  • 权限/所有权命令(chmod、chown)
  • 权限提升命令(sudo、su)
  • 代码执行命令(exec、eval)
  • 系统通信命令(写入、墙)
  • 系统控制命令(关机、重启、初始化)

错误处理

该服务器包括全面的错误处理:

  • 未找到命令错误
  • 列入黑名单的命令错误
  • 执行错误
  • MCP 协议错误
  • SIGINT 信号正常关闭

实现细节

该服务器使用以下方式构建:

  • 模型上下文协议 SDK
  • StdioServerTransport 用于通信
  • execa 用于命令执行
  • command-exists 用于命令验证

发展

要修改安全设置,您可以:

  1. 编辑BLACKLISTED_COMMANDS设置以调整被阻止的命令
  2. 修改validateCommand函数以添加其他验证规则
  3. 增强CallToolRequestSchema处理程序中的命令解析逻辑

You must be authenticated.

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.

模型上下文协议的 Node.js 实现提供了安全的 shell 命令执行功能,允许像 Claude 这样的 AI 模型在具有内置安全措施的受控环境中运行 shell 命令。

  1. 特征
    1. 安装
      1. 安全功能
        1. 可用工具
          1. 运行命令
        2. 黑名单命令
          1. 错误处理
            1. 实现细节
              1. 发展

                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
                • A
                  security
                  A
                  license
                  A
                  quality
                  A comprehensive Model Context Protocol server that provides advanced Node.js development tooling for automating project creation, component generation, package management, and documentation with AI-powered assistance.
                  Last updated -
                  7
                  2
                  JavaScript
                  MIT License
                • A
                  security
                  F
                  license
                  A
                  quality
                  A Model Context Protocol server that allows secure execution of pre-approved commands, enabling AI assistants to safely interact with the user's system.
                  Last updated -
                  1
                  3
                  18
                  JavaScript
                • A
                  security
                  A
                  license
                  A
                  quality
                  A server that uses the Model Context Protocol (MCP) to allow AI agents to safely execute shell commands on a host system.
                  Last updated -
                  1
                  76
                  2
                  TypeScript
                  MIT License
                  • Linux
                  • Apple

                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/hdresearch/mcp-shell'

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