Skip to main content
Glama

read_screen

Retrieve visible text from an iTerm2 terminal session. Strip ANSI codes and trim blank lines to get clean terminal output.

Instructions

Read the visible contents of an iTerm2 session as plain text.

ANSI escape codes are stripped. Trailing blank lines are trimmed.

:param session_id: Target session UUID. Defaults to the active session. :param max_lines: If set, return only the last N lines.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idNo
max_linesNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'read_screen' tool. It resolves the target session, fetches screen contents via async_get_screen_contents(), converts to plain text via _screen_text(), optionally truncates to max_lines, and returns the result (or '(screen is empty)').
    @mcp.tool()
    async def read_screen(
        session_id: str | None = None,
        max_lines: int | None = None,
    ) -> str:
        """Read the visible contents of an iTerm2 session as plain text.
    
        ANSI escape codes are stripped. Trailing blank lines are trimmed.
    
        :param session_id: Target session UUID. Defaults to the active session.
        :param max_lines: If set, return only the last N lines.
        """
        sess = await _session(session_id)
        contents = await sess.async_get_screen_contents()
        text = _screen_text(contents)
        if max_lines is not None and max_lines > 0:
            text = "\n".join(text.splitlines()[-max_lines:])
        return text or "(screen is empty)"
  • Helper function _screen_text() that flattens a ScreenContents object into plain text by iterating over all lines and stripping trailing blank lines.
    def _screen_text(contents: iterm2.ScreenContents) -> str:
        """Flatten a ``ScreenContents`` into plain text, stripping trailing blank lines."""
        lines = [contents.line(i).string for i in range(contents.number_of_lines)]
        while lines and not lines[-1].strip():
            lines.pop()
        return "\n".join(lines)
  • The tool is registered via the @mcp.tool() decorator (line 192) on the FastMCP instance created at line 21 ('mcp = FastMCP("iterm2-mcp")').
    mcp = FastMCP("iterm2-mcp")
Behavior4/5

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

With no annotations, the description carries full burden. It discloses ANSI escape stripping, trailing blank line trimming, and default session behavior. It's sufficient for a read-only tool.

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

Conciseness5/5

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

The description is just 4 sentences, front-loaded with the core purpose, followed by essential behavioral notes and parameter docs. No waste.

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 2 parameters, an existing output schema, and low complexity, the description covers key aspects. Minor gap: no error handling or auth info, but acceptable for a read tool.

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 adds clear meaning for both parameters: session_id is a target UUID defaulting to active, max_lines returns last N lines. This fully compensates for schema gaps.

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 reads visible contents of an iTerm2 session as plain text, distinguishing it from siblings like run_command or write_to_terminal. The verb 'read' and resource 'visible contents' are specific.

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

Usage Guidelines4/5

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

The description implies use for reading screen content but does not explicitly contrast with siblings or provide exclusions. However, the context is clear enough for an AI agent to infer when to use this tool.

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