Skip to main content
Glama
zad0xlik

RateSpot MCP Server

by zad0xlik

analyze-file

Process and extract relevant data from files to support mortgage rate analysis, enabling integration with RateSpot MCP Server for real-time rate comparisons and lending insights.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the file to analyze

Implementation Reference

  • Core handler logic for file analysis: retrieves file stats, detects MIME type from extension and binary signatures using file-type-js, determines if binary via signatures and byte analysis, detects text encoding (UTF-8, ASCII, etc.). Returns structured file info.
    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
      };
    }
  • Zod input schema defining the 'path' parameter as a required string for the analyze-file tool.
      path: z.string().describe("Path to the file to analyze")
    },
  • Registers the 'analyze-file' MCP tool with server.tool(), linking schema, handler that calls FileAnalyzer.getFileInfo, and formats output as JSON text content with error handling.
    server.tool(
      "analyze-file",
      {
        path: z.string().describe("Path to the file to analyze")
      },
      async (params) => {
        try {
          const info = await FileAnalyzer.getFileInfo(params.path);
          return {
            content: [{
              type: "text",
              text: JSON.stringify(info, null, 2)
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: `Error analyzing file: ${error instanceof Error ? error.message : String(error)}`
            }],
            isError: true
          };
        }
      }
    );
Install Server

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