Skip to main content
Glama

ReadImage

Extract and interpret image data directly from the shell using a specified file path. Enables efficient image processing within the development workflow.

Instructions

Read an image from the shell.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes

Implementation Reference

  • Core handler function that reads the image file from the filesystem, encodes it to base64, guesses 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
  • Dispatch logic in get_tool_output that invokes the ReadImage handler when the tool argument matches ReadImage type.
    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):
  • Pydantic BaseModel defining the input schema for the ReadImage tool, requiring a single 'file_path' string field.
    class ReadImage(BaseModel): file_path: str
  • MCP Tool registration in TOOL_PROMPTS list, providing the schema, name, description, and annotations for the ReadImage tool.
    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), ),
  • Supporting Pydantic model for image data output, 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

Other Tools

Related 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