Skip to main content
Glama

Desktop Image Manager MCP Server

count-desktop-images

Counts the number of image files stored on your desktop, enabling users to manage and organize their desktop image collections efficiently with the Desktop Image Manager MCP Server.

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

  • server.ts:53-71 (handler)
    The asynchronous handler function that executes the tool logic: fetches desktop image files and returns the count in a text response, with error handling.
    async () => { try { const imageFiles = await getDesktopImageFiles(); return { content: [{ type: "text", text: `桌面上共有 ${imageFiles.length} 个图片文件。` }] }; } catch (error) { return { content: [{ type: "text", text: `获取图片数量时出错: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
  • server.ts:49-72 (registration)
    Registration of the 'count-desktop-images' tool with the MCP server, specifying name, description, empty input schema, and handler function.
    server.tool( "count-desktop-images", "统计桌面上的图片文件数量", {}, async () => { try { const imageFiles = await getDesktopImageFiles(); return { content: [{ type: "text", text: `桌面上共有 ${imageFiles.length} 个图片文件。` }] }; } 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 image files using isImageFile, and returns their names.
    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 corresponds to a supported image extension.
    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 resolve the user's desktop directory path.
    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