import { z } from "zod"; import { withAuth, getSessionCredentials } from "../../auth/index.js"; import { handleApiResponse, handleToolError, validateRequired } from "../helpers/errorHandler.js"; import { AcaiHttpClient } from "../helpers/acaiHttpClient.js"; import { withAuthParams } from "../helpers/authSchema.js"; export function registerGetModuleConfigVarsTool(server) { server.tool( "get_module_config_vars", `Get the current configuration variable values for a module instance on a page record. Returns resolved values (text, HTML, etc.) for simple vars and arrays of objects for multi/repeater vars. Required params: - tableName (string) without 'cms_' prefix - recordNum (number) record primary key ('num' field, never 'id') - sectionId (string) section ID of the module instance`, withAuthParams({ tableName: z.string().describe("Parent table name (e.g. 'apartados')"), recordNum: z.number().describe("Parent record number"), sectionId: z.string().describe("Section ID of the module instance"), }), { readOnlyHint: true, destructiveHint: false }, withAuth(async ({ tableName, recordNum, sectionId }, extra) => { try { const validationError = validateRequired({ tableName, recordNum, sectionId }, ['tableName', 'recordNum', 'sectionId'], 'get_module_config_vars'); if (validationError) return validationError; const sessionId = extra.sessionId; const credentials = await getSessionCredentials(sessionId); const payload = { tableName, recordNum, sectionId }; const response = await AcaiHttpClient.getModuleConfigVars( credentials, credentials.token, credentials.tokenHash, payload ); const apiError = handleApiResponse(response.data, 'get_module_config_vars'); if (apiError) return apiError; return { content: [{ type: "text", text: JSON.stringify({ success: true, action: 'get_module_config_vars', tableName, recordNum, sectionId, data: response.data?.data ?? response.data }, null, 2) }] }; } catch (error) { return handleToolError(error, 'get_module_config_vars', { tableName, recordNum, sectionId }); } }) ); }