ssh_tunnel_close
Close SSH tunnels to terminate secure remote connections and free up network resources in the MCP SSH Manager.
Instructions
Close an SSH tunnel
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tunnelId | No | Tunnel ID to close | |
| server | No | Close all tunnels for this server |
Implementation Reference
- src/tunnel-manager.js:514-523 (handler)Main execution handler for ssh_tunnel_close tool. Accepts tunnelId parameter, retrieves the tunnel instance from the active tunnels map, calls its close() method if found, and returns true on success.export function closeTunnel(tunnelId) { const tunnel = tunnels.get(tunnelId); if (!tunnel) { throw new Error(`Tunnel ${tunnelId} not found`); } tunnel.close(); return true; }
- src/tunnel-manager.js:378-401 (helper)Core close logic in SSHTunnel class. Sets state to CLOSED, closes all connections and server socket, handles remote forwarding cleanup, and removes from active tunnels map.close() { logger.info(`Closing tunnel ${this.id}`); this.state = TUNNEL_STATES.CLOSED; // Close all active connections for (const conn of this.connections) { conn.destroy(); } this.connections.clear(); // Close server if (this.server) { this.server.close(); this.server = null; } // Cancel remote forwarding if needed if (this.type === TUNNEL_TYPES.REMOTE) { this.ssh.unforwardIn(this.config.remoteHost, this.config.remotePort); } tunnels.delete(this.id); }
- src/tool-registry.js:58-72 (registration)ssh_tunnel_close is registered in the 'advanced' tool group (line 67) for conditional enabling/disabling via tool configuration manager.'ssh_deploy', 'ssh_execute_sudo', 'ssh_alias', 'ssh_command_alias', 'ssh_hooks', 'ssh_profile', 'ssh_connection_status', 'ssh_tunnel_create', 'ssh_tunnel_list', 'ssh_tunnel_close', 'ssh_key_manage', 'ssh_execute_group', 'ssh_group_manage', 'ssh_history' ]