A powerful Model Context Protocol (MCP) server built with .NET 10 that enables AI-powered configuration and management of Windows Subsystem for Linux (WSL). Features intelligent agents using Microsoft Semantic Kernel and machine learning capabilities for optimization and predictions.
- Distribution Management: List, install, start, stop, export, and import WSL distributions
- Command Execution: Run commands in any WSL distribution
- Configuration: Modify WSL settings (memory, CPU, swap, etc.) via
.wslconfig - File Operations: Copy files between Windows and WSL filesystems
- System Information: Get detailed WSL version and status information
- Semantic Kernel Agents: Complex task planning and execution with natural language understanding
- Performance Analysis: ML-powered insights into WSL resource usage and bottlenecks
- Smart Recommendations: AI-generated optimization suggestions based on system metrics
- Resource Prediction: Predict resource requirements for different workload types
- Automated Task Planning: Break down complex operations into manageable steps
- Performance trend analysis
- Bottleneck detection
- Workload-specific resource recommendations
- Health scoring and diagnostics
- Windows 11 (22H2 or later recommended)
- WSL 2 installed and configured
- .NET 10 SDK
- (Optional) OpenAI API key for advanced agent features
cd d:\wsl-mcp-agentdotnet restoredotnet buildFor Semantic Kernel agent features, set environment variables:
$env:OPENAI_API_KEY = "your-api-key-here"Or use Azure OpenAI:
$env:AZURE_OPENAI_ENDPOINT = "your-endpoint"
$env:AZURE_OPENAI_KEY = "your-key"dotnet runList all installed WSL distributions with status information.
Arguments: None
Example Response:
[
{
"name": "Ubuntu",
"isDefault": true,
"state": "Running",
"version": "2"
}
]Get WSL version and system information.
Arguments: None
Install a new WSL distribution.
Arguments:
distro(string): Distribution name (e.g., "Ubuntu", "Debian", "Kali-Linux")
Start or wake up a WSL distribution.
Arguments:
distro(string): Distribution name to start
Stop/terminate a running WSL distribution.
Arguments:
distro(string): Distribution name to stop
Execute a command in a WSL distribution.
Arguments:
distro(string): Distribution namecommand(string): Command to execute
Example:
{
"distro": "Ubuntu",
"command": "uname -a"
}Configure WSL settings (memory, processors, swap, etc.).
Arguments:
settings(object): Configuration object
Example:
{
"settings": {
"memory": "8GB",
"processors": "4",
"swap": "4GB",
"localhostForwarding": "true"
}
}Export a WSL distribution to a tar file.
Arguments:
distro(string): Distribution nameoutput_path(string): Path for tar file (e.g., "C:\backups\ubuntu.tar")
Import a WSL distribution from a tar file.
Arguments:
distro(string): New distribution nametar_path(string): Path to tar fileinstall_path(string): Installation location
Copy files from WSL to Windows.
Arguments:
distro(string): Distribution namewsl_path(string): Source path in WSL (e.g., "/home/user/file.txt")windows_path(string): Destination in Windows (e.g., "C:\temp\file.txt")
Copy files from Windows to WSL.
Arguments:
distro(string): Distribution namewindows_path(string): Source path in Windowswsl_path(string): Destination in WSL
Use AI agent to perform complex WSL tasks with planning and reasoning.
Arguments:
task(string): Natural language task descriptioncontext(string, optional): Additional context or constraints
Example:
{
"task": "Set up a new Ubuntu distribution optimized for Docker development",
"context": "I need at least 16GB memory and want to enable systemd"
}Get AI-powered recommendations for WSL optimization.
Arguments:
distro(string, optional): Specific distribution name
Example Response:
{
"score": 75,
"items": [
{
"category": "Memory",
"priority": "High",
"title": "High Memory Usage Detected",
"description": "Current memory usage is 85%",
"action": "Add 'memory=8GB' to .wslconfig",
"expectedImpact": "Improved performance and reduced swapping"
}
]
}Analyze WSL performance and resource usage with ML insights.
Arguments:
distro(string, optional): Specific distribution name
Predict future resource requirements using ML.
Arguments:
distro(string): Distribution nameworkload(string): Workload description (e.g., "Docker containers", "ML training", "web development")
Example:
{
"distro": "Ubuntu",
"workload": "Running multiple Docker containers for microservices development"
}Example Response:
{
"recommendedMemoryGb": 16,
"recommendedCpuCores": 6,
"recommendedDiskGb": 100,
"confidence": 0.90,
"reasoning": "Container workloads require substantial resources"
}// List all distributions
{"tool": "wsl_list_distros"}
// Start Ubuntu
{"tool": "wsl_start_distro", "arguments": {"distro": "Ubuntu"}}
// Execute command
{"tool": "wsl_execute_command", "arguments": {
"distro": "Ubuntu",
"command": "df -h"
}}// Configure WSL for high-performance workloads
{"tool": "wsl_configure", "arguments": {
"settings": {
"memory": "16GB",
"processors": "8",
"swap": "8GB",
"nestedVirtualization": "true",
"vmIdleTimeout": "60000"
}
}}// Let the agent handle complex setup
{"tool": "wsl_agent_task", "arguments": {
"task": "Install and configure a new Debian distribution for Python data science work",
"context": "Need Jupyter, pandas, numpy, and scikit-learn"
}}
// Get performance recommendations
{"tool": "wsl_get_recommendations", "arguments": {
"distro": "Ubuntu"
}}
// Predict resources for workload
{"tool": "wsl_predict_resources", "arguments": {
"distro": "Ubuntu",
"workload": "Training machine learning models with TensorFlow"
}}// Export current distribution
{"tool": "wsl_export_distro", "arguments": {
"distro": "Ubuntu",
"output_path": "C:\\Backups\\ubuntu-backup.tar"
}}
// Import to new location
{"tool": "wsl_import_distro", "arguments": {
"distro": "Ubuntu-Dev",
"tar_path": "C:\\Backups\\ubuntu-backup.tar",
"install_path": "C:\\WSL\\Ubuntu-Dev"
}}- .NET 10: Latest .NET features including Native AOT support
- Model Context Protocol: MCP SDK for tool registration and communication
- Microsoft Semantic Kernel: AI agent orchestration and planning
- Microsoft.ML: Machine learning for predictions and recommendations
- Windows SDK: Native Windows integration
WslMcpServer/
โโโ Program.cs # MCP server initialization and tool registration
โโโ Services/
โ โโโ WslService.cs # Core WSL operations via wsl.exe
โโโ Agents/
โ โโโ WslAgentService.cs # Semantic Kernel agent integration
โ โโโ WslIntelligenceService.cs # ML-powered analytics and predictions
โโโ WslMcpServer.csproj # Project configuration
The server can modify %USERPROFILE%\.wslconfig:
[wsl2]
memory=8GB # Memory allocation
processors=4 # CPU cores
swap=4GB # Swap space
localhostForwarding=true
nestedVirtualization=true
vmIdleTimeout=60000
dnsTunneling=true # Improved network performanceOPENAI_API_KEY: OpenAI API key for agent featuresAZURE_OPENAI_ENDPOINT: Azure OpenAI endpointAZURE_OPENAI_KEY: Azure OpenAI key
Ensure WSL is installed:
wsl --installRun as Administrator if needed:
Start-Process powershell -Verb RunAs- Verify AI credentials are set
- Check network connectivity
- Review logs for detailed errors
dotnet publish -c Release -r win-x64 --self-containeddotnet testModify appsettings.json or set:
$env:DOTNET_ENVIRONMENT = "Development"See LICENSE file for details.
Contributions welcome! This project showcases:
- Latest .NET 10 features
- MCP server implementation
- AI agent integration with Semantic Kernel
- Windows ML capabilities
- WSL automation
- Automated Development Environments: Create consistent dev environments across teams
- CI/CD Integration: Manage WSL environments for build pipelines
- Multi-Distribution Testing: Test across different Linux distributions
- Resource Optimization: AI-powered resource allocation based on workload
- Disaster Recovery: Automated backup and restore procedures
- Performance Monitoring: Continuous analysis and optimization recommendations
Built with .NET 10 ๐ | Powered by AI ๐ค | For Windows 11 ๐ป