Skip to main content
Glama
mmntm

Weblate MCP Server

by mmntm

getUserStatistics

Retrieve contribution statistics for a specific user in Weblate translation projects to track and analyze translation activity.

Instructions

Get contribution statistics for a specific user

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
usernameYesThe username to get statistics for

Implementation Reference

  • The main execution logic of the getUserStatistics tool. Fetches stats from service, formats them, and returns formatted text content or error.
    async getUserStatistics({ username }: { username: string }) {
      try {
        const stats = await this.statisticsService.getUserStatistics(username);
    
        return {
          content: [
            {
              type: 'text',
              text: this.formatUserStatistics(username, stats),
            },
          ],
        };
      } catch (error) {
        this.logger.error(`Failed to get user statistics for ${username}`, error);
        return {
          content: [
            {
              type: 'text',
              text: `Error getting user statistics: ${error.message}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Zod schema and metadata for the getUserStatistics tool, defining input parameter 'username'.
    @Tool({
      name: 'getUserStatistics',
      description: 'Get contribution statistics for a specific user',
      parameters: z.object({
        username: z.string().describe('The username to get statistics for'),
      }),
    })
  • Service helper that calls Weblate API to retrieve raw user statistics data.
    async getUserStatistics(username: string) {
      try {
        const response = await usersStatisticsRetrieve({
          client: this.clientService.getClient(),
          path: { username },
          query: { format: 'json' },
        });
    
        if (response.error) {
          throw new Error(`Failed to get user statistics: ${response.error}`);
        }
    
        return response.data;
      } catch (error) {
        this.logger.error(`Failed to get user statistics for ${username}`, error);
        throw error;
      }
    }
  • Helper function to format the raw statistics into a user-friendly markdown string.
      private formatUserStatistics(username: string, stats: any): string {
        const getStatValue = (key: string, defaultValue = 'N/A') => {
          return stats?.[key] !== undefined ? stats[key] : defaultValue;
        };
    
        return `## πŸ‘€ User Statistics: ${stats?.full_name || username}
    
    **User Details:**
    - πŸ‘€ Username: ${getStatValue('username')}
    - πŸ“§ Email: ${getStatValue('email')}
    - πŸ“… Joined: ${stats?.date_joined ? new Date(stats.date_joined).toLocaleDateString() : 'N/A'}
    
    **Contribution Stats:**
    - ✏️ Translations: ${getStatValue('translated')}
    - βœ… Approved: ${getStatValue('approved')}
    - πŸ’‘ Suggestions: ${getStatValue('suggestions')}
    - πŸ’¬ Comments: ${getStatValue('comments')}
    
    **Activity:**
    - πŸ“ˆ Total Changes: ${getStatValue('total_changes')}
    - πŸ—“οΈ Last Activity: ${stats?.last_login ? new Date(stats.last_login).toLocaleDateString() : '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