lokalise_create_comments
Add comments to translation keys to ask questions, provide context, or flag issues for team collaboration. Supports bulk creation for efficiency.
Instructions
Adds one or more comments to a translation key for team collaboration. Required: projectId, keyId, comments array with 'comment' text. Use to ask translators questions, provide context, leave implementation notes, or flag issues. Supports bulk creation for efficiency. Returns: Created comments with IDs. Note: Comments are visible to all project members.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | Yes | Project ID to create comments in | |
| keyId | Yes | Key ID to attach comments to | |
| comments | Yes | Array of comments to create |
Implementation Reference
- src/domains/comments/comments.tool.ts:247-252 (registration)Registration of the 'lokalise_create_comments' tool with the MCP server, associating the tool name, description, Zod schema, and handler function.
server.tool( "lokalise_create_comments", "Adds one or more comments to a translation key for team collaboration. Required: projectId, keyId, comments array with 'comment' text. Use to ask translators questions, provide context, leave implementation notes, or flag issues. Supports bulk creation for efficiency. Returns: Created comments with IDs. Note: Comments are visible to all project members.", CreateCommentsToolArgs.shape, handleCreateComments, ); - MCP tool handler that receives validated arguments, delegates to the controller, and returns a formatted text response or error.
async function handleCreateComments(args: CreateCommentsToolArgsType) { const methodLogger = Logger.forContext( "comments.tool.ts", "handleCreateComments", ); methodLogger.debug(`Creating ${args.comments.length} comment(s)...`, args); try { const result = await commentsController.createComments(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 the input parameters for creating comments: projectId (string), keyId (number), and comments (array of objects with 'comment' string).
export const CreateCommentsToolArgs = z .object({ projectId: z.string().describe("Project ID to create comments in"), keyId: z.number().describe("Key ID to attach comments to"), comments: z .array(CommentDataSchema) .min(1) .describe("Array of comments to create"), }) .strict(); export type CreateCommentsToolArgsType = z.infer<typeof CreateCommentsToolArgs>; - Service layer that calls the Lokalise API's comments().create() with mapped data and project/key IDs.
async createComments(args: CreateCommentsToolArgsType): Promise<Comment[]> { const methodLogger = logger.forMethod("createComments"); methodLogger.info("Creating comments", { projectId: args.projectId, keyId: args.keyId, count: args.comments.length, }); try { const api = getLokaliseApi(); // Map our schema to SDK types const commentData: CommentData[] = args.comments.map((item) => ({ comment: item.comment, })); const result = await api.comments().create(commentData, { project_id: args.projectId, key_id: args.keyId, }); methodLogger.info("Created comments successfully", { projectId: args.projectId, keyId: args.keyId, created: result.length, }); return result; } catch (error) { methodLogger.error("Failed to create comments", { error, args }); throw createUnexpectedError( `Failed to create comments on key ${args.keyId} in project ${args.projectId}`, error, ); } },