get_global_stats
Retrieve global email statistics for your SendGrid account by specifying date ranges and aggregation periods to analyze email campaign performance.
Instructions
Retrieve global email statistics for your SendGrid account
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| aggregated_by | No | How to group the statistics | day |
| end_date | No | End date in YYYY-MM-DD format (defaults to today) | |
| start_date | Yes | Start date in YYYY-MM-DD format |
Implementation Reference
- src/tools/stats.ts:16-23 (handler)The handler function that executes the get_global_stats tool logic by constructing the SendGrid stats API URL and fetching data via makeRequest.handler: async ({ start_date, end_date, aggregated_by }: { start_date: string; end_date?: string; aggregated_by?: string }): Promise<ToolResult> => { let url = `https://api.sendgrid.com/v3/stats?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) }] }; },
- src/tools/stats.ts:7-15 (schema)The tool configuration including Zod input schema for validating parameters: start_date (required), end_date (optional), aggregated_by (optional, defaults to 'day').config: { title: "Get Global Email Statistics", description: "Retrieve global email statistics for your SendGrid account", inputSchema: { 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/tools/stats.ts:6-24 (registration)The complete registration of the get_global_stats tool within the statsTools export, including config and handler.get_global_stats: { config: { title: "Get Global Email Statistics", description: "Retrieve global email statistics for your SendGrid account", inputSchema: { 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 ({ start_date, end_date, aggregated_by }: { start_date: string; end_date?: string; aggregated_by?: string }): Promise<ToolResult> => { let url = `https://api.sendgrid.com/v3/stats?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) }] }; }, },
- src/tools/index.ts:9-17 (registration)Registration of statsTools (containing get_global_stats) into the allTools export, aggregating all tools for the MCP server.export const allTools = { ...automationTools, ...campaignTools, ...contactTools, ...mailTools, ...miscTools, ...statsTools, ...templateTools, };