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.5

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.5.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.5-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tunnel_manager-0.0.5.tar.gz
Algorithm Hash digest
SHA256 a6433935fecaf98e964e6f2a895fb316fc0876dbf8820129aa937fdbe245abf3
MD5 c9bb416a9d461dc82cd5bd7ccffae1ee
BLAKE2b-256 ceaf3cdbbe1b026d3bd4c95a1fc97804f4ad7ce7b34d51060e636b63658da377

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tunnel_manager-0.0.5-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.12.3

File hashes

Hashes for tunnel_manager-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e05ffaedb7b477accd4be00b39848323de31ab9e8d6632fba8ed9df3bc10bf01
MD5 269cbca689963bf1740d5093e49f1a74
BLAKE2b-256 4e0a2f9a9d7431edf31e4ce6a89e3fa649fa3368dac9385efe0bed37bcc1ca10

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