Skip to main content
Glama

MCP CMD — Chạy lệnh Windows không bao giờ bị treo 🚀

MCP Server nhẹ, giúp AI assistant (Antigravity, Claude, Gemini CLI...) chạy lệnh CMD & PowerShell trên Windows an toàn, không bao giờ bị treo, với bảo mật đa tầng.

🔗 Repo: github.com/quangminh1212/MCP_CMD


Vấn đề gì được giải quyết?

Khi dùng AI coding assistant trên Windows, lệnh shell thường bị treo vĩnh viễn do:

  • Prompt chờ nhập liệu (y/n, password...)

  • Process zombie không tự tắt

  • Escape ký tự đặc biệt trong PowerShell

MCP CMD xử lý tất cả bằng cách:

  • ✅ Đóng stdin ngay lập tức — không prompt nào block được

  • ✅ Tự kill cả process tree khi timeout — không zombie

  • ✅ PowerShell chạy qua Base64 — hết lỗi escape

  • ✅ Output giới hạn 10MB — không tràn bộ nhớ

  • ✅ Phát hiện shell injection & lệnh nguy hiểm — cảnh báo bảo mật

  • ✅ Chống path traversal & UNC injection — bảo vệ thư mục làm việc


Related MCP server: Windows CLI MCP Server

7 Tools có sẵn

Tool

Mô tả

cmd_run

Chạy 1 lệnh CMD đơn lẻ

cmd_batch

Chạy nhiều lệnh tuần tự (dừng khi lỗi hoặc tiếp tục)

powershell_run

Chạy PowerShell an toàn, không lỗi escape

system_info

Xem thông tin hệ thống (OS, RAM, user)

process_list

Liệt kê các process đang chạy

process_cleanup

Dọn dẹp process treo/zombie

show_security_rules

Hiển thị cấu hình bảo mật & giới hạn runtime


Cài đặt nhanh (3 bước)

1. Clone & cài đặt

git clone https://github.com/quangminh1212/MCP_CMD.git
cd MCP_CMD
npm install

2. Thêm vào MCP config

Thêm đoạn sau vào file cấu hình MCP của bạn (ví dụ: .gemini/settings.json, claude_desktop_config.json):

{
  "mcpServers": {
    "cmd": {
      "command": "node",
      "args": ["C:\\path\\to\\MCP_CMD\\index.js"],
      "autoApprove": ["cmd_run", "cmd_batch", "powershell_run", "system_info", "process_list", "process_cleanup", "show_security_rules"]
    }
  }
}

⚠️ Thay C:\\path\\to\\MCP_CMD bằng đường dẫn thực tế trên máy bạn.

3. Xong! 🎉

AI assistant của bạn giờ có thể chạy lệnh Windows mà không bao giờ bị treo.


Ví dụ sử dụng

Chạy lệnh CMD đơn giản

{
  "name": "cmd_run",
  "arguments": {
    "command": "echo Hello && dir /b",
    "cwd": "C:\\Projects",
    "timeout": 30000
  }
}

Chạy nhiều lệnh liên tiếp

{
  "name": "cmd_batch",
  "arguments": {
    "commands": [
      { "command": "npm install", "cwd": "C:\\Projects\\my-app" },
      { "command": "npm run build", "cwd": "C:\\Projects\\my-app" },
      { "command": "npm test", "cwd": "C:\\Projects\\my-app" }
    ],
    "timeout": 60000,
    "continueOnError": false
  }
}

Chạy PowerShell

{
  "name": "powershell_run",
  "arguments": {
    "command": "Get-Process | Sort-Object CPU -Descending | Select-Object -First 5 Name, CPU",
    "timeout": 15000
  }
}

Dọn dẹp process treo

{
  "name": "process_cleanup",
  "arguments": {
    "maxAgeSeconds": 10,
    "dryRun": false,
    "includeNode": false
  }
}

Kiến trúc Anti-Hang

┌─────────────────────────────────────────────┐
│  MCP Client (AI Assistant)                  │
│  Gửi JSON-RPC request qua stdio            │
└────────────────┬────────────────────────────┘
                 │
┌────────────────▼────────────────────────────┐
│  MCP CMD Server (Node.js)                   │
│                                             │
│  1. spawn("cmd.exe", ["/c", command])       │
│  2. child.stdin.end()  ← đóng ngay         │
│  3. Thu stdout/stderr (giới hạn 5MB)        │
│  4. setTimeout → taskkill /T /F /PID        │
│  5. Trả kết quả khi xong hoặc timeout      │
└─────────────────────────────────────────────┘

Bảo vệ

Cách thực hiện

Không treo khi chờ input

stdin.end() ngay sau spawn

Không process zombie

taskkill /T /F /PID kill cả cây process

Không tràn bộ nhớ

Output giới hạn 10MB

Không popup GUI

windowsHide: true

Không lỗi escape PS

PowerShell dùng -EncodedCommand (Base64 UTF-16LE)

Chống path traversal

resolve(normalize(cwd)) + chặn .., UNC, null byte

Phát hiện lệnh nguy hiểm

Cảnh báo [SECURITY] cho del, format, shutdown...

Phát hiện shell injection

Cảnh báo khi dùng &&, |, >, ;...

Giới hạn độ dài lệnh

Chặn lệnh > 8192 bytes


Yêu cầu

  • Node.js v18+

  • Windows OS

Testing

npm test

The integration suite covers:

  • MCP stdio transport through node index.js

  • Wrapper startup through wrapper.js

  • Launcher startup through launcher.exe

  • Prompt/timeout anti-hang regression cases

  • Parallel execution queue behavior

  • Plain-text PowerShell error output

License

MIT © 2026 quangminh1212

Available Tools

8 tools
cmd_admin_runA

Run a Windows CMD command with Administrator (elevated) privileges. Uses PowerShell Start-Process -Verb RunAs to launch an elevated cmd.exe. Output is captured via temp files since elevated processes cannot pipe stdio to non-elevated parents. Use this for commands that require admin rights (e.g., netsh, sc query, icacls, dism, sfc). NOTE: UAC prompt may appear if not already elevated.

Inputs: command (required), cwd, timeout.

cmd_batchA

Run multiple CMD commands one by one. Each command runs in its own cmd.exe /c process (no hanging). Stops on first failure unless continueOnError is true.

Inputs: commands (required), timeout, continueOnError.

cmd_runA

Run a Windows CMD command without hanging. Uses cmd.exe /c with stdin closed and process tree kill on timeout. Safe for any non-interactive command.

Inputs: command (required), cwd, timeout.

powershell_runB

Run a PowerShell command without hanging. Uses -NonInteractive -NoProfile flags to prevent prompts and speed up startup. Command is Base64-encoded to avoid escaping issues.

Inputs: command (required), cwd, timeout.

process_cleanupA

Find and kill hanging/orphaned cmd.exe and conhost.exe processes. Targets windowless CMD processes older than the specified age (default: 30 seconds). Use this to clean up stale processes left by Antigravity's run_command tool.

Inputs: dryRun, includeNode, maxAgeSeconds.

process_listA

List running cmd.exe, powershell.exe, node.exe, and conhost.exe processes. Useful for diagnosing hanging processes before cleanup.

Inputs: filter.

show_security_rulesB

Display current security configuration, restrictions, and runtime limits. Shows command length limits, timeout values, concurrency settings, dangerous command patterns, and MCP infrastructure protection rules.

Inputs: no named parameters.

system_infoA

Get basic Windows system info: OS, architecture, memory, username. Quick diagnostic.

Inputs: no named parameters.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.6/5.0

    Scored across 8 tools

    Disambiguation4/5

    The execution tools are mostly distinct: cmd_run (non-elevated single), cmd_admin_run (elevated), cmd_batch (multiple), and powershell_run (different shell) each have clear roles. Minor conceptual overlap exists since cmd_batch with one command equals cmd_run, and process_list/process_cleanup are tightly related, but descriptions clarify boundaries well.

    Naming Consistency3/5

    Naming mixes conventions: prefix/namespace style (cmd_run, cmd_admin_run, powershell_run, process_list) alongside noun_phrases (system_info) and verb_noun (show_security_rules). Patterns are readable but not uniform across the set.

    Tool Count5/5

    Eight tools is well-scoped for a Windows command-execution server, with each tool earning its place across execution, process management, and diagnostics. No filler or redundant entries.

    Completeness4/5

    Covers command execution (normal, elevated, batch, PowerShell), process listing/cleanup, system info, and security rules—a solid lifecycle for the domain. Minor gaps: no targeted kill-by-PID or arbitrary background-process control beyond the age-based cleanup.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables safe execution of terminal commands across different shells (bash, cmd, PowerShell) with configurable timeouts, working directories, and resource limits for command-line operations through AI assistants.
      -
    • A
      license
      A
      quality
      C
      maintenance
      Enables secure command-line interactions on Windows systems with support for PowerShell, CMD, Git Bash, and WSL shells, providing controlled file access, command execution, and configurable security restrictions.
      6
      20 npm
      4
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to safely perform file operations, run terminal sessions, manage processes, search content, and inspect Git repositories on a local Windows machine under configurable permission and audit controls.
      Apache 2.0
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI assistants to securely control a local Windows environment through guardrail-protected command execution, Python running, process and filesystem management, system monitoring, and desktop GUI automation. It uses layered security checks to validate commands, code, and paths before execution.
      MIT