Skip to main content
Glama

Filesystem MCP Server

by QuantGeekDev
GetFileInfoTool.ts1.68 kB
import { MCPTool } from "mcp-framework"; import { z } from "zod"; import fs from "fs/promises"; interface FileInfo { size: number; created: Date; modified: Date; accessed: Date; isDirectory: boolean; isFile: boolean; permissions: string; } interface GetFileInfoInput { path: string; } class GetFileInfoTool extends MCPTool<GetFileInfoInput> { name = "get_file_info"; description = "Retrieve detailed metadata about a file or directory. Returns comprehensive " + "information including size, creation time, last modified time, permissions, " + "and type. This tool is perfect for understanding file characteristics " + "without reading the actual content. Only works within allowed directories."; schema = { path: { type: z.string(), description: "Path to the file or directory to get information about", }, }; private async getFileStats(filePath: string): Promise<FileInfo> { const stats = await fs.stat(filePath); return { size: stats.size, created: stats.birthtime, modified: stats.mtime, accessed: stats.atime, isDirectory: stats.isDirectory(), isFile: stats.isFile(), permissions: stats.mode.toString(8).slice(-3), }; } async execute(input: GetFileInfoInput) { try { const info = await this.getFileStats(input.path); return Object.entries(info) .map(([key, value]) => `${key}: ${value}`) .join("\n"); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(`Failed to get file info: ${errorMessage}`); } } } export default GetFileInfoTool;

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/QuantGeekDev/mcp-filesystem'

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