Skip to main content
Glama

Filesystem MCP Server

by QuantGeekDev
ReadFileTool.ts981 B
import { MCPTool } from "mcp-framework"; import { z } from "zod"; import fs from "fs/promises"; interface ReadFileInput { path: string; } class ReadFileTool extends MCPTool<ReadFileInput> { name = "read_file"; description = "Read the complete contents of a file from the file system. " + "Handles various text encodings and provides detailed error messages " + "if the file cannot be read. Use this tool when you need to examine " + "the contents of a single file. Only works within allowed directories."; schema = { path: { type: z.string(), description: "Path to the file to read", }, }; async execute(input: ReadFileInput) { try { const content = await fs.readFile(input.path, "utf-8"); return content; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(`Failed to read file: ${errorMessage}`); } } } export default ReadFileTool;

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