get_file_info
Retrieve file metadata including size, modification date, and type by specifying the file path.
Instructions
File info
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/filesystem_tools.js:400-467 (handler)Main handler function for get_file_info tool. Uses fs.statSync to get file stats (size, timestamps, type), mime-types for MIME detection, and fs.accessSync for permissions (read/write/execute). Returns success/failure response with file metadata.
function getFileInfo(filePath, allowedDirs) { try { if (!filePath) { return { success: false, message: 'No file path provided' }; } if (!isPathAllowed(filePath, allowedDirs)) { return { success: false, message: `Access to path "${filePath}" is not allowed` }; } const resolvedPath = path.resolve(filePath); // Check if file exists if (!fs.existsSync(resolvedPath)) { return { success: false, message: `File not found: ${filePath}` }; } // Get file stats const stats = fs.statSync(resolvedPath); const type = stats.isDirectory() ? 'directory' : 'file'; // Determine MIME type for files let mimeType = null; if (type === 'file') { mimeType = mime.lookup(resolvedPath) || 'application/octet-stream'; } return { success: true, path: filePath, type, size: stats.size, created: stats.birthtime.toISOString(), modified: stats.mtime.toISOString(), accessed: stats.atime.toISOString(), mimeType, permissions: { readable: (() => { try { fs.accessSync(resolvedPath, fs.constants.R_OK); return true; } catch { return false; } })(), writable: (() => { try { fs.accessSync(resolvedPath, fs.constants.W_OK); return true; } catch { return false; } })(), executable: (() => { try { fs.accessSync(resolvedPath, fs.constants.X_OK); return true; } catch { return false; } })() } }; } catch (error) { logger.error(`Error getting file info: ${error.message}`); return { success: false, message: `Error getting file info: ${error.message}` }; } } - src/mcp/server.js:91-91 (schema)Input schema registration for get_file_info in the MCP server. Defines 'path' as a required string property in the JSON object inputSchema.
{ name:'get_file_info', description:'File info', inputSchema:{ type:'object', properties:{ path:{type:'string'} }, required:['path'] } }, - src/mcp/server.js:241-242 (registration)MCP server handler case dispatching get_file_info requests to filesystemTools.getFileInfo(args.path, allowedDirectories).
case 'get_file_info': data = filesystemTools.getFileInfo(args.path, allowedDirectories); - src/filesystem_tools.js:748-748 (registration)Module export of getFileInfo function for use by the MCP server.
getFileInfo, - src/filesystem_tools.js:395-395 (helper)JSDoc comment block documenting the getFileInfo function parameters and return type.
* Gets information about a file or directory