Skip to main content
Glama
mmntm

Weblate MCP Server

by mmntm

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
NameRequiredDescriptionDefault
componentSlugYesThe slug of the component
projectSlugYesThe slug of the project

Implementation Reference

  • 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, }; }
  • 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'), }),
  • 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; } }
  • 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'})`; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mmntm/weblate-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server