Rustunnel - Secure Tunnel Management
Expose local services (HTTP/TCP) through public URLs using rustunnel. Perfect for testing webhooks, sharing local development, and deployment workflows.
When to Use
- - Webhook testing - Expose local server to receive webhooks from external services
- Demo sharing - Share local development with stakeholders
- CI/CD integration - Expose preview environments
- Database access - Expose local TCP services (PostgreSQL, Redis, etc.)
- Mobile testing - Test mobile apps against local backend
⚠️ IMPORTANT: Use MCP Tools, Not CLI
Always use MCP tools for tunnel management. They handle lifecycle automatically.
| Method | Lifecycle | Recommended |
|---|
| MCP tools (createtunnel, closetunnel) | Automatic cleanup | ✅ Yes |
| CLI (rustunnel http 3000) |
Manual process management | ❌ Only for cloud sandboxes |
Why MCP tools?
- - Automatic cleanup when closed
- No orphaned processes
- Proper tunnel lifecycle management
- Returns tunnel_id for tracking
Configuration File
Location: INLINECODE0
This file stores your server address and auth token. The agent will read from this file instead of asking every time.
Format:
CODEBLOCK0
First-Time Setup
Before using tunnels, ensure config exists:
- 1. Check if config file exists: INLINECODE1
- If not, ask user: "What's your rustunnel auth token and server address?"
- Create config file directly:
mkdir -p ~/.rustunnel
chmod 700 ~/.rustunnel
- 4. Write config with user's token:
server: <user-provided-server>
auth_token: <user-provided-token>
- 5. Set permissions: INLINECODE2
Agent Workflow
Always follow this sequence:
Step 1: Check Config
CODEBLOCK3
If config exists with auth_token: Read token and proceed.
If config missing:
- 1. Ask user: "What's your rustunnel auth token and server address?"
- Create config file directly:
mkdir -p ~/.rustunnel
chmod 700 ~/.rustunnel
- 3. Write config with user's token:
server: <user-provided-server>
auth_token: <user-provided-token>
- 4. Set permissions: INLINECODE3
Step 2: Read Token from Config
When making tool calls, read auth_token from ~/.rustunnel/config.yml:
CODEBLOCK6
Use these values in tool calls - don't ask the user every time.
Step 3: Use MCP Tools
With token from config, call MCP tools directly.
MCP Tools (Recommended)
create_tunnel
Expose a local port and get a public URL.
Parameters:
| Param | Type | Required | Description |
|---|
| INLINECODE6 | string | yes | API token (read from config) |
| INLINECODE7 |
integer | yes | Local port to expose |
|
protocol | "http" \| "tcp" | yes | Tunnel type |
|
subdomain | string | no | Custom subdomain (HTTP only) |
|
region | string | no | Region ID (e.g.
"eu",
"us",
"ap"). Omit to auto-select. Use
list_regions to see options. |
Returns:
CODEBLOCK7
Lifecycle: Tunnel stays open until close_tunnel is called or MCP server exits.
close_tunnel
Close a tunnel by ID. Public URL stops working immediately.
Parameters:
| Param | Type | Required | Description |
|---|
| INLINECODE16 | string | yes | API token |
| INLINECODE17 |
string | yes | UUID from create_tunnel |
This is the proper way to close tunnels. No orphaned processes.
list_tunnels
List all currently active tunnels.
Parameters:
| Param | Type | Required | Description |
|---|
| INLINECODE18 | string | yes | API token (read from config) |
Returns: JSON array of tunnel objects.
gettunnelhistory
Retrieve history of past tunnels.
Parameters:
| Param | Type | Required | Description |
|---|
| INLINECODE19 | string | yes | API token |
| INLINECODE20 |
"http" \| "tcp" | no | Filter by protocol |
|
limit | integer | no | Max entries (default: 25) |
list_regions
List available tunnel server regions. No authentication required.
Parameters: None
Returns: JSON array of region objects:
CODEBLOCK8
getconnectioninfo
Returns the CLI command string without spawning anything. Use when MCP can't
spawn subprocesses (cloud sandboxes, containers) or you prefer running the CLI yourself.
Parameters:
| Param | Type | Required | Description |
|---|
| INLINECODE22 | string | yes | API token |
| INLINECODE23 |
integer | yes | Local port to expose |
|
protocol | "http" \| "tcp" | yes | Tunnel type |
|
region | string | no | Region ID (e.g.
"eu"). Omit to auto-select. |
Returns:
{
"cli_command": "rustunnel http 3000 --server edge.rustunnel.com:4040 --token abc123",
"server": "edge.rustunnel.com:4040",
"install_url": "https://github.com/joaoh82/rustunnel/releases/latest"
}
Common Workflows
Common Workflows
1. Expose Local API (MCP Tools)
CODEBLOCK10
2. Custom Subdomain
CODEBLOCK11
3. TCP Tunnel (Database)
CODEBLOCK12
4. Cloud Sandbox (CLI Fallback)
CODEBLOCK13
Prerequisites
- 1. Rustunnel MCP server installed:
CODEBLOCK14
- 2. Config file:
~/.rustunnel/config.yml with auth_token set
MCP Configuration
Add to your MCP client config:
CODEBLOCK15
Note: The MCP server address should match the server in ~/.rustunnel/config.yml.
Architecture
CODEBLOCK16
Security Notes
- - Tokens are sent over HTTPS (use
--insecure only in local dev) - MCP tools handle process cleanup automatically
- Tunnels are closed when MCP server exits
- Config file should be protected: INLINECODE32
Related Skills
- - vercel-deploy - Deploy to Vercel for production hosting
- here-now - Instant static file hosting
- backend - Backend service patterns
- nodejs-patterns - Node.js deployment patterns
Resources
Rustunnel - 安全隧道管理
使用 rustunnel 通过公共 URL 暴露本地服务(HTTP/TCP)。非常适合测试 Webhook、共享本地开发环境以及部署工作流。
使用场景
- - Webhook 测试 - 暴露本地服务器以接收来自外部服务的 Webhook
- 演示共享 - 与利益相关者共享本地开发环境
- CI/CD 集成 - 暴露预览环境
- 数据库访问 - 暴露本地 TCP 服务(PostgreSQL、Redis 等)
- 移动端测试 - 针对本地后端测试移动应用
⚠️ 重要提示:使用 MCP 工具,而非 CLI
始终使用 MCP 工具进行隧道管理。 它们会自动处理生命周期。
| 方法 | 生命周期 | 推荐 |
|---|
| MCP 工具(createtunnel、closetunnel) | 自动清理 | ✅ 是 |
| CLI(rustunnel http 3000) |
手动进程管理 | ❌ 仅限云沙箱 |
为什么选择 MCP 工具?
- - 关闭时自动清理
- 无孤立进程
- 正确的隧道生命周期管理
- 返回 tunnel_id 用于跟踪
配置文件
位置: ~/.rustunnel/config.yml
此文件存储您的服务器地址和认证令牌。代理将从此文件读取,而不是每次都询问。
格式:
yaml
rustunnel 配置
文档:https://github.com/joaoh82/rustunnel
server: edge.rustunnel.com:4040
auth_token: your-token-here
tunnels:
expense_tracker:
proto: http
local_port: 3000
# api:
# proto: http
# local_port: 8080
# subdomain: myapi
首次设置
使用隧道前,请确保配置文件存在:
- 1. 检查配置文件是否存在: ~/.rustunnel/config.yml
- 如果不存在,询问用户: 您的 rustunnel 认证令牌和服务器地址是什么?
- 直接创建配置文件:
bash
mkdir -p ~/.rustunnel
chmod 700 ~/.rustunnel
- 4. 使用用户的令牌写入配置:
yaml
server: <用户提供的服务器>
auth_token: <用户提供的令牌>
- 5. 设置权限: chmod 600 ~/.rustunnel/config.yml
代理工作流
始终遵循以下顺序:
步骤 1:检查配置
bash
检查配置是否存在
cat ~/.rustunnel/config.yml
如果配置存在且包含 auth_token: 读取令牌并继续。
如果配置缺失:
- 1. 询问用户:您的 rustunnel 认证令牌和服务器地址是什么?
- 直接创建配置文件:
bash
mkdir -p ~/.rustunnel
chmod 700 ~/.rustunnel
- 3. 使用用户的令牌写入配置:
yaml
server: <用户提供的服务器>
auth_token: <用户提供的令牌>
- 4. 设置权限:chmod 600 ~/.rustunnel/config.yml
步骤 2:从配置读取令牌
进行工具调用时,从 ~/.rustunnel/config.yml 读取 auth_token:
yaml
auth_token: your-token-here
server: edge.rustunnel.com:4040
在工具调用中使用这些值 - 不要每次都询问用户。
步骤 3:使用 MCP 工具
使用从配置中获取的令牌,直接调用 MCP 工具。
MCP 工具(推荐)
create_tunnel
暴露本地端口并获取公共 URL。
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|
| token | 字符串 | 是 | API 令牌(从配置读取) |
| local_port |
整数 | 是 | 要暴露的本地端口 |
| protocol | http \| tcp | 是 | 隧道类型 |
| subdomain | 字符串 | 否 | 自定义子域名(仅限 HTTP) |
| region | 字符串 | 否 | 区域 ID(例如 eu、us、ap)。省略则自动选择。使用 list_regions 查看选项。 |
返回:
json
{
public_url: https://abc123.edge.rustunnel.com,
tunnel_id: a1b2c3d4-...,
protocol: http
}
生命周期: 隧道保持开放,直到调用 close_tunnel 或 MCP 服务器退出。
close_tunnel
通过 ID 关闭隧道。公共 URL 立即停止工作。
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|
| token | 字符串 | 是 | API 令牌 |
| tunnelid |
字符串 | 是 | 来自 createtunnel 的 UUID |
这是关闭隧道的正确方式。 无孤立进程。
list_tunnels
列出所有当前活动的隧道。
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|
| token | 字符串 | 是 | API 令牌(从配置读取) |
返回: 隧道对象的 JSON 数组。
gettunnelhistory
检索过去隧道的历史记录。
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|
| token | 字符串 | 是 | API 令牌 |
| protocol |
http \| tcp | 否 | 按协议筛选 |
| limit | 整数 | 否 | 最大条目数(默认:25) |
list_regions
列出可用的隧道服务器区域。无需认证。
参数: 无
返回: 区域对象的 JSON 数组:
json
[
{ id: eu, name: Europe, location: Helsinki, FI, host: eu.edge.rustunnel.com, control_port: 4040, active: true }
]
getconnectioninfo
返回 CLI 命令字符串,不启动任何进程。当 MCP 无法生成子进程(云沙箱、容器)或您更愿意自己运行 CLI 时使用。
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|
| token | 字符串 | 是 | API 令牌 |
| local_port |
整数 | 是 | 要暴露的本地端口 |
| protocol | http \| tcp | 是 | 隧道类型 |
| region | 字符串 | 否 | 区域 ID(例如 eu)。省略则自动选择。 |
返回:
json
{
cli_command: rustunnel http 3000 --server edge.rustunnel.com:4040 --token abc123,
server: edge.rustunnel.com:4040,
install_url: https://github.com/joaoh82/rustunnel/releases/latest
}
常见工作流
常见工作流
1. 暴露本地 API(MCP 工具)
- 1. 从 ~/.rustunnel/config.yml 读取 authtoken
- 创建隧道:createtunnel(token, localport=3000, protocol=http)
- 存储 tunnelid 以便后续清理
- 向用户返回 publicurl
- 完成后:closetunnel(token, tunnel_id)
2. 自定义子域名
- 1. 从配置读取 authtoken
- createtunnel(token, localport=5173, protocol=http, subdomain=myapp-preview)
- 返回 URL:https://myapp-preview.edge.rustunnel.com
- 完成后 closetunnel(token, tunnel_id)
3. TCP 隧道(数据库)
- 1. 从配置读取 authtoken
- createtunnel(token, localport=5432, protocol=tcp)
- 返回 tcp://host:port 用于连接
- 完成后 closetunnel(token, tunnel_id)
4. 云沙箱(CLI 回退)
- 1. 从配置读取 authtoken
- getconnectioninfo(token, localport=3000, protocol=http)
- 输出 CLI 命令供用户在本地运行
- 用户运行命令
- listtunnels(token) 验证并获取 publicurl
- 完成后,用户按 Ctrl+C 终止 CLI 进程
先决条件
- 1. 已安装