Skip to content

HWZen/windows-admin-exec-mcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

windows-admin-exec-mcp

MCP for Windows systems to execute instructions with administrator privileges.
适用于Windows系统的以管理员权限执行指令的 MCP。


Architecture

┌─────────────────────────────────────────────────────────┐
│  AI Assistant (Claude / any MCP host)                   │
│     ↓ MCP stdio                                         │
│  Python MCP Server  (client/mcp/main.py)                │
│     ↓ TCP JSON (localhost:12380)                        │
│  C++ Windows Service  (service/)                        │
│     • Runs as LocalSystem (administrator)               │
│     • Optional Telegram approval gate                   │
│     • Executes cmd.exe /c <command>                     │
│     • Returns stdout / stderr / exit code               │
└─────────────────────────────────────────────────────────┘

Optional alternative client:
  Python OpenClaw Skill  (client/openclaw/skill.py)
     ↓ same TCP JSON protocol
  C++ Windows Service

Components

Component Language / Tech Location
Windows service C++20, CMake, vcpkg service/
MCP server (AI client) Python 3.12, mcp client/mcp/
OpenClaw skill Python 3.12 client/openclaw/

IPC Protocol

All messages between the Python clients and the C++ service are framed as:

[4-byte big-endian length][UTF-8 JSON body]

Request (client → service):

{
  "id": "uuid4",
  "command": "ipconfig /all",
  "working_dir": "",
  "timeout_seconds": 60
}

Response (service → client):

{
  "id": "uuid4",
  "success": true,
  "stdout_output": "...",
  "stderr_output": "",
  "exit_code": 0,
  "error_message": ""
}

Quick Start

1. Build the Windows Service

Requirements: Visual Studio 2022, CMake ≥ 3.25, vcpkg.

cd service
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake
cmake --build build --config Release

2. Install the Service

cd service
copy build\Release\AdminExecMCP.exe .
copy config.example.json config.json
REM Edit config.json if you want Telegram approval
install.bat

Note: install.bat must be run as Administrator.
The service registers itself as AdminExecMCP and starts automatically on boot.

3. Configure the Python MCP client

pip install -r client/mcp/requirements.txt

Add to your Claude Desktop / MCP host config (claude_desktop_config.json):

{
  "mcpServers": {
    "windows-admin-exec": {
      "command": "python",
      "args": ["C:/path/to/client/mcp/main.py"]
    }
  }
}

4. (Optional) Enable Telegram Approval

Edit config.json next to AdminExecMCP.exe:

{
  "approval": {
    "enabled": true,
    "type": "telegram",
    "telegram": {
      "bot_token": "123456:ABC-DEF...",
      "chat_id": "987654321",
      "timeout_seconds": 300
    }
  }
}

Restart the service after editing:

net stop AdminExecMCP && net start AdminExecMCP

When the AI calls execute_command, the service will send a Telegram message like:

🔐 AdminExecMCP — Approval Required

Command:
  ipconfig /all

Reply:
  /approve_<uuid>  — to approve
  /deny_<uuid>     — to deny

5. (Optional) OpenClaw Skill

import importlib.util
spec = importlib.util.spec_from_file_location("skill", r"C:\path\to\client\openclaw\skill.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
for skill in module.SKILLS:
    agent.register_skill(skill)

Service Management

Action Command (run as Admin)
Install & start AdminExecMCP.exe install
Remove AdminExecMCP.exe uninstall
Debug (console) AdminExecMCP.exe console

Security Considerations

  • The service binds only to 127.0.0.1 (localhost) by default; it is not accessible from the network.
  • Enable Telegram approval (approval.enabled = true) to require explicit human sign-off for every command the AI attempts to run.
  • The service runs as LocalSystem. Commands it executes inherit this token and have full administrator access to the local machine.
  • Restrict who can connect to the MCP server in your AI host configuration.

Running the Tests

pip install pytest mcp
pytest tests/

Tech Stack

Layer Technology
C++ service C++20, CMake 3.25+, VS 2022, vcpkg
C++ dependencies nlohmann/json, libcurl
Python clients Python 3.12, mcp
Telegram integration Telegram Bot API via libcurl (C++)

About

MCP for Windows systems to execute instructions with administrator privileges.适用于Windows系统的以管理员权限执行指令的mcp。

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors