Skip to main content
Glama

pyodide_read-image

Extract and read image files from a specified mounted directory using Python on the mcp-pyodide server. Input mount name and image path to process visual data efficiently.

Instructions

Read an image from a mounted directory

Input Schema

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

Implementation Reference

  • Core implementation of pyodide_read-image: calls readResource to get base64 image data and formats it as MCP image content.
    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); } }
  • Helper method that reads image from mounted directory's host path, determines MIME type using MIME_TYPES, and base64 encodes the file.
    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) }; } }
  • Tool definition including name, description, and input schema for pyodide_read-image.
    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"], }, };
  • MCP CallToolRequest handler: validates input using isReadImageArgs and delegates to PyodideManager.readImage.
    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; }
  • Registers READ_IMAGE_TOOL (pyodide_read-image) in the server's list of available tools, served via ListToolsRequest.
    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, ];

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

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