Skip to main content
Glama
akshat12000

File System Explorer MCP Server

by akshat12000

read_file

Retrieve text content from files on your system by specifying the file path. This tool enables reading file contents for analysis, editing, or processing within the File System Explorer MCP Server environment.

Instructions

Read the contents of a text file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe file path to read

Implementation Reference

  • The main handler logic for the 'read_file' tool. Validates the input path using ReadFileArgsSchema, resolves and sanitizes the path, checks if it's a file and not too large, reads the file content using fs.readFile, formats the output with file info and content, and returns it in the expected MCP format.
    case "read_file": { const { path: filePath } = ReadFileArgsSchema.parse(args); const safePath = validatePath(filePath); const stats = await fs.stat(safePath); if (stats.isDirectory()) { throw new Error("Cannot read a directory as a file"); } // Check file size to prevent reading huge files const maxSize = 1024 * 1024; // 1MB limit if (stats.size > maxSize) { throw new Error(`File too large (${formatFileSize(stats.size)}). Maximum size is ${formatFileSize(maxSize)}`); } const content = await fs.readFile(safePath, 'utf-8'); return { content: [ { type: "text", text: `File: ${safePath}\nSize: ${formatFileSize(stats.size)}\nModified: ${stats.mtime.toLocaleString()}\n\n--- Content ---\n${content}` } ] }; }
  • Zod schema for validating the input arguments of the 'read_file' tool, specifically the 'path' parameter.
    const ReadFileArgsSchema = z.object({ path: z.string().describe("The file path to read") });
  • src/index.ts:158-171 (registration)
    Registration of the 'read_file' tool in the ListToolsRequestSchema handler, defining its name, description, and input schema for MCP clients to discover and use it.
    { name: "read_file", description: "Read the contents of a text file", inputSchema: { type: "object", properties: { path: { type: "string", description: "The file path to read" } }, required: ["path"] } },

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/akshat12000/FileSystem-MCPServer'

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