get_variable
Retrieve iTerm2 session variables (e.g., jobName, path, hostname) from active or specified sessions.
Instructions
Read an iTerm2 session variable.
Commonly useful names: jobName, jobPid, path (requires shell
integration), username, hostname, rows, columns,
autoName. Prefix with user. for variables set via iTerm2 custom
control sequences.
:param name: The variable name to read. :param session_id: Target session UUID. Defaults to the active session.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| session_id | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/iterm2_mcp/server.py:409-423 (handler)The `get_variable` tool handler function. It is decorated with @mcp.tool(), reads an iTerm2 session variable by name (e.g., jobName, path, username) via the iTerm2 Python API, and returns the variable name and value. Accepts an optional session_id parameter.
@mcp.tool() async def get_variable(name: str, session_id: str | None = None) -> str: """Read an iTerm2 session variable. Commonly useful names: ``jobName``, ``jobPid``, ``path`` (requires shell integration), ``username``, ``hostname``, ``rows``, ``columns``, ``autoName``. Prefix with ``user.`` for variables set via iTerm2 custom control sequences. :param name: The variable name to read. :param session_id: Target session UUID. Defaults to the active session. """ sess = await _session(session_id) value = await sess.async_get_variable(name) return f"{name}={value!r}" - src/iterm2_mcp/server.py:400-401 (registration)The @mcp.tool() decorator registering get_variable as an MCP tool on the FastMCP instance. Line 400 shows the decorator preceding the handler function definition.
@mcp.tool() async def list_profiles() -> str: