MCP Shell Server

MIT License
59
1
  • Linux
  • Apple

Integrations

  • Enables execution of Git commands through the shell interface, allowing AI agents to perform version control operations like commits, pulls, pushes, and branch management.

  • Supports running npm commands through the shell interface, enabling package management operations like installing, updating, and removing JavaScript packages.

  • Facilitates running pnpm commands through the shell interface, offering fast, disk-space efficient package management for JavaScript projects.

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"] } } }

规则配置

将以下内容添加到您的 Cursor 规则文件中:

You have tools at your disposal to solve the coding task. Follow these rules regarding tool calls: 1. ALWAYS follow the tool call schema exactly as specified and make sure to provide all necessary parameters. 2. The conversation may reference tools that are no longer available. NEVER call tools that are not explicitly provided. 3. **NEVER refer to tool names when speaking to the USER.** For example, instead of saying 'I need to use the shell_exec tool to execute your command', just say 'I will execute your command'. 4. Only calls tools when they are necessary. If the USER's task is general or you already know the answer, just respond without calling tools. 5. Before calling each tool, first explain to the USER why you are calling 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 -h, --help Display help message -V, --version Display version information

工具参考

shell_exec

在指定的 shell 中执行命令。

参数:

  • command (字符串,必需):要执行的 shell 命令

资源参考

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

主机名

返回系统的主机名。

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文件。

执照

麻省理工学院

ID: t1x2r819sf