get_global_stats
Retrieve global email statistics from your SendGrid account to analyze performance metrics within specified date ranges.
Instructions
Retrieve global email statistics for your SendGrid account
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| start_date | Yes | Start date in YYYY-MM-DD format | |
| end_date | No | End date in YYYY-MM-DD format (defaults to today) | |
| aggregated_by | No | How to group the statistics | day |
Implementation Reference
- src/tools/stats.ts:16-23 (handler)The main handler function that implements the logic for the get_global_stats tool by constructing the SendGrid API URL and calling makeRequest to fetch global email 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/stats.ts:10-14 (schema)Zod schema for input validation of the get_global_stats tool parameters.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/index.ts:21-23 (registration)The MCP server registration loop that registers the get_global_stats tool (along with all other tools from allTools).for (const [name, tool] of Object.entries(allTools)) { server.registerTool(name, tool.config as any, tool.handler as any); }
- src/tools/index.ts:15-15 (registration)Spreads the statsTools object (containing get_global_stats) into the allTools export used for registration....statsTools,
- src/tools/stats.ts:6-24 (registration)Full definition 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) }] }; }, },