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: delete_field
// Borra un campo del schema y opcionalmente su columna MySQL (dropColumn=true).
// Si dropColumn=false y la columna tiene datos, el backend devuelve error con
// dataCount para permitir confirmacion explicita.
export function registerDeleteFieldTool(server) {
server.tool(
"delete_field",
`Delete a field from a table.
- dropColumn=false (default): removes only the schema entry. If the MySQL
column has data, backend refuses and returns dataCount so you can warn
the user.
- dropColumn=true: ALTER TABLE DROP COLUMN. Data in that column is lost
permanently.
Table names WITHOUT 'cms_' prefix.`,
withAuthParams({
tableName: z.string().describe("Table name without 'cms_' prefix"),
fieldName: z.string().describe("Field name to delete"),
dropColumn: z.boolean().optional().describe("If true, DROP COLUMN in MySQL. Default false."),
}),
{ readOnlyHint: false, destructiveHint: true },
withAuth(async ({ tableName, fieldName, dropColumn }, _extra) => {
try {
const body = {
tableName,
fieldName,
confirm: true,
dropColumn: dropColumn === true,
};
const { mcp } = await callSchemaEndpoint("/api/schema/delete-field", body);
return mcp;
} catch (error) {
return handleToolError(error, "delete_field", { tableName, fieldName, dropColumn: dropColumn === true });
}
})
);
}