mcp tablas
This commit is contained in:
45
mcp-server/tools/tables/deleteField.js
Normal file
45
mcp-server/tools/tables/deleteField.js
Normal 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 });
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user