import { z } from "zod"; import { withAuth } from "../../auth/index.js"; import { withAuthParams } from "../helpers/authSchema.js"; import { handleToolError } from "../helpers/errorHandler.js"; import { callSchemaEndpoint } from "./_schemaEndpoint.js"; // Tool: reorder_fields // Reasigna el orden de los campos editables de una tabla. Los campos de // sistema (num, creationDate, etc.) se ignoran; solo afecta al orden visual // en el formulario del admin. export function registerReorderFieldsTool(server) { server.tool( "reorder_fields", `Reorder fields inside a table's admin form. Pass the full ordered list of fieldNames; system fields (num, creationDate, etc.) are ignored by the backend. Data is untouched. Table names WITHOUT 'cms_' prefix.`, withAuthParams({ tableName: z.string().describe("Table name without 'cms_' prefix"), order: z.array(z.string().min(1)).min(1).describe("Ordered list of fieldNames"), }), { readOnlyHint: false, destructiveHint: false }, withAuth(async ({ tableName, order }, _extra) => { try { const { mcp } = await callSchemaEndpoint("/api/schema/reorder-fields", { tableName, order }); return mcp; } catch (error) { return handleToolError(error, "reorder_fields", { tableName, count: Array.isArray(order) ? order.length : 0 }); } }) ); }