getComponentStatistics
Retrieve detailed statistics for a specific component in a Weblate project, including translation status and progress, by providing the project and component slugs.
Instructions
Get detailed statistics for a specific component
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| componentSlug | Yes | The slug of the component | |
| projectSlug | Yes | The slug of the project |
Implementation Reference
- src/tools/statistics.tool.ts:57-86 (handler)The main handler function for the 'getComponentStatistics' MCP tool. It receives projectSlug and componentSlug, fetches stats from the statistics service, formats them using formatComponentStatistics, and returns an MCP-formatted text response or error.async getComponentStatistics({ projectSlug, componentSlug, }: { projectSlug: string; componentSlug: string; }) { try { const stats = await this.statisticsService.getComponentStatistics(projectSlug, componentSlug); return { content: [ { type: 'text', text: this.formatComponentStatistics(projectSlug, componentSlug, stats), }, ], }; } catch (error) { this.logger.error(`Failed to get component statistics for ${projectSlug}/${componentSlug}`, error); return { content: [ { type: 'text', text: `Error getting component statistics: ${error.message}`, }, ], isError: true, }; }
- src/tools/statistics.tool.ts:50-55 (schema)The input schema defined using Zod for validating projectSlug and componentSlug parameters.name: 'getComponentStatistics', description: 'Get detailed statistics for a specific component', parameters: z.object({ projectSlug: z.string().describe('The slug of the project'), componentSlug: z.string().describe('The slug of the component'), }),
- src/tools/statistics.tool.ts:49-56 (registration)The @Tool decorator registers the getComponentStatistics method as an MCP tool with name, description, and schema.@Tool({ name: 'getComponentStatistics', description: 'Get detailed statistics for a specific component', parameters: z.object({ projectSlug: z.string().describe('The slug of the project'), componentSlug: z.string().describe('The slug of the component'), }), })
- Backend service method that retrieves raw component statistics from the Weblate API using componentsStatisticsRetrieve.async getComponentStatistics(projectSlug: string, componentSlug: string) { try { const response = await componentsStatisticsRetrieve({ client: this.clientService.getClient(), path: { project__slug: projectSlug, slug: componentSlug }, query: { format: 'json' }, }); if (response.error) { throw new Error(`Failed to get component statistics: ${response.error}`); } return response.data; } catch (error) { this.logger.error(`Failed to get component statistics for ${projectSlug}/${componentSlug}`, error); throw error; } }
- src/tools/statistics.tool.ts:313-342 (helper)Helper function to format the raw statistics into a human-readable Markdown string for the tool response.private formatComponentStatistics(projectSlug: string, componentSlug: 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 `## ๐ Component Statistics: ${stats?.name || componentSlug} **Project:** ${projectSlug} **Component:** ${componentSlug} **Translation Progress:** - ๐ฏ Translated: ${formatPercent(getStatValue('translated_percent'))} - โ Approved: ${formatPercent(getStatValue('approved_percent'))} - ๐ Needs Review: ${formatPercent(getStatValue('readonly_percent'))} - โ Untranslated: ${formatPercent(getStatValue('nottranslated_percent'))} **String Counts:** - ๐ Total: ${getStatValue('total')} - โ Translated: ${getStatValue('translated')} - ๐ฏ Approved: ${getStatValue('approved')} - โ Untranslated: ${getStatValue('nottranslated')} **Component Details:** - ๐ URL: ${stats?.web_url || 'N/A'} - ๐ Source Language: ${stats?.source_language?.name || 'N/A'} (${stats?.source_language?.code || 'N/A'})`; }