pyodide_list-mounted-directory
Retrieve and display the contents of a mounted directory using the specified mount point name. This tool simplifies directory inspection for Python code execution via the MCP server.
Instructions
List contents of a mounted directory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mountName | Yes | Name of the mount point |
Implementation Reference
- Core implementation of the pyodide_list-mounted-directory tool. Retrieves the mount configuration and executes Python code in Pyodide to list directory contents, distinguishing files and directories.// List contents of a mounted directory 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); } }
- src/handlers/index.ts:109-117 (handler)MCP server tool handler dispatch: validates input arguments and delegates to 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; }
- src/tools/index.ts:49-62 (schema)Tool schema definition: specifies name, description, and input schema requiring 'mountName' parameter.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"], }, };
- src/handlers/index.ts:32-38 (registration)Tool registration: includes LIST_MOUNTED_DIRECTORY_TOOL in the server's TOOLS list for discovery 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, ];
- src/handlers/index.ts:49-51 (schema)Runtime input validation schema using arktype for mountName argument.const isListMountedDirectoryArgs = type({ mountName: "string", });