Skip to main content
Glama

Desktop Image Manager MCP Server

list-desktop-images

Retrieve a list of image file names stored on your desktop using the Desktop Image Manager MCP Server to organize and manage image files efficiently.

Instructions

获取桌面上的图片文件名称列表

Input Schema

NameRequiredDescriptionDefault

No arguments

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": {}, "type": "object" }

Implementation Reference

  • Handler function for the 'list-desktop-images' tool. It retrieves image files from the desktop using getDesktopImageFiles(), formats them into a numbered list, and returns as text content. Handles empty list and errors.
    async () => { try { const imageFiles = await getDesktopImageFiles(); if (imageFiles.length === 0) { return { content: [{ type: "text", text: "桌面上没有找到图片文件。" }] }; } const fileList = imageFiles.map((file, index) => `${index + 1}. ${file}`).join('\n'); return { content: [{ type: "text", text: `桌面上的图片文件列表:\n${fileList}` }] }; } catch (error) { return { content: [{ type: "text", text: `获取图片列表时出错: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
  • server.ts:75-105 (registration)
    Registers the 'list-desktop-images' tool with the MCP server, specifying name, Chinese description, empty input schema, and inline handler function.
    server.tool( "list-desktop-images", "获取桌面上的图片文件名称列表", {}, async () => { try { const imageFiles = await getDesktopImageFiles(); if (imageFiles.length === 0) { return { content: [{ type: "text", text: "桌面上没有找到图片文件。" }] }; } const fileList = imageFiles.map((file, index) => `${index + 1}. ${file}`).join('\n'); return { content: [{ type: "text", text: `桌面上的图片文件列表:\n${fileList}` }] }; } catch (error) { return { content: [{ type: "text", text: `获取图片列表时出错: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
  • Core helper function that reads the desktop directory, filters for image files using isImageFile(), and returns their basenames. Used by both count-desktop-images and list-desktop-images tools.
    const getDesktopImageFiles = async (): Promise<string[]> => { const desktopPath = getDesktopPath(); try { const files = await fs.readdir(desktopPath); const imagePaths = files.filter(file => { const filePath = path.join(desktopPath, file); return fs.statSync(filePath).isFile() && isImageFile(filePath); }); return imagePaths; } catch (error) { console.error(`Error reading desktop directory: ${error}`, ); return []; } };
  • Helper function to check if a file path has an image extension. Supports common formats.
    const isImageFile = (filePath: string): boolean => { const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.tiff', '.svg']; const ext = path.extname(filePath).toLowerCase(); return imageExtensions.includes(ext); };
  • Helper function to get the path to the user's Desktop directory.
    const getDesktopPath = () => { const { homedir } = os.userInfo(); return path.join(homedir, 'Desktop'); };

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/zhixiaoqiang/desktop-image-manager-mcp'

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