Skip to main content
Glama
mmntm

Weblate MCP Server

by mmntm

getComponentStatistics

Retrieve detailed statistics for a translation component to monitor translation progress, identify untranslated strings, and track completion rates in Weblate projects.

Instructions

Get detailed statistics for a specific component

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectSlugYesThe slug of the project
componentSlugYesThe slug of the component

Implementation Reference

  • Primary handler decorated with @Tool decorator. Defines input schema, fetches statistics from service, formats response as markdown text, and handles errors.
    @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'),
      }),
    })
    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,
        };
      }
    }
  • Zod schema for input parameters: projectSlug and componentSlug.
    parameters: z.object({
      projectSlug: z.string().describe('The slug of the project'),
      componentSlug: z.string().describe('The slug of the component'),
    }),
  • The WeblateStatisticsTool is registered as a provider in the AppModule, enabling its tools to be available via MCP.
      WeblateChangesTool,
      WeblateStatisticsTool,
    ],
  • Service method that retrieves raw component statistics from 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;
      }
    }
  • Utility method to format the raw statistics data into a 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