Skip to main content
Glama
yonaka15
by yonaka15

pyodide_read-image

Read image files from mounted directories in Pyodide environments for Python-based image processing tasks.

Instructions

Read an image from a mounted directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
mountNameYesName of the mount point
imagePathYesPath of the image file

Implementation Reference

  • Handler for the 'pyodide_read-image' tool: validates input using isReadImageArgs and calls PyodideManager.readImage(mountName, imagePath).
    case "pyodide_read-image": {
      const readImageArgs = isReadImageArgs(args);
      if (readImageArgs instanceof type.errors) {
        throw readImageArgs;
      }
      const { mountName, imagePath } = readImageArgs;
      const results = await pyodideManager.readImage(mountName, imagePath);
      return results;
    }
  • Tool schema definition for 'pyodide_read-image', specifying input schema with mountName and imagePath as required string properties.
    export const READ_IMAGE_TOOL: Tool = {
      name: "pyodide_read-image",
      description: "Read an image from a mounted directory",
      inputSchema: {
        type: "object",
        properties: {
          mountName: {
            type: "string",
            description: "Name of the mount point",
          },
          imagePath: {
            type: "string",
            description: "Path of the image file",
          },
        },
        required: ["mountName", "imagePath"],
      },
    };
  • Registration of the pyodide_read-image tool by including READ_IMAGE_TOOL in the TOOLS array returned by ListToolsRequestHandler.
    const TOOLS: Tool[] = [
      tools.EXECUTE_PYTHON_TOOL,
      tools.INSTALL_PYTHON_PACKAGES_TOOL,
      tools.GET_MOUNT_POINTS_TOOL,
      tools.LIST_MOUNTED_DIRECTORY_TOOL,
      tools.READ_IMAGE_TOOL,
    ];
  • PyodideManager.readImage: core logic that retrieves image resource via readResource, formats it using contentFormatters.formatImage, and returns formatted success response.
    async readImage(mountName: string, imagePath: string) {
      if (!this.pyodide) {
        return formatCallToolError("Pyodide not initialized");
      }
      try {
        const resource = await this.readResource(mountName, imagePath);
        if ("error" in resource) {
          return formatCallToolError(resource.error);
        }
        const content = contentFormatters.formatImage(
          resource.blob,
          resource.mimeType
        );
        return formatCallToolSuccess(content);
      } catch (error) {
        return formatCallToolError(error);
      }
    }
  • PyodideManager.readResource: reads image file from host filesystem path, determines MIME type from extension, base64-encodes the content, returns blob and mimeType or error.
    async readResource(
      mountName: string,
      resourcePath: string
    ): Promise<
      | {
          blob: string;
          mimeType: string;
        }
      | { error: string }
    > {
      if (!this.pyodide) {
        return { error: "Pyodide not initialized" };
      }
    
      const mountConfig = this.mountPoints.get(mountName);
      if (!mountConfig) {
        return { error: `Mount point not found: ${mountName}` };
      }
    
      try {
        // Get full path to the image
        const fullPath = path.join(mountConfig.hostPath, resourcePath);
        if (!fs.existsSync(fullPath)) {
          return { error: `Image file not found: ${fullPath}` };
        }
    
        // Get MIME type from file extension
        const ext = path.extname(fullPath).toLowerCase();
        const mimeType = MIME_TYPES[ext];
        if (!mimeType) {
          return { error: `Unsupported image format: ${ext}` };
        }
    
        // Read and encode image
        const imageBuffer = await fs.promises.readFile(fullPath);
        const base64Data = imageBuffer.toString("base64");
    
        return { blob: base64Data, mimeType };
      } catch (error) {
        return { error: String(error) };
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states the action ('Read') but doesn't disclose behavioral traits like what happens if the image is invalid, if it requires specific permissions, or what the output format is. This is inadequate for a tool with no annotation coverage.

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 a single, efficient sentence with no wasted words. It's appropriately sized and front-loaded, making it easy to understand quickly.

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

Completeness2/5

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

Given no annotations and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., image data, metadata, or an error) or handle potential issues like invalid paths. For a tool with 2 parameters and no structured support, it should provide more 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?

The schema description coverage is 100%, so the schema already documents both parameters (mountName and imagePath) with descriptions. The description doesn't add any meaning beyond this, such as examples or constraints, but meets the baseline for high schema coverage.

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 from a mounted directory'), making the purpose understandable. It doesn't explicitly differentiate from sibling tools like pyodide_list-mounted-directory, which might also involve mounted directories, so it's not a perfect 5.

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 no guidance on when to use this tool versus alternatives, such as how it differs from pyodide_list-mounted-directory or when to prefer it over other image-handling methods. It lacks explicit context or exclusions.

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/yonaka15/mcp-pyodide'

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