This guide helps you set up Foundries VPN for use with the MCP Remote Testing server.
Foundries VPN uses WireGuard but with a server-based architecture where devices connect to a centralized VPN server managed by FoundriesFactory. This is different from standard WireGuard (peer-to-peer).
Key Differences:
- Standard WireGuard: Direct peer-to-peer connections
- Foundries VPN: Server-based (devices → VPN Server → Client)
fioctl is the Foundries.io command-line tool for managing FoundriesFactory.
Installation:
Linux (using Go):
# Install Go if not already installed
sudo apt install golang-go # Debian/Ubuntu
# or
sudo yum install golang # RHEL/CentOS
# Install fioctl
go install github.com/foundriesio/fioctl@latest
# Add Go bin to PATH (if not already)
export PATH=$PATH:$(go env GOPATH)/bin
echo 'export PATH=$PATH:$(go env GOPATH)/bin' >> ~/.bashrcLinux (using pre-built binary):
# Download latest release from GitHub
wget https://github.com/foundriesio/fioctl/releases/latest/download/fioctl-linux-amd64
chmod +x fioctl-linux-amd64
sudo mv fioctl-linux-amd64 /usr/local/bin/fioctlmacOS:
brew install fioctlWindows: Download from: https://github.com/foundriesio/fioctl/releases
Verify Installation:
fioctl --versionAfter installing fioctl, configure it with your FoundriesFactory credentials:
fioctl loginThis will:
- Open a browser for OAuth2 authentication
- Store credentials securely
- Configure default factory (if you have access to multiple factories)
Verify Configuration:
fioctl factories listIf configured correctly, this will list your accessible factories.
Foundries VPN still uses WireGuard, so you need WireGuard tools installed:
Debian/Ubuntu:
sudo apt update
sudo apt install wireguard-toolsRHEL/CentOS:
sudo yum install wireguard-toolsArch Linux:
sudo pacman -S wireguard-toolsmacOS:
brew install wireguard-toolsUse fioctl to enable WireGuard VPN on your Foundries devices:
fioctl devices config wireguard <device-name> enableExample:
fioctl devices config wireguard my-device-01 enableNote: Configuration changes are applied via OTA update, which may take up to 5 minutes.
Get the WireGuard configuration file from FoundriesFactory:
Option A: FoundriesFactory Web Interface
- Log in to FoundriesFactory
- Navigate to Remote Access / VPN section
- Download WireGuard configuration file
Option B: FoundriesFactory API Use the FoundriesFactory API to retrieve VPN configuration.
Option C: VPN Server Admin Contact your Foundries VPN server administrator for the configuration file.
The MCP server automatically searches for Foundries VPN config files in this order:
- Environment Variable:
FOUNDRIES_VPN_CONFIG_PATH(if set) - Secrets Directory:
{LAB_TESTING_ROOT}/secrets/foundries-vpn.conforfoundries.conf - User Config:
~/.config/wireguard/foundries.conf - System Config:
/etc/wireguard/foundries.conf
Recommended Locations:
~/.config/wireguard/foundries.conf(user-specific){LAB_TESTING_ROOT}/secrets/foundries-vpn.conf(project-specific)
Set Secure Permissions:
chmod 600 ~/.config/wireguard/foundries.confUsing Environment Variable:
export FOUNDRIES_VPN_CONFIG_PATH=/path/to/your/foundries.confOr in Cursor MCP config:
{
"mcpServers": {
"ai-lab-testing": {
"command": "python3.10",
"args": ["/path/to/lab_testing/server.py"],
"env": {
"LAB_TESTING_ROOT": "/path/to/ai-lab-testing",
"FOUNDRIES_VPN_CONFIG_PATH": "/path/to/foundries.conf"
}
}
}
}Using MCP Tools (Recommended):
# Check VPN status
foundries_vpn_status()
# Connect to VPN (auto-detects config)
connect_foundries_vpn()
# Or specify config path
connect_foundries_vpn(config_path="/path/to/foundries.conf")Using NetworkManager (No Root Required):
# Import config
nmcli connection import type wireguard file ~/.config/wireguard/foundries.conf
# Connect
nmcli connection up foundriesUsing wg-quick (Requires Root):
sudo wg-quick up ~/.config/wireguard/foundries.confCheck VPN Status:
# Using MCP tool
foundries_vpn_status()
# Or manually
wg show
nmcli connection show --active | grep wireguardList Foundries Devices:
# Using MCP tool
list_foundries_devices()Access Devices: Once connected, devices should be accessible via the Foundries VPN server:
ssh <device-name>The MCP server provides tools to manage Foundries VPN:
foundries_vpn_status()- Checks if fioctl is installed and configured
- Checks WireGuard connection status
- Provides helpful suggestions if prerequisites are missing
list_foundries_devices()
# Or with specific factory
list_foundries_devices(factory="my-factory")- Lists devices in FoundriesFactory
- Shows devices with WireGuard enabled
enable_foundries_vpn_device(device_name="my-device")
# Or with specific factory
enable_foundries_vpn_device(device_name="my-device", factory="my-factory")- Enables WireGuard VPN on a device
- Configuration applied via OTA update (up to 5 minutes)
disable_foundries_vpn_device(device_name="my-device")- Disables WireGuard VPN on a device
- Configuration applied via OTA update (up to 5 minutes)
connect_foundries_vpn()
# Or with specific config path
connect_foundries_vpn(config_path="/path/to/foundries.conf")- Connects to Foundries VPN server
- Auto-detects config file if not specified
Important: By default, the Foundries WireGuard server daemon (factory-wireguard-server) configures devices with restrictive allowed-ips (/32 - only their own IP), preventing peer-to-peer communication. This is a security feature, but for development environments, you may want to enable full network access.
Root Cause: The daemon code sets AllowedIPs = {ip} (line 257 in factory-wireguard.py), which creates /32 restrictions. The daemon also regenerates the config periodically, overwriting manual changes.
Solution: Modify Daemon Code for Development
On the VPN server (gateway container), modify the daemon code:
-
Edit the daemon script:
# On VPN server cd /root/factory-wireguard-server # Edit factory-wireguard.py line 257
-
Change line 257 from:
AllowedIPs = {ip}
To:
AllowedIPs = 10.42.42.0/24
-
Restart the daemon:
# If using systemd systemctl restart factory-vpn-<factory>.service # Or if running manually pkill -f factory-wireguard.py # Then restart the daemon process
-
Add client peer manually:
# Get client public key (see "Finding Your Client Key" below) wg set factory peer <CLIENT_PUBLIC_KEY> allowed-ips 10.42.42.0/24 wg-quick save factory
Note: The client peer is NOT managed by the daemon, so it must be added manually and will persist. Device peers will now be configured with full network access (10.42.42.0/24) by the daemon.
The client key (also called "client public key") is your WireGuard public key. It's derived from your private key and is used to identify your client peer on the VPN server.
How to find your client public key:
Method 1: From your WireGuard config file
# Your config file contains your private key
# Extract the public key from it:
cat ~/.config/wireguard/foundries.conf | grep -A 1 "\[Interface\]" | grep "PrivateKey" | awk '{print $3}' | wg pubkeyMethod 2: Generate from private key file
# If you have your private key saved separately
cat /path/to/privatekey | wg pubkeyMethod 3: From WireGuard status (if connected)
# When connected, check your public key
wg show | grep "public key"Method 4: Generate new key pair
# Generate new private/public key pair
wg genkey | tee /tmp/privatekey | wg pubkey > /tmp/publickey
# View your public key (share this with VPN admin)
cat /tmp/publickey
# Example output:
# mzHaZPGowqqzAa5tVFQJs0zoWuDVLppt44HwgdcPXkg=What the client key looks like:
- Base64-encoded string
- Example:
mzHaZPGowqqzAa5tVFQJs0zoWuDVLppt44HwgdcPXkg= - Always ends with
= - About 44 characters long
Where it's used:
- Added to VPN server as a peer:
wg set factory peer <CLIENT_PUBLIC_KEY> allowed-ips 10.42.42.0/24 - Identifies your client machine on the VPN network
- Must be shared with VPN server administrator to get access
Security Note:
- The public key is safe to share (it's public!)
- The private key must be kept secret (never share it)
- Your private key is in your WireGuard config file (
PrivateKey = ...)
Error: fioctl not found in PATH
Solution:
- Install fioctl (see Installation section above)
- Verify installation:
fioctl --version - Ensure fioctl is in your PATH
Error: fioctl not configured. Run 'fioctl login'
Solution:
- Run
fioctl loginto configure credentials - Verify:
fioctl factories list - Ensure you have access to FoundriesFactory
Error: Foundries VPN configuration file not found
Solution:
- Obtain WireGuard config from FoundriesFactory
- Save config to one of these locations (searched in order):
- Set
FOUNDRIES_VPN_CONFIG_PATHenvironment variable {LAB_TESTING_ROOT}/secrets/foundries-vpn.conforfoundries.conf~/.config/wireguard/foundries.conf/etc/wireguard/foundries.conf
- Set
- Or provide
config_pathparameter toconnect_foundries_vpn() - Verify config file exists and has correct permissions (
chmod 600)
Error: Failed to enable WireGuard VPN on device 'device-name'
Solution:
- Verify device name:
list_foundries_devices() - Check device exists in factory
- Ensure you have permissions to configure devices
Error: Failed to connect to Foundries VPN
Solution:
- Check VPN config file is valid
- Verify VPN server is accessible
- Check WireGuard tools are installed
- Try NetworkManager method if wg-quick fails
| Aspect | Standard WireGuard | Foundries VPN |
|---|---|---|
| Architecture | Peer-to-peer | Server-based |
| Configuration | Manual config files | Managed via FoundriesFactory |
| Device Management | Manual peer management | Automated via fioctl |
| Connection Model | Direct device-to-device | Device → VPN Server → Client |
-
Use fioctl for Device Management
- Enable/disable VPN on devices via
fioctl devices config wireguard - List devices via
fioctl devices list
- Enable/disable VPN on devices via
-
Use MCP Tools for VPN Connection
- Check status before connecting
- Auto-detect config files
- Get helpful error messages and suggestions
-
Wait for OTA Updates
- Device VPN configuration changes take up to 5 minutes
- Check device status after enabling VPN
-
Secure Configuration Files
- Set permissions:
chmod 600on VPN config files - Store configs in secure locations
- Set permissions:
-
Use NetworkManager When Possible
- Allows connecting without root privileges
- Better integration with system networking
- fioctl Documentation: https://docs.foundries.io/latest/reference-manual/fioctl/
- Foundries VPN Documentation: https://docs.foundries.io/latest/reference-manual/remote-access/wireguard.html
- fioctl GitHub: https://github.com/foundriesio/fioctl
- Foundries VPN Server: https://github.com/foundriesio/factory-wireguard-server
Foundries VPN setup requires:
- ✅ Install
fioctlCLI tool - ✅ Configure
fioctlwithfioctl login - ✅ Install WireGuard tools
- ✅ Enable VPN on devices via
fioctl - ✅ Obtain VPN config from FoundriesFactory
- ✅ Connect using MCP tools or manual methods
The MCP server provides tools to simplify this process and guide you through each step.