list_sessions
List all iTerm2 windows, tabs, and sessions, returning a tree with session IDs. Highlights the focused window, tab, and session with an asterisk.
Instructions
List all iTerm2 windows, tabs, and sessions.
Returns a tree with session IDs that can be passed to other tools. The
* marker shows the currently focused window, tab, and session.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/iterm2_mcp/server.py:80-101 (handler)Handler for the 'list_sessions' MCP tool. Iterates over iTerm2 windows, tabs, and sessions, building an indented tree string. Marks the currently focused window/tab/session with '*'. Returns a descriptive string.
@mcp.tool() async def list_sessions() -> str: """List all iTerm2 windows, tabs, and sessions. Returns a tree with session IDs that can be passed to other tools. The ``*`` marker shows the currently focused window, tab, and session. """ app = await _app() out: list[str] = [] for win in app.terminal_windows: is_active_win = win is app.current_terminal_window out.append(f"Window {win.window_id}{' *' if is_active_win else ''}") for tab in win.tabs: is_active_tab = is_active_win and tab is win.current_tab out.append(f" Tab {tab.tab_id}{' *' if is_active_tab else ''}") for sess in tab.sessions: is_active_sess = is_active_tab and sess is tab.current_session name = sess.name or "" out.append( f" Session {sess.session_id}{' *' if is_active_sess else ''} [{name}]" ) return "\n".join(out) if out else "(no iTerm2 windows open)" - src/iterm2_mcp/server.py:80-80 (registration)Registration: the @mcp.tool() decorator on line 80 registers 'list_sessions' with the FastMCP server.
@mcp.tool()