lokalise_add_projects_to_group
Add projects to a user group, granting all members immediate access. Use to expand group scope or onboard projects to teams.
Instructions
Adds projects to a user group, granting all group members access to specified projects. Required: teamId, groupId, projectIds array. Use to expand group project scope, onboard projects to existing teams, or batch project assignments. Returns: Operation confirmation. All group members gain immediate project access.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| teamId | Yes | Team ID containing the user group | |
| groupId | Yes | User group ID | |
| projectIds | Yes | Project IDs to add to the group |
Implementation Reference
- src/domains/usergroups/usergroups.tool.ts:367-372 (registration)Registration of the 'lokalise_add_projects_to_group' MCP tool with schema and handler.
server.tool( "lokalise_add_projects_to_group", "Adds projects to a user group, granting all group members access to specified projects. Required: teamId, groupId, projectIds array. Use to expand group project scope, onboard projects to existing teams, or batch project assignments. Returns: Operation confirmation. All group members gain immediate project access.", AddProjectsToolArgs.shape, handleAddProjects, ); - Handler function that delegates to controller's addProjects method and formats the response.
async function handleAddProjects(args: AddProjectsToolArgsType) { const methodLogger = Logger.forContext( "usergroups.tool.ts", "handleAddProjects", ); methodLogger.debug("Adding projects to user group...", args); try { const result = await usergroupsController.addProjects(args); methodLogger.debug("Got the response from the controller", result); return { content: [ { type: "text" as const, text: result.content, }, ], }; } catch (error) { methodLogger.error("Tool failed", { error: (error as Error).message, args, }); return formatErrorForMcpTool(error); - Zod schema defining input validation for teamId (string), groupId (string|number), and projectIds (array of string|number, min 1).
export const AddProjectsToolArgs = z .object({ teamId: z.string().describe("Team ID containing the user group"), groupId: z.union([z.string(), z.number()]).describe("User group ID"), projectIds: z .array(z.union([z.string(), z.number()])) .min(1) .describe("Project IDs to add to the group"), }) .strict(); export type AddProjectsToolArgsType = z.infer<typeof AddProjectsToolArgs>; - Service layer that calls the Lokalise API SDK's add_projects_to_group method.
async addProjects(args: AddProjectsToolArgsType): Promise<UserGroup> { const methodLogger = logger.forMethod("addProjects"); methodLogger.info("Adding projects to user group", { teamId: args.teamId, groupId: args.groupId, projectCount: args.projectIds.length, }); try { const api = getLokaliseApi(); // Convert project IDs to proper array type for SDK const projectIds = args.projectIds.map((id) => typeof id === "string" ? id : id.toString(), ); const result = await api .userGroups() .add_projects_to_group(args.teamId, args.groupId, projectIds); methodLogger.info("Added projects to user group successfully", { teamId: args.teamId, groupId: args.groupId, addedCount: args.projectIds.length, }); return result; } catch (error) { methodLogger.error("Failed to add projects to user group", { error, args, }); throw createUnexpectedError( `Failed to add projects to user group ${args.groupId}`, error, ); } }, - Helper that formats the API response into a Markdown string for the user.
export function formatAddProjectsResult( group: UserGroup, addedCount: number, ): string { let content = "# Projects Added Successfully\n\n"; content += `**Group**: ${group.name} (ID: ${group.group_id})\n`; content += `**Projects Added**: ${addedCount}\n`; content += `**Total Projects**: ${group.projects?.length || 0}\n\n`; content += `✅ Successfully added ${addedCount} project(s) to the user group\n`; return content; }