Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
session_idNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • 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}"
  • 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:
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, but the description discloses that reading certain variables requires shell integration and explains the naming convention for custom variables (prefix user.). This adds valuable behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the key action, followed by a list of examples and parameter docs. It is concise with no wasted sentences, though the parameter section could be slightly more integrated.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the two parameters, no annotations, and existing output schema, the description provides adequate context. It explains variable availability and default behavior, making the tool understandable for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Despite 0% schema description coverage, the description thoroughly explains both parameters: provides examples for 'name' (common names and prefix) and clarifies that 'session_id' defaults to the active session. This adds significant meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's function as reading an iTerm2 session variable, with specific examples of commonly useful names. This distinguishes it from sibling tools like run_command or send_escape_sequence.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use the tool (reading session variables) and gives common variable names, but does not explicitly state when not to use it or mention alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lorencarvalho/iterm2-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server