import_tmx
Update a translation memory by importing a TMX file. Returns an import ID to track the asynchronous operation until completion.
Instructions
Imports a TMX file into a translation memory. This is an async operation that returns an import job object containing an import_id. Poll with check_import_status using the returned import_id until the import is complete.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the memory to update. Format: mem_xyz123. | |
| tmx_content | Yes | The content of the tmx file to upload. |
Implementation Reference
- src/mcp/tools/import_tmx.ts:21-43 (handler)The main handler function for the import_tmx tool. Validates input args, enforces a 5MB limit on TMX content, writes the content to a temp file, calls lara.memories.importTmx, and cleans up the temp file afterwards.
export async function importTmx(args: any, lara: Translator) { const validatedArgs = importTmxSchema.parse(args); const { id, tmx_content } = validatedArgs; // File size limit: 5MB const MAX_TMX_SIZE = 5 * 1024 * 1024; if (Buffer.byteLength(tmx_content, 'utf8') > MAX_TMX_SIZE) { throw new InvalidInputError("TMX file too large. Maximum allowed size is 5MB."); } const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'lara-tmx-')); const tempFilePath = path.join(tempDir, 'import.tmx'); try { fs.writeFileSync(tempFilePath, tmx_content, { mode: 0o600 }); return await lara.memories.importTmx(id, tempFilePath); } finally { try { fs.rmSync(tempDir, { recursive: true, force: true }); } catch (_) { /* best-effort cleanup */ } } } - src/mcp/tools/import_tmx.ts:8-19 (schema)Zod schema defining the input parameters for import_tmx: id (memory ID, format mem_xyz123) and tmx_content (the TMX file content string).
export const importTmxSchema = z.object({ id: z .string() .describe( "The ID of the memory to update. Format: mem_xyz123." ), tmx_content: z .string() .describe( "The content of the tmx file to upload." ), }); - src/mcp/tools.ts:56-68 (registration)Registration of import_tmx in the handlers map, mapping the tool name 'import_tmx' to the importTmx handler function.
import_tmx: importTmx, check_import_status: checkImportStatus, get_glossary: getGlossary, create_glossary: createGlossary, update_glossary: updateGlossary, delete_glossary: deleteGlossary, import_glossary_csv: importGlossaryCsv, check_glossary_import_status: checkGlossaryImportStatus, export_glossary: exportGlossary, get_glossary_counts: getGlossaryCounts, add_glossary_entry: addGlossaryEntry, delete_glossary_entry: deleteGlossaryEntry, }; - src/mcp/tools.ts:291-303 (registration)Tool definition for import_tmx including name, description, inputSchema (generated from importTmxSchema via z.toJSONSchema), annotations (title, readOnlyHint, destructiveHint, openWorldHint), and invocation meta.
{ name: "import_tmx", description: "Imports a TMX file into a translation memory. This is an async operation that returns an import job object containing an import_id. Poll with check_import_status using the returned import_id until the import is complete.", inputSchema: z.toJSONSchema(importTmxSchema), annotations: { title: "Import TMX file", readOnlyHint: false, destructiveHint: false, openWorldHint: false, }, _meta: invocationMeta("Queuing TMX import…", "TMX import queued"), }, - src/mcp/tools.ts:113-114 (helper)Helper narrate function case for import_tmx: returns a human-readable message when the tool completes, including the job ID if present.
case "import_tmx": return `Queued TMX import${result?.id ? " (job " + result.id + ")" : ""}`;