ssh_list_sessions
Retrieve a list of all active SSH sessions to monitor and manage connections efficiently using the SSH MCP Server.
Instructions
모든 활성 SSH 세션 목록 조회
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "ssh_list_sessions"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- main.py:270-293 (handler)The main handler function implementing the ssh_list_sessions MCP tool. It retrieves the list of active sessions from the SSHSessionManager and formats them into a readable string output.
async def ssh_list_sessions() -> str: """모든 활성 SSH 세션 목록 조회""" try: sessions = await ssh_manager.list_sessions() if not sessions: return "No active SSH sessions" output = ["Active SSH Sessions:"] output.append("-" * 50) for session_id, info in sessions.items(): uptime_min = int(info['uptime'] / 60) output.append(f"- {session_id}") output.append(f" Host: {info['username']}@{info['host']}:{info['port']}") output.append(f" Status: {'Active' if info['is_active'] else 'Inactive'}") output.append(f" Uptime: {uptime_min} minutes") output.append(f" Commands: {info['command_count']}") output.append("") return "\n".join(output) except Exception as e: return f"Failed to list sessions: {str(e)}" - main.py:269-269 (registration)Registration of the ssh_list_sessions tool using the @mcp.tool() decorator from FastMCP.
@mcp.tool() - main.py:129-142 (helper)Helper method in SSHSessionManager class that lists all active SSH sessions, handling errors by closing problematic sessions.
async def list_sessions(self) -> Dict[str, Dict[str, Any]]: """모든 세션 목록 조회""" sessions = {} for session_id in list(self.connections.keys()): try: sessions[session_id] = await self.get_session_info(session_id) except Exception as e: logger.warning(f"Failed to get info for session {session_id}: {e}") # 문제가 있는 세션은 정리 await self.close_session(session_id) return sessions