Bash MCP

by yannbam

Bash MCP(主控制程序)

一个 TypeScript 应用程序,允许 Claude 在安全保障措施下安全地执行 Bash 命令。该项目实现了模型上下文协议 (MCP),为 Claude 等 AI 助手执行 Bash 命令提供了一个安全的接口。

特征

  • 在受控环境中执行 bash 命令
  • 支持无状态和有状态(交互式)命令执行
  • 安全保障措施:
    • 白名单命令
    • 白名单目录
    • 命令验证
    • 输出清理
  • 交互式命令的会话管理
  • 综合日志记录
  • 用于 AI 集成的 MCP 服务器实现

安装

npm install npm run build

配置

配置存储在config/default.json中。您可以自定义:

  • 允许的命令
  • 允许的目录
  • 会话设置
  • 安全设置
  • 日志记录设置

示例配置:

{ "allowedCommands": ["ls", "cat", "echo", "pwd"], "allowedDirectories": ["/tmp", "/home"], "session": { "timeout": 300, "maxActiveSessions": 5, "defaultMode": "stateless" }, "security": { "validateCommandsStrictly": true, "sanitizeOutput": true, "maxOutputSize": 1048576, "commandTimeout": 30 }, "logging": { "level": "info", "file": "logs/bash-mcp.log", "maxSize": 10485760, "maxFiles": 5 } }

用法

作为图书馆

简单命令执行
import { executeCommand } from 'bash-mcp'; const result = await executeCommand('ls -la', { cwd: '/home/user' }); console.log(result.output);
互动环节
import { initBashMCP } from 'bash-mcp'; const mcp = await initBashMCP(); // Create a session const session = mcp.createSession('/home/user'); const sessionId = session.sessionId; // Execute a command in the session const result1 = await mcp.executeCommand('ls -la', { sessionId }); console.log(result1.output); // Send input to the session const result2 = await mcp.sendInput({ sessionId, input: 'echo "Hello, world!"' }); console.log(result2.output); // Close the session when done mcp.closeSession(sessionId);

作为 MCP 服务器

该项目包括一个 MCP 服务器实现,可与 Claude Desktop 或其他 MCP 客户端一起使用:

# Start the TypeScript MCP server npm run mcp # Start the JavaScript MCP server npm run mcp-js # Start with MCP Inspector npm run inspector

有关 MCP 服务器实现的详细文档,请参阅MCP.md

安全注意事项

此 MCP 在设计时充分考虑了安全性,但重要的是:

  • 保持允许的命令和目录列表尽可能严格
  • 定期检查并更新配置
  • 监控日志中是否存在可疑活动
  • 保持 MCP 及其依赖项保持最新

发展

建筑

npm run build

代码检查和格式化

要检查 linting 问题:

npm run lint

要自动修复 linting 和格式问题:

./fix-lint.sh

或者手动:

npm run lint:fix # Fix linting issues npm run format # Format code

测试

npm test

MCP SDK 版本

该项目使用 MCP SDK 版本 1.0.1。

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

一个 TypeScript 应用程序,允许 Claude 安全地执行具有安全保障的 bash 命令,并通过模型上下文协议提供安全的接口。

  1. Features
    1. Installation
      1. Configuration
        1. Usage
          1. As a Library
          2. As an MCP Server
        2. Security Considerations
          1. Development
            1. Building
            2. Linting and Formatting
            3. Testing
          2. MCP SDK Version

            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 11 days ago
              1
              68
              Python
              MIT License
              • Apple
            • A
              security
              A
              license
              A
              quality
              A Model Context Protocol server that provides secure command-line access to Windows systems, allowing MCP clients like Claude Desktop to safely execute commands in PowerShell, CMD, and Git Bash shells with configurable security controls.
              Last updated 2 months ago
              9
              350
              105
              JavaScript
              MIT License
            • A
              security
              A
              license
              A
              quality
              A Node.js implementation of the Model Context Protocol that provides secure shell command execution capabilities, allowing AI models like Claude to run shell commands in a controlled environment with built-in security measures.
              Last updated 5 months ago
              1
              110
              25
              JavaScript
              MIT License
              • Apple
            • -
              security
              F
              license
              -
              quality
              A TypeScript application that allows Claude to safely execute bash commands with security safeguards including whitelisted commands, directories, and comprehensive logging.
              Last updated a month ago
              TypeScript
              • Linux

            View all related MCP servers

            ID: cb73j9oj3x