Skip to main content
Glama
deyikong

SendGrid MCP Server

by deyikong

Get Email Statistics by Subuser

get_subuser_stats

Get email statistics for specified subusers within a date range, grouped by day, week, or month.

Instructions

Retrieve email statistics for specific subusers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
subusersYesComma-separated list of subuser names to retrieve stats for
start_dateYesStart date in YYYY-MM-DD format
end_dateNoEnd date in YYYY-MM-DD format (defaults to today)
aggregated_byNoHow to group the statisticsday

Implementation Reference

  • The handler function for get_subuser_stats. It calls the SendGrid API at /v3/subusers/stats with subusers, start_date, end_date, and aggregated_by parameters.
    get_subuser_stats: {
      config: {
        title: "Get Email Statistics by Subuser",
        description: "Retrieve email statistics for specific subusers",
        inputSchema: {
          subusers: z.string().describe("Comma-separated list of subuser names to retrieve stats for"),
          start_date: z.string().describe("Start date in YYYY-MM-DD format"),
          end_date: z.string().optional().describe("End date in YYYY-MM-DD format (defaults to today)"),
          aggregated_by: z.enum(["day", "week", "month"]).optional().default("day").describe("How to group the statistics"),
        },
      },
      handler: async ({ subusers, start_date, end_date, aggregated_by }: { subusers: string; start_date: string; end_date?: string; aggregated_by?: string }): Promise<ToolResult> => {
        let url = `https://api.sendgrid.com/v3/subusers/stats?subusers=${encodeURIComponent(subusers)}&start_date=${start_date}`;
        if (end_date) url += `&end_date=${end_date}`;
        if (aggregated_by) url += `&aggregated_by=${aggregated_by}`;
        
        const result = await makeRequest(url);
        return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
      },
    },
  • Input schema for get_subuser_stats: subusers (string), start_date (string), end_date (optional string), aggregated_by (enum day/week/month, defaults to day).
    inputSchema: {
      subusers: z.string().describe("Comma-separated list of subuser names to retrieve stats for"),
      start_date: z.string().describe("Start date in YYYY-MM-DD format"),
      end_date: z.string().optional().describe("End date in YYYY-MM-DD format (defaults to today)"),
      aggregated_by: z.enum(["day", "week", "month"]).optional().default("day").describe("How to group the statistics"),
    },
  • src/index.ts:20-23 (registration)
    Tools are registered via the allTools export. server.registerTool(name, config, handler) is called for each tool including get_subuser_stats.
    // Register all tools
    for (const [name, tool] of Object.entries(allTools)) {
      server.registerTool(name, tool.config as any, tool.handler as any);
    }
  • allTools object collects all tool definitions from statsTools (which includes get_subuser_stats) and exports them for registration.
    export const allTools = {
      ...automationTools,
      ...campaignTools,
      ...contactTools,
      ...mailTools,
      ...miscTools,
      ...statsTools,
      ...templateTools,
    };
  • The makeRequest helper function used by the handler to make authenticated HTTP requests to the SendGrid API.
    export async function makeRequest(url: string, options: RequestInit = {}): Promise<any> {
      const response = await fetch(url, {
        headers: {
          ...getAuthHeaders(),
          ...options.headers,
        },
        ...options,
      });
    
      if (!response.ok) {
        const errorText = await response.text();
        throw new Error(`SendGrid API error (${response.status}): ${errorText}`);
      }
    
      return response.json();
    }
Behavior2/5

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

Without annotations, the description carries full burden. It only states 'Retrieve', implying a read operation, but fails to disclose authentication needs, rate limits, or whether the operation is read-only. No contradictions with annotations (none exist).

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

Conciseness4/5

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

The description is a single concise sentence with no waste. However, it lacks structure by omitting details about other parameters or output.

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?

The tool has 4 parameters but the description only mentions subusers. There is no output schema, and the description does not clarify what statistics are returned (e.g., counts, rates, time series). This makes it incomplete for an agent to fully understand usage.

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 coverage is 100%, so baseline is 3. The description adds no additional parameter semantics beyond the title and schema; 'for specific subusers' merely restates the subusers parameter's purpose.

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

Purpose5/5

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

The description 'Retrieve email statistics for specific subusers' clearly states the verb (Retrieve), resource (email statistics), and scope (specific subusers), distinguishing it from sibling tools like get_global_stats or get_stats_by_browser.

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 is provided on when to use this tool versus alternatives. It doesn't mention that get_global_stats should be used for overall stats or that this tool is for subuser-specific filtering.

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

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/deyikong/sendgrid-mcp'

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