mcp tablas

This commit is contained in:
Jordan Diaz
2026-04-25 08:51:17 +00:00
parent 62239cb0a5
commit e84a36c83d
17 changed files with 535 additions and 497 deletions

View File

@@ -0,0 +1,45 @@
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: regenerate_enlaces
// Recalcula el campo `enlace` (slug) de todos los registros de una tabla.
// Cambia URLs publicas — destructivo para SEO / links externos. Si
// generateAlias=true se crean entradas en `alias_urls` para que los links
// viejos sigan funcionando.
export function registerRegenerateEnlacesTool(server) {
server.tool(
"regenerate_enlaces",
`Regenerate the 'enlace' (URL slug) of every record in a table.
Changes PUBLIC URLs — anything linking to the old slugs (external sites, saved
bookmarks, search engines) will 404 unless you opt into alias redirects.
- generateAlias=false (default): only updates the 'enlace' column. Old URLs
return 404.
- generateAlias=true: also writes entries into 'alias_urls' so old URLs
redirect to the new ones. Safer choice when the table is already public.
Table names WITHOUT 'cms_' prefix.`,
withAuthParams({
tableName: z.string().describe("Table name without 'cms_' prefix"),
generateAlias: z.boolean().optional().describe("If true, write redirects into alias_urls. Default false."),
}),
{ readOnlyHint: false, destructiveHint: true },
withAuth(async ({ tableName, generateAlias }, _extra) => {
try {
const body = {
tableName,
generateAlias: generateAlias === true,
};
const { mcp } = await callSchemaEndpoint("/api/schema/regenerate-enlaces", body);
return mcp;
} catch (error) {
return handleToolError(error, "regenerate_enlaces", { tableName, generateAlias: generateAlias === true });
}
})
);
}