resize_pty
Resize the terminal dimensions (rows and columns) of an active PTY session to adapt to display changes or window resizing requirements.
Instructions
Resize the PTY terminal dimensions for a session.
Only works in pty mode.
Args: session_id: The session ID. rows: New row count. cols: New column count.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes | ||
| rows | No | ||
| cols | No |
Implementation Reference
- Core handler: The Session.resize_pty() method that performs the actual PTY resize via pexpect's setwinsize(). It validates mode is 'pty' and process is running, then sets dimensions.
def resize_pty(self, rows: int, cols: int) -> None: if self.mode != "pty": raise RuntimeError("PTY resize only available in pty mode") if self.status != SessionStatus.RUNNING: raise RuntimeError("Process not running") self._process.setwinsize(rows, cols) self._rows = rows self._cols = cols - MCP tool definition with typed parameters (session_id: str, rows: int=24, cols: int=80) and docstring, registered via @mcp.tool() decorator.
@mcp.tool() def resize_pty( session_id: str, rows: int = 24, cols: int = 80, ) -> dict: """Resize the PTY terminal dimensions for a session. Only works in pty mode. Args: session_id: The session ID. rows: New row count. cols: New column count. """ session = _mgr.get(session_id) if not session: return {"error": f"Session '{session_id}' not found"} try: session.resize_pty(rows=rows, cols=cols) return {"success": True} except RuntimeError as e: return {"error": str(e)} - Alternative handler: The resize_pty function in tools.py (used by the non-decorator tool registration path) that gets session from manager and calls session.resize_pty().
def resize_pty(args: dict) -> dict: session = _get_session(args["session_id"]) session.resize_pty(rows=args["rows"], cols=args["cols"]) return {"success": True} - src/interactive_process_mcp/tools.py:92-101 (registration)Registration: The tool is registered in the tuple list returned by create_tools() at line 99 as ('resize_pty', resize_pty).
return [ ("start_process", start_process), ("send_input", send_input), ("read_output", read_output), ("send_and_read", send_and_read), ("list_sessions", list_sessions), ("terminate_process", terminate_process), ("resize_pty", resize_pty), ("get_session_info", get_session_info), ] - src/interactive_process_mcp/server.py:157-206 (registration)Registration: The @mcp.tool() decorator on line 183 registers resize_pty as an MCP tool in the FastMCP server.
@mcp.tool() def list_sessions() -> dict: """List all interactive process sessions.""" return {"sessions": _mgr.list_all()} @mcp.tool() def terminate_process( session_id: str, force: bool = False, grace_period: float = 5.0, ) -> dict: """Terminate an interactive process. Args: session_id: The session ID to terminate. force: Use SIGKILL instead of SIGTERM. Default False. grace_period: Seconds to wait after SIGTERM before SIGKILL. Default 5. """ session = _mgr.get(session_id) if not session: return {"error": f"Session '{session_id}' not found"} session.terminate(force=force, grace_period=grace_period) return {"success": True} @mcp.tool() def resize_pty( session_id: str, rows: int = 24, cols: int = 80, ) -> dict: """Resize the PTY terminal dimensions for a session. Only works in pty mode. Args: session_id: The session ID. rows: New row count. cols: New column count. """ session = _mgr.get(session_id) if not session: return {"error": f"Session '{session_id}' not found"} try: session.resize_pty(rows=rows, cols=cols) return {"success": True} except RuntimeError as e: return {"error": str(e)}