Skip to main content
Glama
zad0xlik

RateSpot MCP Server

by zad0xlik

read-file

Access and retrieve file content by specifying the file path, enabling integration with RateSpot MCP Server for mortgage rate APIs and lending information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the file to read

Implementation Reference

  • Core implementation of file reading: retrieves file info, checks if binary, reads the file synchronously, decodes using detected encoding, and returns content.
    static readFile(filePath: string) { const info = this.getFileInfo(filePath); if (info.isBinary) { throw new Error('Cannot read binary files'); } const buffer = fs.readFileSync(filePath); const encoding = info.encoding || 'utf8'; const content = iconv.decode(buffer, encoding); return { content, encoding, info }; }
  • Input schema for the read-file tool: requires a 'path' string parameter.
    { path: z.string().describe("Path to the file to read") },
  • Registers the 'read-file' MCP tool with schema and a handler that delegates to FileAnalyzer.readFile and handles response formatting and errors.
    server.tool( "read-file", { path: z.string().describe("Path to the file to read") }, async (params) => { try { const result = await FileAnalyzer.readFile(params.path); return { content: [{ type: "text", text: result.content }] }; } catch (error) { return { content: [{ type: "text", text: `Error reading file: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
  • Supporting method called by readFile to get file stats, detect MIME type, binary nature, and text encoding.
    static getFileInfo(filePath: string) { const stats = fs.statSync(filePath); const ext = path.extname(filePath); const buffer = fs.readFileSync(filePath); // Detect MIME type let mimeType = this.getMimeTypeFromExtension(ext); if (fileType.fileTypes) { for (const [type, signature] of Object.entries(fileType.fileTypes)) { if (Array.isArray(signature) && buffer.length >= signature.length && signature.every((byte, i) => buffer[i] === byte)) { mimeType = `image/${type}`; break; } } } const isBinary = this.isBinaryFile(buffer); let encoding: string | undefined; // Try to detect encoding for text files if (!isBinary) { try { // Try UTF-8 first const content = buffer.toString('utf8'); if (this.isValidUtf8(content)) { encoding = 'utf8'; } else { // Try other common encodings const encodings = ['ascii', 'utf16le', 'latin1']; for (const enc of encodings) { try { iconv.decode(buffer, enc); encoding = enc; break; } catch { continue; } } } } catch { // If all encoding detection fails, default to binary } } return { path: filePath, size: stats.size, created: stats.birthtimeMs, modified: stats.mtimeMs, mimeType, extension: ext, isBinary, encoding }; }

Other Tools

Related Tools

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/zad0xlik/ratespot-mcp'

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