getProjectStatistics
Retrieve project statistics including completion rates and string counts to monitor translation progress in Weblate.
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:16-47 (handler)The primary MCP tool handler for 'getProjectStatistics'. Decorated with @Tool decorator for registration, validates input with Zod schema, delegates to statistics service, formats output using helper method, and handles errors.@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'), }), }) 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:19-21 (schema)Zod input schema definition for the tool parameters: projectSlug as a required string.parameters: z.object({ projectSlug: z.string().describe('The slug of the project'), }),
- Helper service method that fetches raw project statistics data from the Weblate API using the projectsStatisticsRetrieve function.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)Private helper method in the tool class that formats the raw statistics data into a human-readable Markdown string with progress percentages and counts.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'}`; }
- src/app.module.ts:74-79 (registration)Registration of the StatisticsService and StatisticsTool in the AppModule providers array, making the tool available to the MCP server.WeblateProjectsTool, WeblateComponentsTool, WeblateLanguagesTool, WeblateTranslationsTool, WeblateChangesTool, WeblateStatisticsTool,