getUserStatistics
Retrieve detailed contribution statistics for a specific user in Weblate translation projects by providing their username. Supports efficient user activity tracking and analysis.
Instructions
Get contribution statistics for a specific user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | The username to get statistics for |
Implementation Reference
- src/tools/statistics.tool.ts:251-282 (handler)The MCP tool handler for 'getUserStatistics'. Includes @Tool registration with name, description, Zod input schema (username: string), fetches data from statistics service, formats response using formatUserStatistics, and handles errors with appropriate MCP response format.@Tool({ name: 'getUserStatistics', description: 'Get contribution statistics for a specific user', parameters: z.object({ username: z.string().describe('The username to get statistics for'), }), }) 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, }; } }
- The service helper method implementing the core logic: calls Weblate API via usersStatisticsRetrieve to fetch 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; } }
- src/tools/statistics.tool.ts:473-494 (helper)Private helper method to format raw user statistics into a Markdown-formatted string for the tool response.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'}`; }
- src/app.module.ts:79-79 (registration)Registration of the WeblateStatisticsTool class (containing the getUserStatistics handler) as a provider in the NestJS AppModule.WeblateStatisticsTool,
- src/tools/statistics.tool.ts:254-256 (schema)Zod schema definition for the tool input parameters.parameters: z.object({ username: z.string().describe('The username to get statistics for'), }),