@liyu1981/mpf
v0.2.3
Published
Mosh Port Forwarding
Downloads
396
Maintainers
Readme
mpf: Mosh Port Forwarding
mpf is a tool designed to solve a common problem: "How can I use port forwarding with Mosh?" Inspired by VS Code's port forwarding feature, mpf acts as a lightweight wrapper for Mosh, adding persistent and dynamic TCP port forwarding. It also maintains a mobile-friendly connection for your forwarded ports.
Demo

Features
- Persistent Port Forwarding: Port forwards are saved to
~/.mpf/forwards.jsonand automatically restored across sessions. - Auto Forwarding: Automatically monitors and forwards newly opened ports.
- Dynamic Forwarding: Add or remove port forwards on-the-fly without restarting your session.
- Reliable Tunnel: High-performance UDP transport with great resilience (powered by QUIC) and automatic fallback to TCP.
Use & Installation
1. Via npx (Recommended)
Run mpf directly using npx without manual installation:
npx @liyu1981/mpf mosh user@hostname2. Via Shell Script
Install mpf to ~/.local/bin using the following command:
curl -fsSL https://raw.githubusercontent.com/liyu1981/moshpf/main/install.sh | bash3. Binary Download
Download pre-compiled binaries from the Releases page.
4. From Source (Go)
If you have Go 1.25+ installed, you can install it via:
go install github.com/liyu1981/moshpf/cmd/moshpf@latest
# The binary will be named 'moshpf'; you may want to alias it to 'mpf'Alternatively, clone the repository and build it:
git clone https://github.com/liyu1981/moshpf.git
cd moshpf
go build -o mpf ./cmd/moshpf/main.goSupported Platforms
mpf supports the following platforms and architectures:
- Linux: amd64, arm64
- macOS (Darwin): arm64
Note: only Linux with amd64 architecture is tested in real usage and others are built with golang's cross compilation. There may be issue in those platforms I do not know. If you find an issue please create an issue or a PR.
Basic Usage
Basic usage is as simple as prefixing mpf to your usual Mosh commands, as shown in the example below:
mpf mosh user@hostname -- tmuxMost of the time, this is all you will need.
Advanced Usage Options
Manage Port Forwards
On the remote side (the machine you joined via Mosh), use the forward, list, and close subcommands to manage port forwards.
Forward a port:
mpf forward 8080
# or with explicit mapping (remote:local)
mpf forward 20000:8080Note: mpf forward 20000:8080 means the local machine listens on port 8080 and forwards to the remote port 20000.
List active forwards:
mpf listClose a forward:
mpf close 8080Choose QUIC or TCP Transport
mpf establishes two types of connections for the tunnel:
- QUIC: A high-performance UDP-based tunnel providing superior support for mobile connections.
- TCP: A reliable control and data tunnel established over SSH.
By default, mpf attempts to establish a QUIC connection and falls back to TCP if it fails. You can control this behavior with flags:
--quic: Force QUIC transport only.--tcp: Force TCP transport only.
Architecture
- Bootstrap:
mpfconnects via SSH, ensures thempfagent is present on the remote host, and starts it. - Tunneling: A QUIC or Yamux session is established using the SSH-started agent's stdin/stdout.
- Mosh Handover:
mpfexecutes the systemmoshbinary. - Supervision: The
mpfparent process remains running to manage the tunnel and listeners, monitoring the connection with heartbeats. - Reconnection: If the tunnel drops,
mpfautomatically re-establishes the connection in the background. - Persistence: Requested ports are stored in
~/.mpf/forwards.jsonand are restored whenever you reconnect to that specificuser@host.
Requirements
mosh(client and server)- SSH access to the remote host (SSH keys recommended)
- Go 1.25+ (if building from source)
License
GPLv3. See LICENSE for details.
