MCP-ShellJS

MCP-ShellJS

site icon
2025.03.29 0
JavaScriptShell 命令执行文件系统操作AI 开发工具开发效率
MCP-ShellJS 是一个基于 Model Context Protocol (MCP) 的服务,为大型语言模型(如 Claude)提供安全、受控的 ShellJS 访问能力。它通过安全沙箱执行 shell 命令,提供多层次的受控文件系统访问。
View on GitHub

Overview

基本能力

产品定位

MCP-ShellJS 是一个为 AI 开发者设计的工具,旨在为大型语言模型提供安全、受控的文件系统操作能力。

核心功能

  • 提供安全的 ShellJS 访问能力
  • 默认只读模式,可选读写和执行权限
  • 基于 Zod 的模式验证
  • 完整的 ShellJS 功能(ls、grep、sed、find 等)
  • TypeScript 实现,强类型支持
  • 简单的 LLM 集成 API

适用场景

  • AI 系统需要安全地探索文件系统
  • 自动化文件处理和组织
  • 代码库的快速搜索和文本处理
  • 构建 Unix 风格的命令管道

工具列表

Read-Only Tools

  • cat: 输出文件内容
  • grep: 搜索文件中的模式
  • find: 递归查找文件
  • ls: 列出目录内容
  • which: 定位命令
  • pwd: 打印工作目录
  • test: 测试文件条件
  • head: 显示文件开头
  • tail: 显示文件结尾
  • sort: 排序行
  • uniq: 过滤重复行

Read-Write Tools

  • mkdir: 创建目录
  • touch: 创建/更新文件
  • cp: 复制文件/目录
  • mv: 移动文件/目录
  • rm: 删除文件/目录
  • sed: 流编辑器

Special Permission Tools

  • exec: 执行命令(需要特殊权限)

常见问题解答

  • 安全性:默认只读模式,需要显式启用读写和执行权限
  • 集成:提供简单的 TypeScript API 和命令行接口
  • 性能:支持高效的文件搜索和处理

使用教程

使用依赖

需要安装 Node.js 和 npm

安装教程

# 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
});

许可证

该项目遵循 GPL-3.0-or-later 开源许可条款。