lokalise_create_keys
Add new translation keys to your Lokalise project for UI text or content. Specify key names, platforms, and optional translations to prepare new features or initial content for localization.
Instructions
Adds new UI text or content to be translated (up to 1000 keys per request). Required: projectId, keys array with {key_name, platforms}. Optional per key: description, tags, translations. Use for new features, initial setup, or content expansion. Returns: Created keys with IDs and any errors. Tip: Include base language translations to speed up workflow. Pairs with: lokalise_list_keys to verify.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | Yes | Project ID to create keys in | |
| keys | Yes | Array of key objects to create (1-1000 keys) |
Implementation Reference
- src/domains/keys/keys.tool.ts:316-322 (registration)Registration of the 'lokalise_create_keys' MCP tool using server.tool() with description, schema (CreateKeysToolArgs.shape), and handler (handleCreateKeys).
// Create Keys Tool server.tool( "lokalise_create_keys", "Adds new UI text or content to be translated (up to 1000 keys per request). Required: projectId, keys array with {key_name, platforms}. Optional per key: description, tags, translations. Use for new features, initial setup, or content expansion. Returns: Created keys with IDs and any errors. Tip: Include base language translations to speed up workflow. Pairs with: lokalise_list_keys to verify.", CreateKeysToolArgs.shape, handleCreateKeys, ); - src/domains/keys/keys.tool.ts:78-107 (handler)MCP tool handler that delegates to keysController.createKeys() and formats the response for MCP.
async function handleCreateKeys(args: CreateKeysToolArgsType) { const methodLogger = Logger.forContext( "tools/keys.tool.ts", "handleCreateKeys", ); methodLogger.debug( `Creating ${args.keys.length} keys in project ${args.projectId}...`, args, ); try { const result = await keysController.createKeys(args); methodLogger.debug("Got the response from the controller", result); return { content: [ { type: "text" as const, text: result.content, }, ], }; } catch (error) { methodLogger.error("Error in handleCreateKeys", { error, args }); throw formatErrorForMcpTool({ error, message: "Failed to create keys", }); } } - src/domains/keys/keys.types.ts:56-92 (schema)Zod schema defining the input arguments: projectId (string), keys array (1-1000 items) each with key_name, description, platforms, translations, and tags.
export const CreateKeysToolArgs = z .object({ projectId: z.string().describe("Project ID to create keys in"), keys: z .array( z.object({ key_name: z.string().describe("Name of the key"), description: z .string() .optional() .describe("Description of the translation key"), platforms: z .array(z.enum(["ios", "android", "web", "other"])) .min(1) .describe("Platforms this key belongs to (required)"), translations: z .array( z.object({ language_iso: z.string().describe("Language ISO code"), translation: z.string().describe("Translation text"), }), ) .optional() .describe("Initial translations for the key"), tags: z .array(z.string()) .optional() .describe("Tags to organize the key"), }), ) .min(1) .max(1000) .describe("Array of key objects to create (1-1000 keys)"), }) .strict(); export type CreateKeysToolArgsType = z.infer<typeof CreateKeysToolArgs>; - Service layer function that calls the Lokalise API (api.keys().create()) to actually create keys in the project.
export async function createKeys( options: CreateKeysParams, ): Promise<BulkResult<Key>> { const methodLogger = serviceLogger.forMethod("createKeys"); try { methodLogger.debug("Calling Lokalise Keys API - create", { projectId: options.project_id, keysCount: options.keys.length, }); const api = getLokaliseApi(); // Prepare API parameters const apiParams = { keys: options.keys.map((key) => ({ key_name: key.key_name, description: key.description, platforms: key.platforms, translations: key.translations || [], tags: key.tags || [], })), }; const result = await api .keys() .create(apiParams, { project_id: options.project_id }); methodLogger.debug("Lokalise Keys API call successful - create", { projectId: options.project_id, createdCount: result.items?.length || 0, errorsCount: result.errors?.length || 0, }); return result; } catch (error: unknown) { methodLogger.error("Lokalise Keys API call failed - create", { error: (error as Error).message, projectId: options.project_id, }); if ((error as ApiError).code === 404) { throw createApiError(`Project not found: ${options.project_id}`, 404); } if ((error as ApiError).code === 403) { throw createApiError("Access denied to this project", 403); } if ((error as ApiError).code === 401) { throw createApiError("Invalid API key", 401); } throw createUnexpectedError( `Failed to create keys in project ${options.project_id}: ${(error as Error).message}`, ); } }