Bash MCP (Master Control Program)

by yannbam
Verified

local-only server

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

Integrations

  • Built as a TypeScript application that provides a secure interface for bash command execution with comprehensive session management for interactive command sessions.

Bash MCP(主控制程序)

一个 TypeScript 应用程序,允许 Claude 在安全保障下安全地执行 bash 命令。

特征

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

安装

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 及其依赖项保持最新

发展

建筑

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
-
security - not tested
F
license - not found
-
quality - not tested

一个 TypeScript 应用程序,允许 Claude 使用安全保障措施(包括白名单命令、目录和全面日志记录)安全地执行 bash 命令。

  1. Features
    1. Installation
      1. Configuration
        1. Usage
          1. Simple Command Execution
          2. Interactive Sessions
        2. Security Considerations
          1. Development
            1. Building
            2. Linting and Formatting
            3. Testing
          ID: d8uq01zv9p