Windows系统管理工具服务器

将Windows系统管理工具作为MCP服务器通过stdio暴露,由neurond调用,不直接暴露到网络。

  • by felixlheureux
  • C#
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 cortexd-labs/mcpw

使用说明

mcpw

Windows MCP服务器 --将Windows系统管理工具公开为 主控程序 (模型上下文协议)服务器 stdio.

设计用于调用 神经元 (联盟代理)。从不直接接触网络。


需求

  • Windows 10/11或Windows Server 2019+
  • .NET 10 SDK (构建)或。NET 10运行时(运行预构建)
  • 对于 iis.* 工具:安装了管理控制台的IIS
  • 对于 ad.* / gpo.* 工具:RSAT或加入域的计算机
  • 对于 hyperv.* 工具:已启用Hyper-V角色
  • 对于 container.* 工具:Docker桌面或Docker引擎(Windows容器)

构建与运行

# Run from source
dotnet run --project src/Mcpw

# Publish self-contained single file
dotnet publish src/Mcpw/Mcpw.csproj -c Release -r win-x64 --self-contained -p:PublishSingleFile=true -o publish/

# Install as Windows Service
.\deploy\install.ps1

测试

# All unit tests (no Windows dependencies — everything behind interfaces + mocks)
dotnet test

# Run with filter
dotnet test --filter "Category=Integration"

# Test with MCP Inspector
npx -y @modelcontextprotocol/inspector
# Transport: stdio | Command: .\publish\mcpw.exe

配置

mcpw读取 C:\ProgramData\mcpw\config.json 在启动时。缺少文件=所有默认值。

{
  "allowedPaths": ["C:\\Users", "C:\\inetpub", "C:\\ProgramData"],
  "blockedPaths": ["C:\\Windows\\System32\\config", "C:\\Windows\\NTDS"],
  "enabledDomains": ["system","process","service","log","network","file","storage","security","container","hardware","schedule","registry","iis"],
  "disabledDomains": ["ad","hyperv","gpo"],
  "privilegeTier": "operate"
}

域名不在 enabledDomains 返回 ToolNotFound。只部署机器需要的东西。


建筑

mcpw (stdio)
├── Server.cs          JSON-RPC 2.0 router, TextReader/TextWriter based
├── Daemon.cs          IHostedService + Windows Service host (SCM)
├── Config.cs          config.json loader with defaults
├── InputValidator.cs  injection/traversal/blocklist guard
├── IToolHandler.cs    interface for all tool domain classes
│
├── Types/             POCOs serialized in MCP responses
├── Windows/           OS abstractions (interface + implementation)
│   ├── IWmiClient         → WmiClient (System.Management)
│   ├── IEventLogAccess    → EventLogAccess (Eventing.Reader)
│   ├── IRegistryAccess    → RegistryAccess (Microsoft.Win32)
│   ├── IServiceControl    → ServiceControl (ServiceProcess)
│   └── IPowerShellHost    → PowerShellHost (Management.Automation)
│
└── Tools/             One class per domain, all testable via mocked interfaces
    ├── SystemTools    system.*
    ├── ProcessTools   process.*
    ├── ServiceTools   service.*
    ├── LogTools       log.*
    ├── NetworkTools   network.*
    ├── FileTools      file.*
    ├── IdentityTools  identity.*
    ├── StorageTools   storage.*
    ├── SecurityTools  security.*
    ├── ContainerTools container.*
    ├── HardwareTools  hardware.*
    ├── ScheduleTools  schedule.*
    ├── RegistryTools  registry.*   (Windows-only)
    ├── IISTools       iis.*        (Windows-only)
    ├── ADTools        ad.*         (Windows-only)
    ├── HyperVTools    hyperv.*     (Windows-only)
    └── GPOTools       gpo.*        (Windows-only)

特权级别

层级 工具 必填
阅读 system.info, process.list, service.list, log.tail, network.*, storage.usage, registry.get, hardware.* 任何用户
操作 service.start/stop, process.kill, iis.pool.recycle, file.write, schedule.add 本地管理员
领域 ad.*, gpo.*, hyperv.* 域名帐户
危险 system.reboot, registry.set/delete, ad.user.resetpw 明确的神经元政策批准

安全

  • 无网络暴露 --仅限stdio,神经元处理mTLS+身份验证
  • 输入验证 --注入字符被拒绝,路径遍历被阻止
  • 路径阻止列表 — C:\Windows\System32\config, C:\Windows\NTDS 总是被封锁
  • WQL参数化 --WMI查询中没有字符串插值
  • PowerShell约束语言模式 --所有嵌入式PS运行都受到限制
  • 注册表阻止列表 --SAM和安全配置单元被阻止

工具参考

看 tools.md 关于输入模式的完整工具参考。


相关


许可证

麻省理工学院