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
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {},
"type": "object"
}
Implementation Reference
- server.ts:79-104 (handler)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 }; } } );
- server.ts:27-40 (helper)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 []; } };
- server.ts:19-23 (helper)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); };
- server.ts:13-16 (helper)Helper function to get the path to the user's Desktop directory.const getDesktopPath = () => { const { homedir } = os.userInfo(); return path.join(homedir, 'Desktop'); };