Skip to main content
Glama

ReadImage

Read-only

Extract and process image data from files to enable visual content analysis and integration within development workflows.

Instructions

Read an image from the shell.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes

Implementation Reference

  • The core handler function that reads the image file from the filesystem, encodes it to base64, determines the MIME type, and returns an ImageData object.
    def read_image_from_shell(file_path: str, context: Context) -> ImageData:
        # Expand the path before checking if it's absolute
        file_path = expand_user(file_path)
    
        # If not absolute after expansion, join with current working directory
        if not os.path.isabs(file_path):
            file_path = os.path.join(context.bash_state.cwd, file_path)
    
        if not os.path.exists(file_path):
            raise ValueError(f"File {file_path} does not exist")
    
        with open(file_path, "rb") as image_file:
            image_bytes = image_file.read()
            image_b64 = base64.b64encode(image_bytes).decode("utf-8")
            image_type = mimetypes.guess_type(file_path)[0]
            return ImageData(media_type=image_type, data=image_b64)  # type: ignore
  • Pydantic model defining the input schema for the ReadImage tool, requiring a 'file_path' parameter.
    class ReadImage(BaseModel):
        file_path: str
  • MCP tool registration defining the name, input schema from ReadImage model, description, and annotations.
    Tool(
        inputSchema=remove_titles_from_schema(ReadImage.model_json_schema()),
        name="ReadImage",
        description="Read an image from the shell.",
        annotations=ToolAnnotations(readOnlyHint=True, openWorldHint=False),
    ),
  • Dispatch logic in the central get_tool_output function that invokes the ReadImage handler when the tool argument matches.
    elif isinstance(arg, ReadImage):
        context.console.print("Calling read image tool")
        image_data = read_image_from_shell(arg.file_path, context)
        output = image_data, 0.0
    elif isinstance(arg, ReadFiles):
  • Supporting Pydantic model for the image output data, including base64 data and MIME type, with a dataurl property.
    class ImageData(BaseModel):
        media_type: MEDIA_TYPES
        data: str
    
        @property
        def dataurl(self) -> str:
            return f"data:{self.media_type};base64," + self.data
Behavior3/5

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

Annotations indicate readOnlyHint=true and openWorldHint=false, covering safety and scope. The description adds that it reads 'from the shell,' suggesting a shell-based operation, but doesn't elaborate on behavioral traits like supported image formats, error handling, or output format. No contradiction with annotations exists.

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 extremely concise with one sentence, front-loaded with the core action, and contains no wasted words. It efficiently communicates the essential purpose without unnecessary elaboration.

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

Completeness3/5

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

Given the tool's low complexity (1 parameter, no output schema) and annotations covering safety and scope, the description is minimally adequate. However, it lacks details on output format or error handling, which could be useful for an agent, though not strictly required with the provided context.

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

Parameters3/5

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

With 0% schema description coverage for the single parameter 'file_path,' the description doesn't add any semantic details about the parameter, such as expected format or constraints. However, the baseline is 3 since the schema fully defines the parameter structure, and the description doesn't need to compensate heavily for a single straightforward parameter.

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

Purpose4/5

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

The description clearly states the action ('Read') and resource ('an image'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'ReadFiles' or 'BashCommand' that might also read files or execute commands involving images.

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

Usage Guidelines2/5

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

The description provides minimal guidance, stating only 'from the shell' without specifying when to use this tool versus alternatives like 'ReadFiles' for general file reading or 'BashCommand' for shell operations. No explicit when/when-not scenarios or prerequisites are mentioned.

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/rusiaaman/wcgw'

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