terminal_close
Close terminal sessions and release system resources to maintain performance and prevent memory leaks in terminal-based applications.
Instructions
Close a terminal session and cleanup resources
Args: session_id: ID of the terminal session
Returns: Dictionary with cleanup status
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes |
Implementation Reference
- The `terminal_close` tool handler: an async function decorated with `@mcp.tool()` that closes a terminal session by invoking cleanup on the associated XTermSession instance and removing it from the global sessions dictionary. Handles errors and returns status.@mcp.tool() async def terminal_close(session_id: str) -> Dict[str, Any]: """Close a terminal session and cleanup resources Args: session_id: ID of the terminal session Returns: Dictionary with cleanup status """ if session_id not in sessions: return {"status": "error", "error": f"Session {session_id} not found"} session = sessions[session_id] try: await session.cleanup() del sessions[session_id] logger.info(f"Closed terminal session {session_id}") return {"session_id": session_id, "status": "closed"} except Exception as e: logger.error(f"Failed to close session {session_id}: {e}") return {"status": "error", "error": str(e)}