Skip to main content
Glama

get_analytics_data

Retrieve email analytics data from TurboSMTP within a specified date range. Use start and end dates, optional filters, pagination, and timezone settings to extract precise insights.

Instructions

Retrieve analytics data from TurboSMTP for a specific date range

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filterNoFilter for analytics data (optional)
fromYesStart date for analytics (format: YYYY-MM-DD)
limitNoNumber of results per page (optional)
pageNoPage number (optional)
toYesEnd date for analytics (format: YYYY-MM-DD)
tzNoTimezone (optional, e.g., "Europe/Rome", "America/New_York")

Implementation Reference

  • The MCP tool handler function 'handleGetAnalyticsData' that performs input validation specific to the tool, delegates to EmailService, formats the output nicely, and returns in MCP content format.
    async handleGetAnalyticsData(args) {
      const { from, to, page, limit, tz, filter } = args;
    
      // Date format validation
      const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
      
      if (!from || !dateRegex.test(from)) {
        throw new Error('The "from" parameter is required and must be in YYYY-MM-DD format');
      }
    
      if (!to || !dateRegex.test(to)) {
        throw new Error('The "to" parameter is required and must be in YYYY-MM-DD format');
      }
    
      // Validate date logic
      const fromDate = new Date(from);
      const toDate = new Date(to);
      
      if (fromDate > toDate) {
        throw new Error('The "from" date must be before or equal to the "to" date');
      }
    
      // Validate optional parameters
      if (page !== undefined && (!Number.isInteger(page) || page < 1)) {
        throw new Error('The "page" parameter must be a positive integer');
      }
    
      if (limit !== undefined && (!Number.isInteger(limit) || limit < 1 || limit > 100)) {
        throw new Error('The "limit" parameter must be an integer between 1 and 100');
      }
    
      try {
        const result = await EmailService.getAnalyticsData({
          from,
          to,
          page,
          limit,
          tz,
          filter
        });
    
        // Format the analytics data for better readability
        let formattedOutput = `šŸ“Š Analytics Data Retrieved Successfully!\n\n`;
        formattedOutput += `Date Range: ${from} to ${to}\n`;
        
        if (page) formattedOutput += `Page: ${page}\n`;
        if (limit) formattedOutput += `Results per page: ${limit}\n`;
        if (tz) formattedOutput += `Timezone: ${tz}\n`;
        if (filter) formattedOutput += `Filter: ${filter}\n`;
        
        formattedOutput += `\nšŸ“ˆ Analytics Summary:\n`;
        formattedOutput += `${JSON.stringify(result.data, null, 2)}`;
    
        return {
          content: [
            {
              type: 'text',
              text: formattedOutput
            }
          ]
        };
      } catch (error) {
        throw new Error(`Error retrieving analytics data: ${error.message}`);
      }
    }
  • Input schema for the get_analytics_data tool, defining the expected parameters, types, descriptions, patterns, and required fields.
    inputSchema: {
      type: 'object',
      properties: {
        from: {
          type: 'string',
          description: 'Start date for analytics (format: YYYY-MM-DD)',
          pattern: '^\\d{4}-\\d{2}-\\d{2}$'
        },
        to: {
          type: 'string',
          description: 'End date for analytics (format: YYYY-MM-DD)',
          pattern: '^\\d{4}-\\d{2}-\\d{2}$'
        },
        page: {
          type: 'number',
          description: 'Page number (optional)',
          minimum: 1
        },
        limit: {
          type: 'number',
          description: 'Number of results per page (optional)',
          minimum: 1,
          maximum: 100
        },
        tz: {
          type: 'string',
          description: 'Timezone (optional, e.g., "Europe/Rome", "America/New_York")'
        },
        filter: {
          type: 'string',
          description: 'Filter for analytics data (optional)'
        }
      },
      required: ['from', 'to']
    }
  • Tool registration in the ListTools handler, specifying name, description, and linking to input schema.
    {
      name: 'get_analytics_data',
      description: 'Retrieve analytics data from TurboSMTP for a specific date range',
      inputSchema: {
        type: 'object',
        properties: {
          from: {
            type: 'string',
            description: 'Start date for analytics (format: YYYY-MM-DD)',
            pattern: '^\\d{4}-\\d{2}-\\d{2}$'
          },
          to: {
            type: 'string',
            description: 'End date for analytics (format: YYYY-MM-DD)',
            pattern: '^\\d{4}-\\d{2}-\\d{2}$'
          },
          page: {
            type: 'number',
            description: 'Page number (optional)',
            minimum: 1
          },
          limit: {
            type: 'number',
            description: 'Number of results per page (optional)',
            minimum: 1,
            maximum: 100
          },
          tz: {
            type: 'string',
            description: 'Timezone (optional, e.g., "Europe/Rome", "America/New_York")'
          },
          filter: {
            type: 'string',
            description: 'Filter for analytics data (optional)'
          }
        },
        required: ['from', 'to']
      }
    },
  • Supporting helper function in EmailService that performs the actual HTTP request to TurboSMTP API for analytics data, including parameter construction and error handling.
    async getAnalyticsData({from, to, page, limit, tz, filter}) {
        // Utility function to validate date format.
        const isValidDate = (dateString) => /^\d{4}-\d{2}-\d{2}$/.test(dateString);
    
        // Validation of 'from' and 'to' parameters.
        if (!from || !isValidDate(from)) {
            throw new Error('The "from" parameter is required and must be in YYYY-MM-DD format.');
        }
        if (!to || !isValidDate(to)) {
            throw new Error('The "to" parameter is required and must be in YYYY-MM-DD format.');
        }
    
        try {
            // Construction of query parameters.
            const queryParams = new URLSearchParams({from, to});
            if (page) queryParams.append('page', page);
            if (limit) queryParams.append('limit', limit);
            if (tz) queryParams.append('tz', tz);
            if (filter) queryParams.append('filter', filter);
    
            // Execution of the GET request to the /analytics endpoint.
            // The API key is included in the 'Authorization' header.
            const response = await axios.get(
                `${this.apiUrl}/analytics?${queryParams.toString()}`,
                {
                    headers: this.headers
                }
            );
    
            // Returning response data on success.
            return {
                success: true,
                message: 'Analytics data successfully retrieved',
                data: response.data
            };
        } catch (error) {
            // Handling HTTP request errors.
            console.error('Error retrieving analytics data:', error.response?.data || error.message);
            throw new Error(
                error.response?.data?.message ||
                'Error retrieving analytics data: ' + error.message
            );
        }
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. While 'Retrieve' implies a read operation, the description doesn't disclose important behavioral traits like authentication requirements, rate limits, pagination behavior (implied by page/limit parameters but not explained), error conditions, or what format the analytics data returns.

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

Conciseness5/5

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

Single sentence, zero waste, front-loaded with the core purpose. Every word earns its place - specifies what's retrieved, from where, and the primary constraint.

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

Completeness2/5

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

For a 6-parameter tool with no annotations and no output schema, the description is inadequate. It doesn't explain what analytics data includes, how results are structured, pagination behavior, authentication needs, or error handling. The agent would struggle to use this effectively without trial and error.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all 6 parameters thoroughly. The description adds no parameter-specific information beyond implying date range usage through 'for a specific date range', which the schema already covers with 'from' and 'to' parameters. Baseline 3 is appropriate when schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the verb 'Retrieve' and resource 'analytics data from TurboSMTP' with scope 'for a specific date range'. It distinguishes from 'send_email' but doesn't explicitly differentiate from 'get_analytics_data_by_id' which likely retrieves data by ID rather than date range.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus alternatives. The description doesn't mention when to use this date-range based retrieval versus 'get_analytics_data_by_id' (likely ID-based retrieval) or when analytics data retrieval is appropriate versus email sending.

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/debba/turbosmtp-mcp-server'

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