import_glossary_csv
Upload CSV content to import entries into a glossary. Supports unidirectional (table-uni) and multidirectional (table-multi) formats. Returns an import ID to monitor progress.
Instructions
Imports a CSV file into a glossary. Supports unidirectional and multidirectional formats. This is an async operation that returns an import job object containing an import_id. Poll with check_glossary_import_status using the returned import_id until the import is complete.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The glossary ID (format: gls_*, e.g., 'gls_xyz123') | |
| csv_content | Yes | The content of the CSV file to upload | |
| content_type | Yes | The format of the CSV file. 'csv/table-uni' for unidirectional, 'csv/table-multi' for multidirectional | csv/table-uni |
| gzip | No | Whether the CSV content is gzip compressed |
Implementation Reference
- The main handler function `importGlossaryCsv` that validates input via Zod schema, writes CSV content to a temp file, and calls `lara.glossaries.importCsv()`. Includes a 5MB size limit and cleans up the temp directory in a finally block.
export async function importGlossaryCsv(args: any, lara: Translator) { const validatedArgs = importGlossaryCsvSchema.parse(args); const { id, csv_content, content_type, gzip } = validatedArgs; // File size limit: 5MB const MAX_CSV_SIZE = 5 * 1024 * 1024; if (Buffer.byteLength(csv_content, 'utf8') > MAX_CSV_SIZE) { throw new InvalidInputError("CSV file too large. Maximum allowed size is 5MB."); } const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'lara-csv-')); const tempFilePath = path.join(tempDir, 'import.csv'); try { fs.writeFileSync(tempFilePath, csv_content, { mode: 0o600 }); return await lara.glossaries.importCsv(id, tempFilePath, content_type, gzip); } finally { try { fs.rmSync(tempDir, { recursive: true, force: true }); } catch (_) { /* best-effort cleanup */ } } } - Zod schema `importGlossaryCsvSchema` defining four input fields: id (glossary ID matching gls_* pattern), csv_content (the CSV file content string), content_type (enum csv/table-uni or csv/table-multi, defaults to csv/table-uni), and gzip (optional boolean).
export const importGlossaryCsvSchema = z.object({ id: z.string() .min(1) .max(255) .regex(/^gls_[a-zA-Z0-9_-]+$/, "Invalid glossary ID format") .describe("The glossary ID (format: gls_*, e.g., 'gls_xyz123')"), csv_content: z .string() .describe("The content of the CSV file to upload"), content_type: z .enum(["csv/table-uni", "csv/table-multi"]) .default("csv/table-uni") .describe("The format of the CSV file. 'csv/table-uni' for unidirectional, 'csv/table-multi' for multidirectional"), gzip: z .boolean() .optional() .describe("Whether the CSV content is gzip compressed"), }); - src/mcp/tools.ts:30-30 (registration)Import of `importGlossaryCsv` and `importGlossaryCsvSchema` from the tool module.
import { importGlossaryCsv, importGlossaryCsvSchema } from "./tools/import_glossary_csv.js"; - src/mcp/tools.ts:62-62 (registration)Registration of `import_glossary_csv` handler in the handlers record mapping tool names to handler functions.
import_glossary_csv: importGlossaryCsv, - src/mcp/tools.ts:401-413 (registration)MCP tool definition including name, description, inputSchema (JSON schema from Zod), annotations (title, readOnlyHint false, destructiveHint false), and _meta invocation messages.
{ name: "import_glossary_csv", description: "Imports a CSV file into a glossary. Supports unidirectional and multidirectional formats. This is an async operation that returns an import job object containing an import_id. Poll with check_glossary_import_status using the returned import_id until the import is complete.", inputSchema: z.toJSONSchema(importGlossaryCsvSchema), annotations: { title: "Import glossary CSV", readOnlyHint: false, destructiveHint: false, openWorldHint: false, }, _meta: invocationMeta("Queuing glossary import…", "Glossary import queued"), },