list_screenshots
Retrieve and list recent Windows screenshots from specified directories using a customizable filter pattern and limit. Simplify screenshot sharing by avoiding manual file path navigation.
Instructions
List recent screenshots from Windows directories
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "list_screenshots"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| directory | No | Specific directory to search (optional, searches all configured dirs by default) | |
| limit | No | Maximum number of screenshots to return (default: 20) | |
| pattern | No | Glob pattern to filter files (default: *.{png,jpg,jpeg,bmp,gif}) | *.{png,jpg,jpeg,bmp,gif} |
Implementation Reference
- src/index.ts:238-293 (handler)Main execution logic for list_screenshots tool: gathers directories, globs for image files, stats them, sorts by recency, limits, and returns JSON list.
case 'list_screenshots': { const limit = (args?.limit as number) || 20; const pattern = (args?.pattern as string) || '*.{png,jpg,jpeg,bmp,gif}'; const specificDir = args?.directory as string | undefined; const directories = specificDir ? [specificDir] : [...getScreenshotDirectories(), ...getCustomDirectories()]; const allFiles: { path: string; mtime: Date; size: number }[] = []; for (const dir of directories) { try { const files = await glob(path.join(dir, pattern as string), { windowsPathsNoEscape: true, nodir: true, }); for (const file of files) { try { const stats = await stat(file); allFiles.push({ path: file, mtime: stats.mtime, size: stats.size, }); } catch (e) { // Skip files we can't stat } } } catch (e) { // Skip directories that don't exist or can't be accessed } } // Sort by modification time (newest first) and limit allFiles.sort((a, b) => b.mtime.getTime() - a.mtime.getTime()); const limitedFiles = allFiles.slice(0, limit as number); return { content: [ { type: 'text', text: JSON.stringify({ count: limitedFiles.length, total_found: allFiles.length, screenshots: limitedFiles.map(f => ({ path: f.path, modified: f.mtime.toISOString(), size_kb: Math.round(f.size / 1024), })), }, null, 2), }, ], }; } - src/index.ts:177-199 (schema)Input schema defining parameters: limit (number, default 20), pattern (string glob, default image extensions), directory (optional specific dir).
{ name: 'list_screenshots', description: 'List recent screenshots from Windows directories', inputSchema: { type: 'object', properties: { limit: { type: 'number', description: 'Maximum number of screenshots to return (default: 20)', default: 20, }, pattern: { type: 'string', description: 'Glob pattern to filter files (default: *.{png,jpg,jpeg,bmp,gif})', default: '*.{png,jpg,jpeg,bmp,gif}', }, directory: { type: 'string', description: 'Specific directory to search (optional, searches all configured dirs by default)', }, }, }, }, - src/index.ts:230-232 (registration)Registration of ListToolsRequestHandler which returns the tools array including list_screenshots.
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools, })); - src/index.ts:234-234 (registration)Registration of CallToolRequestHandler containing the switch dispatching to list_screenshots handler.
server.setRequestHandler(CallToolRequestSchema, async (request) => { - src/index.ts:116-158 (helper)Key helper to get list of screenshot directories, supports WSL/Windows, registry query, defaults, dedupes.
const getScreenshotDirectories = (): string[] => { const username = os.userInfo().username; const windowsUsername = process.env.WINDOWS_USERNAME || username; const env = detectEnvironment(); // Try to get the actual Screenshots folder from registry first const registryPath = getWindowsScreenshotPath(); const directories: string[] = []; if (registryPath) { directories.push(registryPath); } // Add default paths based on environment if (env.type === 'wsl') { // WSL paths directories.push( `/mnt/c/Users/${windowsUsername}/Pictures/Screenshots`, `/mnt/c/Users/${windowsUsername}/Pictures`, `/mnt/c/Users/${windowsUsername}/OneDrive/Pictures/Screenshots`, `/mnt/c/Users/${windowsUsername}/OneDrive/Pictures 2/Screenshots 1`, `/mnt/c/Users/${windowsUsername}/Documents/Screenshots`, `/mnt/c/Users/${windowsUsername}/Desktop`, `/mnt/c/Users/${windowsUsername}/AppData/Local/Temp`, `/mnt/c/Windows/Temp` ); } else if (env.type === 'windows') { // Native Windows paths directories.push( `C:\\Users\\${windowsUsername}\\Pictures\\Screenshots`, `C:\\Users\\${windowsUsername}\\Pictures`, `C:\\Users\\${windowsUsername}\\OneDrive\\Pictures\\Screenshots`, `C:\\Users\\${windowsUsername}\\OneDrive\\Pictures 2\\Screenshots 1`, `C:\\Users\\${windowsUsername}\\Documents\\Screenshots`, `C:\\Users\\${windowsUsername}\\Desktop`, `C:\\Users\\${windowsUsername}\\AppData\\Local\\Temp`, `C:\\Windows\\Temp` ); } // Remove duplicates return [...new Set(directories)]; };