WinRM MCP Server
A Model Context Protocol (MCP) server that enables AI agents to execute PowerShell commands on remote Windows machines via WinRM.
Quick Start
- Install
uvif you haven't already (installation guide) - Add the following to your VS Code MCP configuration:
{
"servers": {
"winrm-mcp-server": {
"command": "uvx",
"args": ["winrm-mcp-server"],
"env": {
"WINRM_MCP_HOSTNAME": "your-windows-host.com",
"WINRM_MCP_USERNAME": "your-username",
"WINRM_MCP_PASSWORD": "your-password"
}
}
}
}
- That's it! No installation required -
uvxhandles everything automatically.
Features
- Remote Command Execution: Execute PowerShell commands on remote Windows hosts
- Secure Authentication: Uses username/password authentication with support for both HTTP and HTTPS
- Error Handling: Comprehensive error handling with semantic separation of error types
- Timeout Management: Configurable command timeouts (default: 5 minutes)
- Comprehensive Logging: Detailed logging compatible with VS Code's MCP Server output
- Connection Flexibility: Automatically tries HTTPS first, falls back to HTTP if needed
Installation
Using uvx (Recommended)
The recommended way to use this MCP server is with uvx, which runs the package without installing it globally:
# No installation needed! uvx will handle everything
Benefits of using uvx:
- ✅ No global package installation required
- ✅ Automatic dependency management and isolation
- ✅ Always uses the latest version from PyPI
- ✅ Cleaner system without package conflicts
- ✅ uvx handles Python environment setup automatically
Prerequisites: Make sure you have uv installed. If not, install it with:
# On Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# On macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
From PyPI (Alternative)
If you prefer to install the package globally:
pip install winrm-mcp-server
From Source (Development)
- Clone this repository
- Install dependencies using
uv:
cd winrm-mcp-server
uv sync
Configuration
The server can be configured via VS Code's MCP configuration. Add the following to your VS Code settings or MCP configuration file:
Using uvx (Recommended Configuration)
{
"servers": {
"winrm-mcp-server": {
"command": "uvx",
"args": ["winrm-mcp-server"],
"env": {
"WINRM_MCP_HOSTNAME": "remote.host.com",
"WINRM_MCP_USERNAME": "username",
"WINRM_MCP_PASSWORD": "secret"
}
}
}
}
Using the installed package
{
"servers": {
"winrm-mcp-server": {
"command": "winrm-mcp-server",
"env": {
"WINRM_MCP_HOSTNAME": "remote.host.com",
"WINRM_MCP_USERNAME": "username",
"WINRM_MCP_PASSWORD": "secret"
}
}
}
}
Using from source (Development)
{
"servers": {
"winrm-mcp-server": {
"command": "python",
"args": ["run_server.py"],
"cwd": "/path/to/winrm-mcp-server",
"env": {
"WINRM_MCP_HOSTNAME": "remote.host.com",
"WINRM_MCP_USERNAME": "username",
"WINRM_MCP_PASSWORD": "secret"
}
}
}
}
Environment Variables
You can customize the server behavior using environment variables:
Required Variables:
WINRM_MCP_HOSTNAME: Target Windows hostname or IP address (required)WINRM_MCP_USERNAME: Username for authentication (required)WINRM_MCP_PASSWORD: Password for authentication (required)
Optional Variables:
WINRM_MCP_COMMAND_TIMEOUT: Command execution timeout in seconds (default: 300)WINRM_MCP_CONNECTION_PORT: Connection port to use (default: 5985 for HTTP, 5986 for HTTPS)WINRM_MCP_CONNECTION_TIMEOUT: Connection timeout in seconds (default: 30)WINRM_MCP_USE_HTTPS: Prefer HTTPS over HTTP (default: true)WINRM_MCP_SKIP_SSL_VERIFICATION: Skip SSL certificate verification (default: false)WINRM_MCP_MAX_RETRIES: Maximum retries for transient failures (default: 3)
Usage
The server exposes a single tool: execute_command
Parameters
command: PowerShell command to execute
Example
{
"tool": "execute_command",
"arguments": {
"command": "Get-Process | Select-Object Name, CPU | Sort-Object CPU -Descending | Select-Object -First 10"
}
}
Security Considerations
- Credentials are handled securely and not logged
- Supports both HTTP and HTTPS WinRM connections
- SSL certificate validation can be configured
- Command input is validated to prevent injection attacks
Requirements
Target Windows Machines
The target Windows machines must have WinRM enabled and configured:
# Enable WinRM
Enable-PSRemoting -Force
# Configure WinRM for HTTP (if needed)
winrm quickconfig
# Configure WinRM for HTTPS (recommended)
# (Requires SSL certificate configuration)
Network Requirements
- WinRM HTTP port (default: 5985) or HTTPS port (default: 5986) must be accessible
- Windows Firewall rules must allow WinRM traffic
Error Types
The server provides semantic error separation:
- ConnectionError: Network connectivity issues
- AuthenticationError: Invalid credentials or authentication failures
- CommandExecutionError: Command execution failures
- TimeoutError: Command execution timeouts
Development
Setting up the development environment
git clone https://github.com/antonvano-microsoft/winrm-mcp-server.git
cd winrm-mcp-server
uv sync --dev
Testing the package locally
You can test the package locally using uvx with the built distribution:
# Build the package first
uv build
# Test with uvx using the local wheel file
uvx --from ./dist/winrm_mcp_server-*.whl winrm-mcp-server
Running Tests
uv run pytest
Code Formatting
uv run black .
uv run isort .
Type Checking
uv run mypy .
Building and Publishing
To build the package:
uv build
To publish to PyPI (maintainers only):
uv publish
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate and follow the existing code style.
License
MIT License - see LICENSE file for details.
Metadata
Release files for winrm-mcp-server 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| winrm_mcp_server-0.1.3.tar.gz | 73.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| winrm_mcp_server-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 84.7 kB
Release files / winrm_mcp_server-0.1.3.tar.gz
| Download URL | winrm_mcp_server-0.1.3.tar.gz |
|---|---|
| Size | 73.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7175405174ae46069601e9c093c2b8e1074eef15cfd4d23d1418abf8af3fdab
|
|
BLAKE2b-256 checksum How to use checksums |
70bad6c0fbb8c012fd0f4304ce98f7a49a792ffabc572309fc881637261fcf47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.18
|
Release files / winrm_mcp_server-0.1.3-py3-none-any.whl
| Download URL | winrm_mcp_server-0.1.3-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fb8574ebfabb4a10cbbc6a79bcf993e4f9491987dd1a106b7a98919e5e1d995a
|
|
BLAKE2b-256 checksum How to use checksums |
396aadbd527cf03ae8c87f374409c2bbd11b5576f4ffa020356f2daad78e68ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.18
|
Security for winrm-mcp-server 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.