Skip to content

bivex/WinReg-Mcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Windows Registry MCP Server

A production-ready Model Context Protocol (MCP) server that provides controlled, secure access to the Windows Registry for AI models.

Architecture

This server follows a clean, layered architecture with strict separation of concerns:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    MCP Protocol Layer                        β”‚
β”‚  (JSON-RPC, stdio transport, request/response handling)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Application/Use-Case Layer                  β”‚
β”‚  - Tool Handlers (RegistryToolHandlers)                     β”‚
β”‚  - Resource Handlers (RegistryResourceHandlers)             β”‚
β”‚  - Authorization & Access Control                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Domain Layer                            β”‚
β”‚  - Registry Operations (IRegistryService)                   β”‚
β”‚  - Domain Models (RegistryKey, RegistryValue)               β”‚
β”‚  - Business Rules & Validation                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Infrastructure Layer                        β”‚
β”‚  - WinReg Adapter (wraps Win32 Registry API)                β”‚
β”‚  - Configuration Provider                                   β”‚
β”‚  - Logging & Metrics                                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Features

Core Capabilities

  • βœ… Read Registry Values - Query specific registry keys/values with path validation
  • βœ… Enumerate Keys - List subkeys under a specific parent key
  • βœ… Enumerate Values - List values under a specific key
  • βœ… Write Registry Values - Create/update registry values with authorization
  • βœ… Delete Registry Items - Remove keys/values with strict permission controls
  • βœ… Query Key Metadata - Get information about keys (modification time, value count)

Security Features

  • πŸ”’ Path Allow-List - Only configured registry paths are accessible
  • πŸ”’ Authorization Levels - READ_ONLY, READ_WRITE, ADMIN access control
  • πŸ”’ Data Exfiltration Protection - Limits on enumeration depth and value counts
  • πŸ”’ Audit Logging - All operations logged with correlation IDs
  • πŸ”’ Rate Limiting - Configurable request rate limits
  • πŸ”’ Timeout Controls - All operations have execution time limits

Observability

  • πŸ“Š Metrics - Prometheus-compatible metrics for operations, latency, errors
  • πŸ“ Structured Logging - JSON-formatted logs with correlation IDs
  • πŸ₯ Health Checks - Liveness, readiness, and startup health endpoints

Quick Start

Prerequisites

  • .NET 8.0 or later
  • Windows OS (Server 2016+ or Windows 10+)

Installation

# Clone the repository
git clone <repository-url>
cd winregcsharp-mcp

# Build the solution
dotnet build

# Run the server
dotnet run --project src/WinRegMcp.Server

Configuration

Create a config/allowed_paths.json file:

{
  "allowed_roots": [
    {
      "path": "HKEY_CURRENT_USER\\Software\\MyApp",
      "access": "read_write",
      "max_depth": 5
    }
  ],
  "denied_paths": [
    "HKEY_LOCAL_MACHINE\\SECURITY",
    "HKEY_LOCAL_MACHINE\\SAM"
  ]
}

Set environment variables:

WINREG_MCP_AUTHORIZATION_LEVEL=READ_ONLY
WINREG_MCP_ALLOWED_PATHS_FILE=config/allowed_paths.json
WINREG_MCP_LOG_LEVEL=info

Available Tools

read_value

Read a specific registry value.

Parameters:

  • path (string): Full registry path (e.g., "HKEY_CURRENT_USER\Software\MyApp")
  • value_name (string): Name of the value to read

Returns: Value data and type information

write_value

Write or update a registry value.

Parameters:

  • path (string): Full registry path
  • value_name (string): Name of the value
  • value_data (string): Data to write
  • value_type (string): Registry type (String, DWord, QWord, Binary, etc.)

enumerate_keys

List subkeys under a registry path.

Parameters:

  • path (string): Parent registry path
  • max_depth (integer, optional): Maximum enumeration depth (default: 1)

Returns: List of subkey names

enumerate_values

List all values in a registry key.

Parameters:

  • path (string): Registry key path

Returns: List of value names and types

get_key_info

Get metadata about a registry key.

Parameters:

  • path (string): Registry key path

Returns: Key information (subkey count, value count, last modified time)

delete_value

Delete a registry value.

Parameters:

  • path (string): Registry key path
  • value_name (string): Name of the value to delete

delete_key

Delete a registry key (requires ADMIN authorization).

Parameters:

  • path (string): Registry key path to delete

Security

Default Allowed Paths (READ_ONLY)

  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
  • HKEY_CURRENT_USER\Software (limited depth)

Always Denied Paths

  • HKEY_LOCAL_MACHINE\SECURITY
  • HKEY_LOCAL_MACHINE\SAM
  • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa

Authorization Levels

  • READ_ONLY: Can only read from allowed paths
  • READ_WRITE: Can read and write to allowed paths
  • ADMIN: Full access (requires explicit configuration)

Development

Project Structure

src/
β”œβ”€β”€ WinRegMcp.Domain/          # Domain models and interfaces
β”‚   β”œβ”€β”€ Models/                # Registry domain models
β”‚   β”œβ”€β”€ Services/              # Domain service interfaces
β”‚   └── Exceptions/            # Domain exceptions
β”œβ”€β”€ WinRegMcp.Infrastructure/  # External adapters
β”‚   β”œβ”€β”€ Registry/              # Win32 Registry adapter
β”‚   β”œβ”€β”€ Configuration/         # Config providers
β”‚   └── Observability/         # Logging and metrics
β”œβ”€β”€ WinRegMcp.Application/     # Use cases and handlers
β”‚   β”œβ”€β”€ Handlers/              # MCP tool handlers
β”‚   β”œβ”€β”€ Authorization/         # Access control
β”‚   └── DTOs/                  # MCP contract DTOs
└── WinRegMcp.Server/          # MCP server entry point
    └── Program.cs

tests/
└── WinRegMcp.Tests/           # Unit and integration tests

Running Tests

dotnet test

Building for Production

dotnet publish -c Release -r win-x64 --self-contained

Versioning

Current version: 1.0.0

  • Breaking changes increment major version
  • New optional parameters increment minor version
  • Bug fixes increment patch version
  • Deprecation notice period: 3 months

License

MIT License - See LICENSE file for details

Contributing

Contributions welcome! Please read CONTRIBUTING.md for guidelines.

Documentation