ReadImage
Reads an image from the shell by providing the file path, making its content accessible for further processing.
Instructions
Read an image from the shell.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes |
Implementation Reference
- src/wcgw/client/tools.py:486-501 (handler)Main handler function that reads an image file from disk, base64-encodes it, and returns ImageData with media type.
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 - src/wcgw/client/tools.py:458-467 (helper)ImageData model and MEDIA_TYPES literal used by ReadImage handler to represent image output data.
MEDIA_TYPES = Literal["image/jpeg", "image/png", "image/gif", "image/webp"] class ImageData(BaseModel): media_type: MEDIA_TYPES data: str @property def dataurl(self) -> str: return f"data:{self.media_type};base64," + self.data - src/wcgw/client/tool_prompts.py:67-72 (registration)Registration of ReadImage as an MCP tool with its JSON schema derived from the ReadImage Pydantic model.
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), ), - src/wcgw/types_.py:246-248 (schema)Pydantic schema defining ReadImage input with a single 'file_path' field.
class ReadImage(BaseModel): file_path: str - src/wcgw/client/tools.py:1020-1023 (handler)Dispatch logic in get_tool_output that routes ReadImage tool calls to read_image_from_shell.
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