get_project_analytics
Analyze project performance by calculating completion rates, velocity, and team metrics to identify improvement areas and track progress over time.
Instructions
Get comprehensive analytics and insights for projects
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_ids | No | Specific project IDs to analyze (optional) | |
| time_range | No | Time range for analytics | month |
| metrics | No | Specific metrics to calculate | |
| include_predictions | No | Include predictive analytics and forecasts | |
| benchmark_comparison | No | Compare against historical benchmarks |
Implementation Reference
- src/tools/analytics-insights.ts:63-124 (handler)The core handler function that implements the get_project_analytics tool. Parses arguments, fetches project data, computes metrics using helpers, adds predictions/benchmarks, generates insights and returns structured analytics.export const getProjectAnalytics = requireAuth(async (args: any) => { const { project_ids, time_range, metrics, include_predictions, benchmark_comparison } = GetProjectAnalyticsSchema.parse(args) logger.info('Getting project analytics', { project_ids, time_range, metrics }) // Get projects to analyze const projects = project_ids ? await Promise.all(project_ids.map(id => supabaseService.getProject(id))) : await supabaseService.getProjects({}, { limit: 100 }) const analytics: any = { time_range, projects_analyzed: projects.length, generated_at: new Date().toISOString(), metrics: {} } // Calculate requested metrics for (const metric of metrics) { try { switch (metric) { case 'completion_rate': analytics.metrics.completion_rate = await calculateCompletionRate(projects, time_range) break case 'velocity': analytics.metrics.velocity = await calculateVelocity(projects, time_range) break case 'team_performance': analytics.metrics.team_performance = await calculateTeamPerformance(projects, time_range) break case 'resource_utilization': analytics.metrics.resource_utilization = await calculateResourceUtilization(projects, time_range) break case 'quality_metrics': analytics.metrics.quality_metrics = await calculateQualityMetrics(projects, time_range) break case 'collaboration_index': analytics.metrics.collaboration_index = await calculateCollaborationIndex(projects, time_range) break } } catch (error) { logger.error(`Failed to calculate ${metric}:`, error) analytics.metrics[metric] = { error: 'Calculation failed' } } } // Add predictions if requested if (include_predictions) { analytics.predictions = await generatePredictions(projects, analytics.metrics, time_range) } // Add benchmark comparison if requested if (benchmark_comparison) { analytics.benchmarks = await getBenchmarkComparison(analytics.metrics, time_range) } // Generate insights and recommendations analytics.insights = generateAnalyticsInsights(analytics.metrics, projects) analytics.recommendations = generateAnalyticsRecommendations(analytics.metrics, analytics.insights) return analytics })
- Zod schema used for input validation in the getProjectAnalytics handler.const GetProjectAnalyticsSchema = z.object({ project_ids: z.array(z.string()).optional(), time_range: z.enum(['week', 'month', 'quarter', 'year', 'all']).default('month'), metrics: z.array(z.enum(['completion_rate', 'velocity', 'team_performance', 'resource_utilization', 'quality_metrics', 'collaboration_index'])).default(['completion_rate', 'velocity', 'team_performance']), include_predictions: z.boolean().default(false), benchmark_comparison: z.boolean().default(false) })
- src/tools/analytics-insights.ts:15-53 (registration)MCPTool object definition registering the tool with name, description, and JSON input schema.export const getProjectAnalyticsTool: MCPTool = { name: 'get_project_analytics', description: 'Get comprehensive analytics and insights for projects', inputSchema: { type: 'object', properties: { project_ids: { type: 'array', items: { type: 'string' }, description: 'Specific project IDs to analyze (optional)' }, time_range: { type: 'string', enum: ['week', 'month', 'quarter', 'year', 'all'], default: 'month', description: 'Time range for analytics' }, metrics: { type: 'array', items: { type: 'string', enum: ['completion_rate', 'velocity', 'team_performance', 'resource_utilization', 'quality_metrics', 'collaboration_index'] }, default: ['completion_rate', 'velocity', 'team_performance'], description: 'Specific metrics to calculate' }, include_predictions: { type: 'boolean', default: false, description: 'Include predictive analytics and forecasts' }, benchmark_comparison: { type: 'boolean', default: false, description: 'Compare against historical benchmarks' } } } }
- src/tools/analytics-insights.ts:786-791 (registration)Export of handlers object that maps 'get_project_analytics' to the handler function, used for global registration.export const analyticsInsightsHandlers = { get_project_analytics: getProjectAnalytics, get_team_productivity: getTeamProductivity, get_workspace_health: getWorkspaceHealth, generate_custom_report: generateCustomReport }
- Helper function to calculate completion rate metric, fetching tasks per project and computing rates.async function calculateCompletionRate(projects: any[], timeRange: string): Promise<any> { const projectStats = await Promise.all(projects.map(async (project) => { const tasks = await supabaseService.getTasks({ project_id: project.id }) const completedTasks = tasks.filter(t => t.status === 'done') return { project_id: project.id, project_name: project.name, total_tasks: tasks.length, completed_tasks: completedTasks.length, completion_rate: tasks.length > 0 ? (completedTasks.length / tasks.length) * 100 : 0 } })) const overallRate = projectStats.reduce((sum, stats) => sum + stats.completion_rate, 0) / projectStats.length return { overall_completion_rate: Math.round(overallRate * 10) / 10, project_breakdown: projectStats, trend: 'stable', // Would calculate actual trend time_range: timeRange } }