Skip to main content
Glama
zad0xlik

RateSpot MCP Server

by zad0xlik

save-streaming-results

Capture and save real-time mortgage rate data to CSV, JSON, or Markdown formats using a session ID from RateSpot MCP Server for efficient analysis and reporting.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileNameNoOptional custom filename (without extension)
formatNoOutput formatcsv
sessionIdYesSession ID from get-mortgage-rates

Implementation Reference

  • The handler function for the 'save-streaming-results' tool. It retrieves the streaming session data, generates a filename with timestamp if not provided, formats the data (JSON with metadata and products, Markdown table, or CSV), writes it to a file in the data directory, ensures the file server is running, generates a download URL, and returns a detailed success message with file information.
    async (params) => {
      try {
        const session = activeSessions.get(params.sessionId);
        
        if (!session) {
          return {
            content: [{
              type: "text",
              text: `Session ${params.sessionId} not found or expired`
            }],
            isError: true
          };
        }
    
        const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
        const defaultName = `mortgage_rates_${timestamp}`;
        const baseName = params.fileName || defaultName;
        const extension = params.format === 'json' ? 'json' : 
                         params.format === 'markdown' ? 'md' : 'csv';
        const fileName = `${baseName}.${extension}`;
        const filePath = path.join(DATA_DIR, fileName);
    
        // Format the data
        let content = '';
        if (params.format === 'json') {
          content = JSON.stringify({
            metadata: session.metadata,
            products: session.data
          }, null, 2);
        } else if (params.format === 'markdown') {
          content = formatResults(session, 'markdown');
        } else {
          content = formatResults(session, 'csv');
        }
    
        // Save the file
        await fs.promises.writeFile(filePath, content, 'utf8');
        const manager = await getFileServerManager();
        await manager.ensureServerRunning(DATA_DIR);
        const downloadUrl = await manager.getDownloadUrl(fileName);
    
        let response = `✅ **Results Saved Successfully**\n\n`;
        response += `📊 **Summary:**\n`;
        response += `• Total Products: ${session.data.length}\n`;
        response += `• Status: ${session.status}\n`;
        response += `• Format: ${params.format.toUpperCase()}\n\n`;
        response += `📁 **File Details:**\n`;
        response += `• Name: ${fileName}\n`;
        response += `• Size: ${Math.round(content.length / 1024)} KB\n`;
        response += `• Path: ${filePath}\n`;
        response += `• Download: ${downloadUrl}\n\n`;
        response += `💡 Use 'list-saved-results' tool to see all saved files.`;
    
        return {
          content: [{
            type: "text",
            text: response
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error saving results: ${error instanceof Error ? error.message : String(error)}`
          }],
          isError: true
        };
      }
    }
  • Input schema for the 'save-streaming-results' tool using Zod validation: requires sessionId, optional format (defaults to csv), optional fileName.
    {
      sessionId: z.string().describe("Session ID from get-mortgage-rates"),
      format: z.enum(["csv", "json", "markdown"]).default("csv").describe("Output format"),
      fileName: z.string().optional().describe("Optional custom filename (without extension)")
    },
  • Registers the 'save-streaming-results' tool on the MCP server using server.tool(name, inputSchema, handlerFunction).
    server.tool(
      "save-streaming-results",
      {
        sessionId: z.string().describe("Session ID from get-mortgage-rates"),
        format: z.enum(["csv", "json", "markdown"]).default("csv").describe("Output format"),
        fileName: z.string().optional().describe("Optional custom filename (without extension)")
      },
      async (params) => {
        try {
          const session = activeSessions.get(params.sessionId);
          
          if (!session) {
            return {
              content: [{
                type: "text",
                text: `Session ${params.sessionId} not found or expired`
              }],
              isError: true
            };
          }
    
          const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
          const defaultName = `mortgage_rates_${timestamp}`;
          const baseName = params.fileName || defaultName;
          const extension = params.format === 'json' ? 'json' : 
                           params.format === 'markdown' ? 'md' : 'csv';
          const fileName = `${baseName}.${extension}`;
          const filePath = path.join(DATA_DIR, fileName);
    
          // Format the data
          let content = '';
          if (params.format === 'json') {
            content = JSON.stringify({
              metadata: session.metadata,
              products: session.data
            }, null, 2);
          } else if (params.format === 'markdown') {
            content = formatResults(session, 'markdown');
          } else {
            content = formatResults(session, 'csv');
          }
    
          // Save the file
          await fs.promises.writeFile(filePath, content, 'utf8');
          const manager = await getFileServerManager();
          await manager.ensureServerRunning(DATA_DIR);
          const downloadUrl = await manager.getDownloadUrl(fileName);
    
          let response = `✅ **Results Saved Successfully**\n\n`;
          response += `📊 **Summary:**\n`;
          response += `• Total Products: ${session.data.length}\n`;
          response += `• Status: ${session.status}\n`;
          response += `• Format: ${params.format.toUpperCase()}\n\n`;
          response += `📁 **File Details:**\n`;
          response += `• Name: ${fileName}\n`;
          response += `• Size: ${Math.round(content.length / 1024)} KB\n`;
          response += `• Path: ${filePath}\n`;
          response += `• Download: ${downloadUrl}\n\n`;
          response += `💡 Use 'list-saved-results' tool to see all saved files.`;
    
          return {
            content: [{
              type: "text",
              text: response
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: `Error saving results: ${error instanceof Error ? error.message : String(error)}`
            }],
            isError: true
          };
        }
      }
    );
  • Helper function formatResults used by the tool to format session data into markdown table, CSV, or JSON string representations.
    function formatResults(session: StreamSession, format: string = 'markdown'): string {
      const products = session.data;
      
      // Sort by rate
      products.sort((a, b) => a.rate - b.rate);
      
      if (format === 'markdown') {
        let output = `# Mortgage Rate Results\n\n`;
        output += `Found ${products.length} mortgage products\n\n`;
        
        output += `| Lender | Rate | APR | Payment | Points | Upfront Costs | Type | Quote |\n`;
        output += `|---------|------|-----|---------|--------|---------------|------|--------|\n`;
        
        for (const product of products) {
          output += `| ${product.lender} | ${product.rate.toFixed(3)}% | ${product.apr.toFixed(3)}% | $${product.payment.toLocaleString()} | ${product.points.toFixed(3)} | $${product.upfrontCosts.toLocaleString()} | ${product.loanType} | ${product.quoteType} |\n`;
        }
        
        return output;
      } else if (format === 'csv') {
        let output = 'Lender,Rate,APR,Payment,Points,Upfront_Costs,Loan_Type,Quote_Type\n';
        
        for (const product of products) {
          output += `${escapeCSV(product.lender)},${product.rate}%,${product.apr}%,$${product.payment},${product.points},$${product.upfrontCosts},${product.loanType},${product.quoteType}\n`;
        }
        
        return output;
      } else {
        return JSON.stringify(products, null, 2);
      }
    }
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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