MCP-ShellJS

by erniebrodeur
Verified

local-only server

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

Integrations

  • Provides controlled access to ShellJS commands for filesystem operations, including read-only functions (ls, grep, find) and optional read-write capabilities (mkdir, touch, cp, mv, rm, sed).

  • Built with TypeScript for strong typing, enabling integration with TypeScript applications through a programmatic API.

  • Implements schema-based validation for command inputs and responses, ensuring that all operations conform to defined security constraints.

MCP-ShellJS

MCP 服务器为 Claude 等 LLM 提供安全、可控的 ShellJS 访问。

概述

MCP-ShellJS 将模型上下文协议 (MCP) 与 ShellJS 连接起来,使 AI 系统能够在安全沙盒中执行 Shell 命令。它通过多层安全机制提供受控的文件系统访问。

特征

  • 简化的安全性
    • 默认为只读模式
    • 通过命令行标志可选的读写模式
    • 通过命令行标志可选的执行权限
  • 使用 Zod 进行基于模式的验证
  • 完整的 ShellJS 功能( lsgrepsedfind等)
  • 强类型 TypeScript 实现
  • 用于 LLM 集成的简单 API

安装

# Clone the repository git clone https://github.com/yourusername/mcp-shelljs.git cd mcp-shelljs # Install dependencies npm install # Build the project npm run build

用法

命令行

# Default mode (read-only) node dist/index.js # Enable read-write operations node dist/index.js --enable-rw # Enable exec command (careful!) node dist/index.js --enable-exec # Enable both node dist/index.js --enable-rw --enable-exec

TypeScript 集成

// Import and initialize the MCP server import { startMCPServer } from 'mcp-shelljs'; // Start the server with default configuration (read-only) startMCPServer(); // Or with custom security configuration startMCPServer({ enableRw: true, // Enable read-write operations enableExec: false // Keep exec disabled });

安全设计

MCP-ShellJS 实现了一个简单的安全模型:

  1. 只读模式(默认):只有不修改文件系统的命令可用
  2. 读写模式--enable-rw ):启用可以创建、修改或删除文件的命令
  3. 执行模式--enable-exec ):启用潜在危险的exec命令来执行任意 shell 命令

该服务器仅使用 stdio 传输运行,使其适合与桌面 LLM 应用程序集成。

为什么使用 MCP-ShellJS?

对于 AI 开发人员来说,MCP-ShellJS 可以在控制风险的情况下实现强大的文件系统功能:

  • 高效探索:使用grep快速搜索并跨代码库find
  • 文本处理:使用sed转换文件而不完全加载它们
  • 安全自动化:让人工智能帮助组织和管理文件
  • 强大的管道:使用 Unix 风格管道进行链式操作

资源

目录资源

directory://{path}?include={glob}&exclude={glob}&honor_gitignore={boolean}

提供具有强大过滤功能的目录列表:

范围描述
include要包含的 Glob 模式(例如, *.js,*.ts
exclude要排除的 Glob 模式(例如, node_modules,dist
honor_gitignoretrue时,过滤掉与 .gitignore 中的模式匹配的文件
recursive当为true时,递归包含子目录

例子:

directory:///project/src?include=*.ts&exclude=*.test.ts&honor_gitignore=true

文件资源

file://{path}?lines={boolean}&start={number}&end={number}

提供文件内容以及查看特定部分的选项:

范围描述
lines如果为true ,则在输出中包含行号
start要包含的第一行(从 1 开始的索引)
end最后一行包括
highlight使用 Glob 模式突出显示匹配的文本

例子:

file:///project/src/index.ts?lines=true&start=10&end=50

工具

MCP-ShellJS 将 ShellJS 命令公开为工具,并按安全风险级别分组:

只读工具

工具描述参数
cat输出文件内容files :字符串/数组, options :带有-n的对象(数字行)
grep搜索文件中的模式regexfilesoptions :带有-v (反转)、 -l (仅文件名)、 -i (忽略大小写)的对象
find递归查找文件paths :字符串/数组(返回包括基本目录的文件路径)
ls列出目录内容paths :字符串/数组, options :对象,带有-R (递归)、 -A (全部)、 -L (跟随符号链接)、 -d (仅限目录)
which找到命令command :字符串(返回命令路径)
pwd打印工作目录(无争论)
test测试文件条件expression :字符串(例如, -d path目录存在, -f path文件存在)
head显示第一行files :字符串/数组, options :带有-n <num>对象(要显示的行数)
tail显示最后几行files :字符串/数组, options :带有-n <num>对象(要显示的行数)
sort排序行files :字符串/数组, options :带有-r (反向)、 -n (数字)的对象
uniq过滤重复的行input :字符串, output :字符串, options :对象,带有-i (忽略大小写)、 -c (计数)、 -d (仅重复)

读写工具

工具描述参数
mkdir创建目录dir :字符串/数组, options :带有-p的对象(创建中间目录)
touch创建/更新文件files :字符串/数组, options :对象, -c (不创建)、 -a (仅访问时间)、 -m (仅修改时间)
cp复制文件/目录source :字符串/数组, dest :字符串, options :对象,带有-R (递归)、 -n (无破坏)、 -f (强制)
mv移动文件/目录source :字符串/数组, dest :字符串, options :带有-f (强制)、 -n (无破坏)的对象
rm删除文件/目录files :字符串/数组, options :带有-r/-R (递归)、 -f (强制)的对象
sed文件流编辑器search_regex :正则表达式, replacement :字符串, files :字符串/数组, options :带有-i对象(就地)

特殊许可工具

工具描述参数
exec执行命令command :字符串, options :具有asyncsilent对象,需要allowExec: true配置

执照

GPL-3.0-或更高版本

-
security - not tested
F
license - not found
-
quality - not tested

安全的 MCP 服务器为 LLM 提供受控的 ShellJS 访问,使 AI 系统能够安全地执行 shell 命令并与可配置的安全沙箱中的文件系统交互。

  1. Overview
    1. Features
      1. Installation
        1. Usage
          1. Command Line
          2. TypeScript Integration
        2. Security Design
          1. Why Use MCP-ShellJS?
            1. Resources
              1. Directory Resource
              2. File Resource
            2. Tools
              1. Read-Only Tools
              2. Read-Write Tools
              3. Special Permission Tools
            3. License
              ID: lyxa7v4e53