gitlab_get_user_activities
Fetch GitLab user activities by username to monitor contributions, optionally filtered by date for tracking recent work.
Instructions
Fetches activities for a given GitLab user by their username, optionally filtered by date.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | The username of the GitLab user. | |
| sinceDate | No | Optional: Activities since this date (YYYY-MM-DD). Defaults to 1 day ago if not provided. |
Implementation Reference
- src/gitlab.service.ts:510-517 (handler)Core handler function that executes the GitLab API call to retrieve user activities/events for a given user ID, optionally filtered by a 'since' date.async getUserActivities(userId: number, sinceDate?: Date): Promise<any[]> { let endpoint = `users/${userId}/events`; if (sinceDate) { // GitLab API expects ISO 8601 format for `after` parameter endpoint += `?after=${sinceDate.toISOString().split('T')[0]}`; } return this.callGitLabApi<any[]>(endpoint); }
- src/index.ts:286-305 (registration)Tool registration including name, description, and input schema definition in the MCP tools list.name: 'gitlab_get_user_activities', description: 'Fetches activities for a given GitLab user by their username, optionally filtered by date.', inputSchema: { type: 'object', properties: { username: { type: 'string', description: 'The username of the GitLab user.', }, sinceDate: { type: 'string', format: 'date', description: 'Optional: Activities since this date (YYYY-MM-DD). Defaults to 1 day ago if not provided.', }, }, required: ['username'], }, },
- src/index.ts:1446-1477 (handler)MCP tool call handler that resolves username to user ID, determines the 'since' date (default 1 day ago), calls the service handler, and formats the response.case 'gitlab_get_user_activities': { if (!gitlabService) { throw new Error('GitLab service is not initialized.'); } const { username, sinceDate } = args as { username: string; sinceDate?: string; }; const userId = await gitlabService.getUserIdByUsername(username); let activities; if (sinceDate) { activities = await gitlabService.getUserActivities( userId, new Date(sinceDate), ); } else { const oneDayAgo = new Date(); oneDayAgo.setDate(oneDayAgo.getDate() - 1); activities = await gitlabService.getUserActivities( userId, oneDayAgo, ); } return { content: [ { type: 'text', text: JSON.stringify(activities, null, 2), }, ], }; }
- src/gitlab.service.ts:473-507 (helper)Helper function to resolve GitLab username to user ID, used by the tool handler. Supports exact match and fuzzy partial matching.async getUserIdByUsername(username: string): Promise<number> { // First try exact username match const exactUsers = await this.callGitLabApi<GitLabUser[]>( `users?username=${username}`, ); if (exactUsers.length > 0) { return exactUsers[0].id; } // Fallback: search all users and filter by partial username (case-insensitive) const allUsers = await this.callGitLabApi<GitLabUser[]>(`users?per_page=100`); const lowerCaseUsername = username.toLowerCase(); const matchingUsers = allUsers.filter( (user) => user.username.toLowerCase().includes(lowerCaseUsername) || user.name.toLowerCase().includes(lowerCaseUsername), ); if (matchingUsers.length === 0) { throw new Error(`User with username containing '${username}' not found.`); } if (matchingUsers.length > 1) { const userList = matchingUsers .map((user) => `${user.username} (${user.name})`) .join(', '); throw new Error( `Multiple users found matching '${username}': ${userList}. Please be more specific.`, ); } return matchingUsers[0].id; }