Skip to main content

Create SSH Tunnels to your remote hosts and host as an MCP Server for Agentic AI!

Project description

Tunnel Manager

PyPI - Version PyPI - Downloads GitHub Repo stars GitHub forks GitHub contributors PyPI - License GitHub

GitHub last commit (by committer) GitHub pull requests GitHub closed pull requests GitHub issues

GitHub top language GitHub language count GitHub repo size GitHub repo file count (file type) PyPI - Wheel PyPI - Implementation

Version: 0.0.4

This project provides a Python-based Tunnel class for secure SSH connections and file transfers, integrated with a FastMCP server (tunnel_mcp.py) to expose these capabilities as tools for AI-driven workflows. The implementation supports both standard SSH (e.g., for local networks) and Teleport's secure access platform, leveraging the paramiko library for SSH operations.

Features

Tunnel Class

  • Purpose: Facilitates secure SSH connections and file transfers to remote hosts.
  • Key Functionality:
    • Run Remote Commands: Execute shell commands on a remote host and retrieve output.
    • File Upload/Download: Transfer files to/from a remote host using SFTP.
    • Teleport Support: Seamlessly integrates with Teleport's certificate-based authentication and proxying.
    • Configuration Flexibility: Loads SSH settings from ~/.ssh/config by default, with optional overrides for identity files, certificates, and proxy commands.
    • Logging: Optional file-based logging for debugging and auditing.

FastMCP Server

  • Purpose: Exposes Tunnel class functionality as a FastMCP server, enabling AI tools to perform remote operations programmatically.
  • Tools Provided:
    • run_remote_command: Runs a shell command on a remote host and returns output.
    • upload_file: Uploads a file to a remote host via SFTP.
    • download_file: Downloads a file from a remote host via SFTP.
  • Transport Options: Supports stdio (for local scripting) and http (for networked access) transport modes.
  • Progress Reporting: Integrates with FastMCP's Context for progress updates during operations.
  • Logging: Comprehensive logging to a file (tunnel_mcp.log by default).
Usage:

Tunnel Class

The Tunnel class can be used standalone for SSH operations. Example:

from tunnel_manager import Tunnel

# Initialize with a remote host (assumes ~/.ssh/config or explicit params)
tunnel = Tunnel(
    remote_host="example.com",
    identity_file="/path/to/id_rsa",
    certificate_file="/path/to/cert",  # Optional for Teleport
    proxy_command="tsh proxy ssh %h",  # Optional for Teleport
    log_file="tunnel.log"
)

# Connect and run a command
tunnel.connect()
out, err = tunnel.run_command("ls -la /tmp")
print(f"Output: {out}\nError: {err}")

# Upload a file
tunnel.send_file("/local/file.txt", "/remote/file.txt")

# Download a file
tunnel.receive_file("/remote/file.txt", "/local/downloaded.txt")

# Close the connection
tunnel.close()

FastMCP Server

The FastMCP server exposes the Tunnel functionality as AI-accessible tools. Start the server with:

python tunnel_mcp.py --transport stdio

Or for HTTP transport:

python tunnel_mcp.py --transport http --host 127.0.0.1 --port 8080
Installation Instructions:

Use with AI

Configure mcp.json

{
  "mcpServers": {
    "tunnel_manager": {
      "command": "uv",
      "args": [
        "run",
        "--with",
        "tunnel-manager",
        "tunnel-manager-mcp"
      ],
      "env": {
        "TUNNEL_REMOTE_HOST": "user@192.168.1.12", // Optional
        "TUNNEL_REMOTE_PORT": "22",                // Optional
        "TUNNEL_IDENTITY_FILE": "",                // Optional
        "TUNNEL_CERTIFICATE": "",                  // Optional
        "TUNNEL_PROXY_COMMAND": "",                // Optional
        "TUNNEL_LOG_FILE": "~./tunnel_log.txt"     // Optional
      },
      "timeout": 200000
    }
  }
}

Deploy MCP Server as a container

docker pull knucklessg1/tunnel-manager:latest

Modify the compose.yml

services:
  tunnel-manager:
    image: knucklessg1/tunnel-manager:latest
    environment:
      - HOST=0.0.0.0
      - PORT=8021
    ports:
      - 8021:8021

Install Python Package

python -m pip install tunnel-manager

or

uv pip install --upgrade tunnel-manager
Repository Owners:

GitHub followers GitHub User's stars

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tunnel_manager-0.0.4.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tunnel_manager-0.0.4-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file tunnel_manager-0.0.4.tar.gz.

File metadata

  • Download URL: tunnel_manager-0.0.4.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for tunnel_manager-0.0.4.tar.gz
Algorithm Hash digest
SHA256 7c1383252861c1f819f26f2009b8f4f1f28873755381b76d7f4b2cbc9ae2be70
MD5 e75863a1235b871e998cd098df2ccc89
BLAKE2b-256 a20e8cb8564f6b7da7059c0ea3e976a3461823c854224bb1b6bd953b2158a9b0

See more details on using hashes here.

File details

Details for the file tunnel_manager-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: tunnel_manager-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for tunnel_manager-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8f588a6c1f8fcd5ebd1f403654887e20579cdbbc468cf7596626cf082b7e2729
MD5 ea61666a923792bafd67ac3ed0fd5b97
BLAKE2b-256 03e926e72ff1bf016ac36b238ad6e5f97a2f84c22aee32a0708db99dd421fb63

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page