Skip to main content
Glama
yonaka15
by yonaka15

pyodide_list-mounted-directory

List files and directories in a mounted Pyodide filesystem to inspect accessible Python execution environments for LLMs.

Instructions

List contents of a mounted directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
mountNameYesName of the mount point

Implementation Reference

  • Core implementation of the tool: lists directory contents using Pyodide Python os.listdir on the mounted filesystem, categorizing files and directories.
      async listMountedDirectory(mountName: string) {
        if (!this.pyodide) {
          return formatCallToolError("Pyodide not initialized");
        }
    
        const mountConfig = this.mountPoints.get(mountName);
        if (!mountConfig) {
          return formatCallToolError(`Mount point not found: ${mountName}`);
        }
    
        try {
          // Use Python code to get directory contents
          const pythonCode = `
    import os
    
    def list_directory(path):
        contents = []
        try:
            for item in os.listdir(path):
                full_path = os.path.join(path, item)
                if os.path.isfile(full_path):
                    contents.append(f"FILE: {item}")
                elif os.path.isdir(full_path):
                    contents.append(f"DIR: {item}")
        except Exception as e:
            print(f"Error listing directory: {e}")
            return []
        return contents
    
    list_directory("${mountConfig.mountPoint}")
    `;
    
          return await this.executePython(pythonCode, 5000);
        } catch (error) {
          return formatCallToolError(error);
        }
      }
  • Tool schema definition including name, description, and input schema requiring 'mountName'.
    export const LIST_MOUNTED_DIRECTORY_TOOL: Tool = {
      name: "pyodide_list-mounted-directory",
      description: "List contents of a mounted directory",
      inputSchema: {
        type: "object",
        properties: {
          mountName: {
            type: "string",
            description: "Name of the mount point",
          },
        },
        required: ["mountName"],
      },
    };
  • Handler dispatch case: validates input using arktype and calls PyodideManager.listMountedDirectory.
    case "pyodide_list-mounted-directory": {
      const listMountedDirectoryArgs = isListMountedDirectoryArgs(args);
      if (listMountedDirectoryArgs instanceof type.errors) {
        throw listMountedDirectoryArgs;
      }
      const { mountName } = listMountedDirectoryArgs;
      const results = await pyodideManager.listMountedDirectory(mountName);
      return results;
    }
  • Registers the tool by including it in the TOOLS array returned by ListToolsRequest handler.
    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,
    ];

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