Skip to main content
Glama
translated

Lara Translate MCP Server

by translated

add_translation

Adds a translation to a translation memory in your Lara Translate account by specifying source and target languages, sentences, and translation units.

Instructions

Adds a translation to a translation memory in your Lara Translate account.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesThe ID or list of IDs where to save the translation unit. Format: mem_xyz123
sourceYesThe source language code of the sentence, it MUST be a language supported by the system, use the list_languages tool to get a list of all the supported languages
targetYesThe target language code of the translation, it MUST be a language supported by the system, use the list_languages tool to get a list of all the supported languages
sentenceYesThe source sentence
translationYesThe translated sentence
tuidNoTranslation Unit unique identifier
sentence_beforeNoThe sentence before the source sentence to specify the context of the translation unit
sentence_afterNoThe sentence after the source sentence to specify the context of the translation unit

Implementation Reference

  • The main handler function 'addTranslation' that implements the core logic of the 'add_translation' tool. It parses arguments using the schema, handles conditional logic for context sentences, and calls the underlying Lara API.
    export async function addTranslation(args: unknown, lara: Translator) {
      const validatedArgs = addTranslationSchema.parse(args);
      const {
        id,
        source,
        target,
        sentence,
        translation,
        tuid,
        sentence_before,
        sentence_after,
      } = validatedArgs;
    
      if (!tuid) {
        return await lara.memories.addTranslation(
          id,
          source,
          target,
          sentence,
          translation
        );
      }
    
      if (
        (sentence_before && !sentence_after) ||
        (!sentence_before && sentence_after)
      ) {
        throw new Error("Please provide both sentence_before and sentence_after");
      }
    
      return await lara.memories.addTranslation(
        id,
        source,
        target,
        sentence,
        translation,
        tuid,
        sentence_before,
        sentence_after
      );
    }
  • Zod schema 'addTranslationSchema' defining the input validation for the 'add_translation' tool, including parameters like id, source, target, sentence, translation, and optional context.
    export const addTranslationSchema = z.object({
      id: z
        .array(z.string())
        .describe(
          "The ID or list of IDs where to save the translation unit. Format: mem_xyz123"
        ),
      source: z
        .string()
        .describe(
          "The source language code of the sentence, it MUST be a language supported by the system, use the list_languages tool to get a list of all the supported languages"
        ),
      target: z
        .string()
        .describe(
          "The target language code of the translation, it MUST be a language supported by the system, use the list_languages tool to get a list of all the supported languages"
        ),
      sentence: z.string().describe("The source sentence"),
      translation: z.string().describe("The translated sentence"),
      tuid: z.string().describe("Translation Unit unique identifier").optional(),
      sentence_before: z
        .string()
        .describe(
          "The sentence before the source sentence to specify the context of the translation unit"
        )
        .optional(),
      sentence_after: z
        .string()
        .describe(
          "The sentence after the source sentence to specify the context of the translation unit"
        )
        .optional(),
    });
  • src/mcp/tools.ts:36-45 (registration)
    Registration of the 'add_translation' handler in the central handlers map used by CallTool to dispatch tool calls.
    const handlers: Record<string, Handler> = {
      translate: translateHandler,
      create_memory: createMemory,
      delete_memory: deleteMemory,
      update_memory: updateMemory,
      add_translation: addTranslation,
      delete_translation: deleteTranslation,
      import_tmx: importTmx,
      check_import_status: checkImportStatus,
    };
  • Registration of the 'add_translation' tool in the ListTools response, including its name, description, and input schema.
    {
      name: "add_translation",
      description:
        "Adds a translation to a translation memory in your Lara Translate account.",
      inputSchema: z.toJSONSchema(addTranslationSchema),
    },
  • src/mcp/tools.ts:8-11 (registration)
    Import statement bringing in the addTranslation handler and addTranslationSchema from the add_translation module.
    import {
      addTranslation,
      addTranslationSchema,
    } from "./tools/add_translation.js";

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/translated/lara-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server