getProjectStatistics
Analyze project data by retrieving statistics such as completion rates and string counts for translation projects managed on the Weblate MCP Server.
Instructions
Get comprehensive statistics for a project including completion rates and string counts
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectSlug | Yes | The slug of the project |
Implementation Reference
- src/tools/statistics.tool.ts:23-47 (handler)The MCP tool handler function that invokes the statistics service, formats the results, and returns MCP-formatted content or error.async getProjectStatistics({ projectSlug }: { projectSlug: string }) { try { const stats = await this.statisticsService.getProjectStatistics(projectSlug); return { content: [ { type: 'text', text: this.formatProjectStatistics(projectSlug, stats), }, ], }; } catch (error) { this.logger.error(`Failed to get project statistics for ${projectSlug}`, error); return { content: [ { type: 'text', text: `Error getting project statistics: ${error.message}`, }, ], isError: true, }; } }
- src/tools/statistics.tool.ts:16-22 (registration)Registers the tool in the MCP framework using the @Tool decorator, specifying name, description, and input schema.@Tool({ name: 'getProjectStatistics', description: 'Get comprehensive statistics for a project including completion rates and string counts', parameters: z.object({ projectSlug: z.string().describe('The slug of the project'), }), })
- src/tools/statistics.tool.ts:19-21 (schema)Zod schema defining the input parameter 'projectSlug' as a required string.parameters: z.object({ projectSlug: z.string().describe('The slug of the project'), }),
- Helper service method that retrieves raw project statistics from the Weblate API.async getProjectStatistics(projectSlug: string) { try { const response = await projectsStatisticsRetrieve({ client: this.clientService.getClient(), path: { slug: projectSlug }, query: { format: 'json' }, }); if (response.error) { throw new Error(`Failed to get project statistics: ${response.error}`); } return response.data; } catch (error) { this.logger.error(`Failed to get project statistics for ${projectSlug}`, error); throw error; } }
- src/tools/statistics.tool.ts:284-311 (helper)Helper method to format raw statistics into a human-readable Markdown string for the tool response.private formatProjectStatistics(projectSlug: string, stats: any): string { const getStatValue = (key: string, defaultValue = 'N/A') => { return stats?.[key] !== undefined ? stats[key] : defaultValue; }; const formatPercent = (value: any) => { return typeof value === 'number' ? `${value.toFixed(1)}%` : 'N/A'; }; return `## ๐ Project Statistics: ${stats?.name || projectSlug} **Overall Progress:** - ๐ฏ Translation Progress: ${formatPercent(getStatValue('translated_percent'))} - โ Approved: ${formatPercent(getStatValue('approved_percent'))} - ๐ Needs Review: ${formatPercent(getStatValue('readonly_percent'))} - โ Untranslated: ${formatPercent(getStatValue('nottranslated_percent'))} **String Counts:** - ๐ Total Strings: ${getStatValue('total')} - โ Translated: ${getStatValue('translated')} - ๐ฏ Approved: ${getStatValue('approved')} - โ Untranslated: ${getStatValue('nottranslated')} - ๐ Read-only: ${getStatValue('readonly')} **Project Details:** - ๐ URL: ${stats?.web_url || 'N/A'} - ๐ Repository: ${stats?.repository_url || 'N/A'}`; }