get_task_stats
Retrieve comprehensive statistics about all tasks to analyze workload, track progress, and monitor task management metrics.
Instructions
Get statistics about all tasks
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools.ts:318-416 (handler)The main execution logic for the 'get_task_stats' tool. Loads tasks from storage, computes comprehensive statistics (total, by status, priority, categories, overdue, due soon, completion rate), and returns a formatted markdown-like text response.export async function getTaskStats() { const storage = await loadTasks(); const tasks = storage.tasks; if (tasks.length === 0) { return { content: [ { type: "text", text: "No tasks yet. Create your first task to get started!", }, ], }; } // Calculate statistics const total = tasks.length; const byStatus = { pending: tasks.filter((t) => t.status === "pending").length, in_progress: tasks.filter((t) => t.status === "in_progress").length, completed: tasks.filter((t) => t.status === "completed").length, }; const byPriority = { high: tasks.filter((t) => t.priority === "high").length, medium: tasks.filter((t) => t.priority === "medium").length, low: tasks.filter((t) => t.priority === "low").length, }; // Category counts const categories = new Map<string, number>(); tasks.forEach((t) => { if (t.category) { categories.set(t.category, (categories.get(t.category) || 0) + 1); } }); // Check for overdue and upcoming tasks const today = new Date().toISOString().split("T")[0]!; const oneWeekFromNow = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000) .toISOString() .split("T")[0]!; const overdue = tasks.filter( (t) => t.status !== "completed" && t.dueDate && t.dueDate < today ).length; const dueSoon = tasks.filter( (t) => t.status !== "completed" && t.dueDate && t.dueDate >= today && t.dueDate <= oneWeekFromNow ).length; const completionRate = total > 0 ? ((byStatus.completed / total) * 100).toFixed(1) : "0"; // Format output let result = "π Task Manager Statistics\n"; result += "=".repeat(30) + "\n\n"; result += `π Total Tasks: ${total}\n`; result += `β Completion Rate: ${completionRate}%\n\n`; result += "Status Breakdown:\n"; result += ` π Pending: ${byStatus.pending}\n`; result += ` β³ In Progress: ${byStatus.in_progress}\n`; result += ` β Completed: ${byStatus.completed}\n\n`; result += "Priority Breakdown:\n"; result += ` π΄ High: ${byPriority.high}\n`; result += ` π‘ Medium: ${byPriority.medium}\n`; result += ` π’ Low: ${byPriority.low}\n`; if (categories.size > 0) { result += "\nCategories:\n"; Array.from(categories.entries()) .sort((a, b) => a[0].localeCompare(b[0])) .forEach(([cat, count]) => { result += ` π ${cat}: ${count}\n`; }); } if (overdue > 0) { result += `\nβ οΈ Overdue Tasks: ${overdue}\n`; } if (dueSoon > 0) { result += `π Due Within 7 Days: ${dueSoon}\n`; } return { content: [ { type: "text", text: result, }, ], }; }
- src/index.ts:171-178 (schema)JSON Schema definition for the tool in the TOOLS array, specifying name, description, and empty input schema (no parameters required).{ name: "get_task_stats", description: "Get statistics about all tasks", inputSchema: { type: "object", properties: {}, }, },
- src/index.ts:233-234 (registration)Registration in the tool dispatch switch statement within the CallToolRequestSchema handler, mapping the tool name to the getTaskStats function call.case "get_task_stats": return await getTaskStats();
- src/index.ts:19-19 (registration)Import of the getTaskStats handler function from './tools.js'.getTaskStats,