Active Directory管理服务器

一个用于管理Active Directory的服务器,通过Python服务器和PowerShell后端实现用户和组管理、域信息查询等功能。

  • by rosingul
  • Python
  • 本地部署
  • 14 星标
  • 更新于
在 GitHub 查看 rosingul/mcp-active-directory-server

使用说明

mcp活动目录服务器

MCP服务器,用于使用Python服务器和PowerShell后端进行Active Directory管理

🏗️ 架构概述

克劳德桌面↔ MCP协议↔ Python服务器↔ PowerShell↔ 活动目录

该系统采用三层架构:

  • 表示层:克劳德桌面(AI界面)
  • 应用层:Python MCP服务器(协议处理程序和编排器)
  • 数据层:PowerShell脚本→ Active Directory(实际AD操作)

📁 部件分解

1. simple_mcp_server.py -MCP协议桥🌉

角色:担任主要协调人和协议翻译

它的作用:

  • 协议处理器 :实现模型上下文协议(MCP)JSON-RPC 2.0规范

  • 工具注册表:定义了14个可供Claude使用的工具:

    • 6基本工具(用户管理、组、连接)
    • 8个高级工具(域信息、林信息、信任、复制等)
  • 凭据管理器:从Windows凭据管理器安全检索AD服务帐户凭据

  • PowerShell编排器:使用适当的参数执行PowerShell脚本

  • 响应格式化程序:将PowerShell JSON输出转换为符合MCP的响应

关键功能:

async def handle_request(request)     # Handles MCP protocol requests

async def run_powershell_script()    # Executes PowerShell operations

async def get_credentials_from_credential_manager()  # Security layer

2. ad_operations.ps1 -Active Directory工作马⚙️

角色: 包含所有实际的Active Directory操作和业务逻辑

它的作用:

  • AD操作: 针对不同AD任务的14种不同功能
  • 输入验证: 处理JSON参数解析和验证
  • 凭证管理: 使用提供的域凭据进行AD身份验证
  • 错误处理: 具有结构化错误响应的全面try-catch块
  • 结构化输出: 返回JSON格式的结果以进行一致的处理

功能类别:

基本操作(6):

Create-User              # New-ADUser operations
Modify-User              # Set-ADUser operations  
Add-UserToGroup          # Add-ADGroupMember
Remove-UserFromGroup     # Remove-ADGroupMember
Get-UserInfo             # Get-ADUser with all properties
Test-ADConnection        # Domain connectivity test

增强操作(8):

Get-DomainInfo          # Get-ADDomain equivalent
Get-ForestInfo          # Get-ADForest equivalent
Get-TrustInfo           # Get-ADTrust relationships
Get-DomainPasswordPolicy # Get-ADDefaultDomainPasswordPolicy
Get-ReplicationStatus   # AD replication health
Get-AllUserAttributes   # Deep user inspection
Get-AllComputerAttributes # Deep computer inspection
Get-SitesAndServices    # Sites, links, subnets

3.安全和配置层🔐

凭证管理:

  • 使用Windows凭据管理器进行安全凭据存储
  • 目标:“MCPActiveDirectory”
  • 具有最低所需权限的服务帐户
  • 脚本中没有硬编码密码

配置变量:

$TargetOU = "OU=ManagedUsers,DC=demo,DC=local"   # Managed OU
$DomainName = "demo.local"                       # Domain name
$DefaultPassword = "TempPassword123!"            # Initial password (this will be used if no password is supplied)

🔄 数据流架构

1.请求流(Claude→ AD)

Claude Desktop
    ↓ (User request: "Create user John Smith")
Python MCP Server
    ↓ (Validates request, formats parameters)
    ↓ (Retrieves credentials from Credential Manager)
    ↓ (Calls PowerShell with JSON data)

PowerShell Script
    ↓ (Parses JSON, authenticates to AD)
    ↓ (Executes New-ADUser cmdlet)
Active Directory

2.响应流(AD→ 克劳德)

Active Directory
  ↓ (Returns AD object/status)
PowerShell Script  
  ↓ (Formats as JSON with success/error status)
Python MCP Server
  ↓ (Receives JSON, validates, formats for MCP)
  ↓ (Creates MCP-compliant response)
Claude Desktop
  ↓ (Displays formatted result to user)

🎯 组件责任

Python服务器职责:

  • ✅ MCP协议合规性
  • ✅ 工具注册和发现
  • ✅ 安全(凭证检索)
  • ✅ 错误处理和日志
  • ✅ 异步操作处理
  • ✅ JSON-RPC 2.0实现

PowerShell脚本职责:

  • ✅ 所有Active Directory操作
  • ✅ 参数验证和净化
  • ✅ 域身份验证
  • ✅ 业务逻辑实现
  • ✅ 结构化错误报告
  • ✅ 全面的数据检索

安全模型:

  • 🔐 凭据:存储在Windows凭据管理器中(加密)
  • 🔐 身份验证:具有最低权限的服务帐户
  • 🔐 范围:仅限于特定OU(Managed用户)