Skip to main content
Glama
gpo-mcp-server

gpo-mcp-server

by hgursel
README.md
# gpo-mcp-server

A **read-only** MCP (Model Context Protocol) server for querying and auditing
Active Directory Group Policy Objects (GPOs) through natural language with
Claude or any MCP-compatible AI client.

Runs on a domain-joined Windows machine. Executes PowerShell cmdlets via
subprocess — no extra AD libraries required.

---

## Features

- **15 read-only MCP tools** spanning GPO discovery, inspection, scope analysis, search, and audit
- **`get_gpo_scope`** — answers "which users/computers will be affected?" by combining linked OUs, security filtering (GpoApply permissions), and WMI filter conditions
- Strict **read-only** design — no GPO configuration is ever modified
- Automatic PowerShell version detection (PS7 `pwsh.exe` preferred, PS5.1 fallback)
- XML report parsing with full support for Admin Templates, Security Settings, Registry policies, and Scripts
- All tests run on any OS (PowerShell calls are mocked)

---

## Architecture

```
Claude (or any MCP client)
        │  stdio
        ▼
gpo-mcp-server (FastMCP, Python)
        │
        ▼
PowerShellRunner (subprocess.run)
        │
        ▼
powershell.exe / pwsh.exe
        │
        ▼
Active Directory (GroupPolicy module)
```

---

## Prerequisites

| Requirement | Notes |
|-------------|-------|
| Windows (domain-joined) | Server must be a member of the AD domain |
| RSAT: Group Policy Management Tools | `Get-WindowsCapability -Online -Name Rsat.GroupPolicy*` |
| PowerShell 5.1+ | Built into Windows; PS7 recommended |
| Python 3.10+ | With `pip` |

### Install RSAT on Windows 10/11

```powershell
Add-WindowsCapability -Online -Name Rsat.GroupPolicy.Management.Tools~~~~0.0.1.0
```

---

## Installation

```bash
# Clone the repository
git clone https://github.com/yourorg/gpo-mcp-server.git
cd gpo-mcp-server

# Install (in a virtual environment recommended)
pip install -e .

# Install with dev/test dependencies
pip install -e ".[dev]"
```

---

## Configuration

All settings are controlled via environment variables:

| Variable | Default | Description |
|----------|---------|-------------|
| `GPO_POWERSHELL_PATH` | auto-detect | Explicit path to `pwsh.exe` or `powershell.exe` |
| `GPO_COMMAND_TIMEOUT` | `30` | Timeout in seconds for PS commands |
| `GPO_TARGET_DOMAIN` | current domain | Target AD domain name |
| `GPO_LOG_LEVEL` | `INFO` | Python logging level (`DEBUG`, `INFO`, `WARNING`) |
| `GPO_BACKUP_PATH` | `C:\GPOBackups` | Default directory for `get_gpo_backup` |

---

## Running the Server

```bash
# Start with stdio transport (default — required for Claude Desktop)
python -m gpo_mcp.server

# or via the installed entry point
gpo-mcp-server
```

---

## Available Tools

### Read Tools

| Tool | Description |
|------|-------------|
| `list_gpos` | List all GPOs in the domain with metadata |
| `get_gpo_details` | Full metadata for a GPO (name, GUID, status, versions, WMI filter) |
| `get_gpo_report` | Full GPO settings report in XML (parsed) or HTML format |
| `get_gpo_settings` | Structured policy settings extracted from a GPO's XML report |
| `get_gpo_links` | All OUs/sites/domains this GPO is linked to, with link status |
| `get_gpo_scope` | **Who is affected** — linked OUs + security filtering (GpoApply) + WMI filter |
| `get_gpo_inheritance` | GPO inheritance chain for an OU with precedence order |
| `get_rsop` | Resultant Set of Policy for a specific user and/or computer |
| `test_connection` | Verify PowerShell and GroupPolicy module availability |

### Search Tools

| Tool | Description |
|------|-------------|
| `find_gpo_by_setting` | Search all GPOs for a setting keyword in names/categories/registry paths |
| `find_gpo_by_permission` | Find GPOs where a user/group has a specific permission level |

### Audit Tools

| Tool | Description |
|------|-------------|
| `compare_gpos` | Side-by-side settings diff between two GPOs |
| `find_unlinked_gpos` | Identify GPOs with no OU/site/domain links |
| `find_disabled_gpos` | Find fully or partially disabled GPOs |
| `get_gpo_backup` | Export a GPO to a backup folder (read-only filesystem operation) |

---

## Usage Examples

### Claude Desktop (`claude_desktop_config.json`)

```json
{
  "mcpServers": {
    "gpo": {
      "command": "gpo-mcp-server",
      "env": {
        "GPO_TARGET_DOMAIN": "contoso.com",
        "GPO_LOG_LEVEL": "INFO"
      }
    }
  }
}
```

### Claude Code

Add to `.claude/mcp.json` in your project:

```json
{
  "mcpServers": {
    "gpo": {
      "command": "python",
      "args": ["-m", "gpo_mcp.server"],
      "env": {
        "GPO_TARGET_DOMAIN": "contoso.com"
      }
    }
  }
}
```

### Example Prompts

```
"List all GPOs in the domain and show me which ones are disabled"

"Show me the scope of the 'Windows Firewall Policy' GPO —
 which users and computers will it apply to?"

"Compare the 'Default Domain Policy' with 'Workstation Baseline' GPO
 and highlight the differences"

"Find all GPOs that configure password length settings"

"Which GPOs does the 'IT Helpdesk' group have permission to edit?"

"Show the GPO inheritance for the Sales OU"

"What is the Resultant Set of Policy for user CONTOSO\jsmith
 on computer DESKTOP-001?"
```

---

## Development

### Run Tests

Tests work on any OS — all PowerShell calls are mocked:

```bash
pytest tests/ -v

# With coverage
pytest tests/ --cov=src/gpo_mcp --cov-report=term-missing
```

### Project Structure

```
src/gpo_mcp/
├── server.py          FastMCP entry point
├── config.py          Environment-driven configuration
├── powershell/
│   └── runner.py      PowerShell subprocess wrapper
├── parsers/
│   └── gpo_xml.py     GPO XML report parser
└── tools/
    ├── gpo_read.py    9 read tools
    ├── gpo_search.py  2 search tools
    └── gpo_audit.py   4 audit tools
```

---

## Security Considerations

- **Read-only by design**: No PowerShell write cmdlets (`Set-*`, `New-*`, `Remove-*`) are ever called.
- **No credential storage**: Uses the Windows identity of the process (domain machine account or interactive user).
- **No code injection**: All user inputs are escaped before being interpolated into PowerShell commands (single-quote escaping applied).
- **Audit logging**: Every PowerShell command executed is logged at `INFO` level, creating an implicit audit trail.
- **Least privilege**: The server only needs "Read" + "Apply Group Policy" permissions on GPOs to function. No elevated rights required for read operations.

---

## Roadmap

| Phase | Status | Description |
|-------|--------|-------------|
| Phase 1 | **Complete** | Read-only GPO inspection (15 tools) |
| Phase 2 | Planned | RAG/vector search over GPO settings history |
| Phase 3 | Planned | Write operations (create, link, modify settings) |

---

## License

MIT — see [LICENSE](LICENSE)

TDQS

A3.7/5.0

Scored across 15 tools

Disambiguation4/5

Most tools have clearly distinct targets (links, inheritance, RSoP, comparison, searches), but a few overlap: get_gpo_scope explicitly re-includes link status and WMI filter info already exposed by get_gpo_links and get_gpo_details, and get_gpo_report vs get_gpo_settings differ mainly in output format. Descriptions do a good job of steering an agent to the right one in most cases.

Naming Consistency4/5

All names use snake_case with a leading verb (list_, get_, find_, compare_, test_), which is highly predictable. The one wrinkle is get_gpo_backup, whose 'get_' verb masks that it creates a backup folder — a create/export verb would be clearer.

Tool Count5/5

Fifteen tools is well within the sweet spot for a read-only GPO auditing domain, and each tool maps to a distinct diagnostic question (links, scope, inheritance, RSoP, drift, unlinked, disabled, backup). Nothing feels like filler.

Completeness4/5

The read-only lifecycle is well covered: enumerate, inspect, parse settings, resolve effective scope/RSoP, compare, and export. Remaining gaps are minor and mostly acknowledged out of scope — no restore/import path and no direct tool for discovering OUs/sites/domains as entry points for inheritance or link queries.

Maintenance

ActivityInactive
ResponsivenessNo recent community issues