get_cursor_position
Retrieve the cursor position (x, y) within the visible screen of an iTerm2 session. Helps in automating terminal interactions by identifying cursor location.
Instructions
Return the cursor coordinates x, y within the visible screen.
:param session_id: Target session UUID. Defaults to the active session.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/iterm2_mcp/server.py:213-221 (handler)The handler function for the 'get_cursor_position' tool. It resolves the session, gets screen contents, and returns the cursor coordinates (x, y) from the visible screen.
async def get_cursor_position(session_id: str | None = None) -> str: """Return the cursor coordinates ``x``, ``y`` within the visible screen. :param session_id: Target session UUID. Defaults to the active session. """ sess = await _session(session_id) contents = await sess.async_get_screen_contents() coord = contents.cursor_coord return f"x={coord.x} y={coord.y}" - src/iterm2_mcp/server.py:212-213 (registration)The '@mcp.tool()' decorator registers 'get_cursor_position' as an MCP tool.
@mcp.tool() async def get_cursor_position(session_id: str | None = None) -> str: