read_screen
Reads the current 5250 screen content to retrieve visible text, cursor position, input fields, and screen dimensions.
Instructions
Read the current 5250 screen content.
Returns structured data with:
screen: list of text rows (the visible display)
cursor: current cursor position {row, col} (1-based)
fields: list of input fields with position, length, value, and type
dimensions: screen size {rows, cols}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/ibmi_mcp/server.py:80-93 (handler)The read_screen MCP tool handler registered via @mcp.tool() decorator. Calls get_screen_data() on the session's ScreenBuffer.
@mcp.tool() async def read_screen() -> dict: """Read the current 5250 screen content. Returns structured data with: - screen: list of text rows (the visible display) - cursor: current cursor position {row, col} (1-based) - fields: list of input fields with position, length, value, and type - dimensions: screen size {rows, cols} """ if _session is None: return {"error": "Not connected. Call connect() first."} return _session.screen.get_screen_data() - src/ibmi_mcp/server.py:80-81 (registration)Registration of read_screen as an MCP tool using the @mcp.tool() decorator from FastMCP.
@mcp.tool() async def read_screen() -> dict: - src/ibmi_mcp/tn5250/screen.py:92-108 (helper)The get_screen_data() helper method on ScreenBuffer that collects and structures the screen content (text rows, cursor, input fields, dimensions).
def get_screen_data(self) -> dict: input_fields = [] for f in self.fields: if f.is_input: input_fields.append({ "row": f.row + 1, "col": f.col + 1, "length": f.length, "value": self.get_field_value(f).rstrip(), "field_type": f.field_type, }) return { "screen": self.get_text_rows(), "cursor": {"row": self.cursor_row + 1, "col": self.cursor_col + 1}, "fields": input_fields, "dimensions": {"rows": self.rows, "cols": self.cols}, } - Constant definition for the OP_READ_SCREEN opcode (0x08) used in TN5250 session protocol handling.
OP_READ_SCREEN = 0x08 - Handler in the TN5250 session for the OP_READ_SCREEN opcode, which unlocks the keyboard when a read screen operation completes.
elif opcode == OP_READ_SCREEN: self._keyboard_locked = False self._unlock_event.set()