feat(mcp): tools de idiomas y traducciones

- Nueva categoria tools/languages: list_web_languages,
  get_record_translations y set_record_translations (registros, config,
  textos_generales y vars de modulo via builder_custom).
- Param lang opcional en list_table_records y get_record
  (options.translates de CocoDB).
- Docs actualizados (03/04/06/09/11b + ACAI_ENDPOINTS) con el modelo de
  cms_traducciones y los workflows de traduccion.
This commit is contained in:
Jordan Diaz
2026-07-16 20:09:47 +00:00
parent d475845c27
commit d46c204ed0
13 changed files with 382 additions and 3 deletions

View File

@@ -0,0 +1,74 @@
import { z } from "zod";
import { withAuth, getSessionCredentials } from "../../auth/index.js";
import { handleToolError, validateRequired, handleApiResponse } from "../helpers/errorHandler.js";
import { AcaiHttpClient } from "../helpers/acaiHttpClient.js";
import { withAuthParams } from "../helpers/authSchema.js";
export function registerGetRecordTranslationsTool(server) {
server.tool(
"get_record_translations",
`Read the stored translations for one or more records of a table, from the central cms_traducciones table.
Translations are keyed by (prefix = language code, tableName without 'cms_', fieldName, recordNum). Values are stored Base64 in the DB but this tool returns them already decoded (plain text). An absent field/prefix means there is no translation and the base-language value is used at runtime.
Params:
- tableName: table name WITHOUT the 'cms_' prefix (e.g. 'apartados', 'productos', 'builder_custom', 'textos_generales').
- recordNums: array of record 'num' primary keys to read.
- fields (optional): only return these field names. Omit to return every translated field found.
- prefix (optional): only return translations for this language prefix (e.g. 'en'). Omit to return all languages.
Returns translations shaped as { "<recordNum>": { "<prefix>": { "<fieldName>": "<value>" } } }.
To translate module vars, first call get_module_config_vars to obtain varsMeta ({ fieldName, recordNum } per var) and read from tableName='builder_custom'. For template literals, read tableName='textos_generales' field 'texto'.`,
withAuthParams({
tableName: z.string().describe("Table name without 'cms_' prefix (e.g. 'apartados', 'builder_custom', 'textos_generales')"),
recordNums: z.array(z.number()).describe("Array of record 'num' primary keys to read translations for"),
fields: z.array(z.string()).optional().describe("Only return these field names. Omit to return all translated fields."),
prefix: z.string().optional().describe("Only return translations for this language prefix (e.g. 'en'). Omit for all languages."),
}),
{ readOnlyHint: true, destructiveHint: false },
withAuth(async ({ tableName, recordNums, fields, prefix }, extra) => {
try {
const validationError = validateRequired(
{ tableName, recordNums },
["tableName", "recordNums"],
"get_record_translations"
);
if (validationError) return validationError;
const credentials = await getSessionCredentials(extra.sessionId);
const payload = { tableName, recordNums };
if (fields && fields.length > 0) payload.fields = fields;
if (prefix) payload.prefix = prefix;
const response = await AcaiHttpClient.postViewerAction(
credentials,
"getTranslations",
payload,
credentials.token,
credentials.tokenHash,
{},
15000
);
const apiError = handleApiResponse(response.data, "get_record_translations");
if (apiError) return apiError;
return {
content: [{
type: "text",
text: JSON.stringify({
success: true,
action: "get_record_translations",
tableName: response.data?.tableName || tableName,
translations: response.data?.translations || {},
}, null, 2)
}],
};
} catch (error) {
return handleToolError(error, "get_record_translations", { tableName, recordNums });
}
})
);
}