
MCP-ShellJS

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