get_subuser_stats
Retrieve email performance metrics for specific subusers within defined date ranges and aggregation periods to monitor and analyze email campaign effectiveness.
Instructions
Retrieve email statistics for specific subusers
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 | |
| subusers | Yes | Comma-separated list of subuser names to retrieve stats for |
Implementation Reference
- src/tools/stats.ts:170-177 (handler)The handler function that builds the SendGrid API request for subuser statistics and returns the JSON response.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) }] }; },
- src/tools/stats.ts:160-169 (schema)Configuration object defining the tool's metadata and input schema using Zod for validation.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"), }, },
- src/index.ts:21-23 (registration)Registration of all tools (including get_subuser_stats from statsTools spread into allTools) to the MCP server.for (const [name, tool] of Object.entries(allTools)) { server.registerTool(name, tool.config as any, tool.handler as any); }
- src/tools/index.ts:9-17 (registration)Aggregation of tool objects from various modules, spreading statsTools which includes get_subuser_stats.export const allTools = { ...automationTools, ...campaignTools, ...contactTools, ...mailTools, ...miscTools, ...statsTools, ...templateTools, };