list_sessions
View all active SSH connections to monitor and manage remote host sessions established through the MCP SSH Session server.
Instructions
List all active SSH sessions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp_ssh_session/server.py:115-126 (handler)MCP tool handler for 'list_sessions'. Lists active SSH sessions using session_manager, formats the output as a bullet list or 'No active sessions' message, and returns it as a string.@mcp.tool() def list_sessions() -> str: """List all active SSH sessions.""" logger = session_manager.logger.getChild('tool_list_sessions') logger.info("Listing active SSH sessions.") sessions = session_manager.list_sessions() if sessions: response = "Active SSH Sessions:\n" + "\n".join(f"- {s}" for s in sessions) else: response = "No active SSH sessions" logger.debug(f"Response: {response}") return response
- Helper method in SSHSessionManager class that returns a list of active SSH session keys (formatted as username@host:port) from the internal _sessions dictionary.def list_sessions(self) -> list[str]: """List all active session keys.""" logger = self.logger.getChild('list_sessions') with self._lock: sessions = list(self._sessions.keys()) logger.info(f"Listing {len(sessions)} active sessions.") logger.debug(f"Active sessions: {sessions}") return sessions