mcp tablas
This commit is contained in:
@@ -1,52 +1,49 @@
|
||||
import { z } from "zod";
|
||||
import { withAuth, getSessionCredentials } from "../../auth/index.js";
|
||||
import { handleToolError, validateRequired, handleApiResponse } from "../helpers/errorHandler.js";
|
||||
import { AcaiHttpClient, FormParamsBuilder } from "../helpers/acaiHttpClient.js";
|
||||
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_table
|
||||
// Borra el schema (ini.php) de una tabla. Si dropData=true tambien hace DROP TABLE
|
||||
// en MySQL — destruye los datos de forma IRREVERSIBLE. Si la tabla tiene registros
|
||||
// y dropData=false el backend devuelve error con recordCount (intencional: no se
|
||||
// debe borrar el schema dejando datos huerfanos en MySQL sin confirmacion explicita).
|
||||
|
||||
export function registerDeleteTableTool(server) {
|
||||
server.tool(
|
||||
"delete_table",
|
||||
"⚠️ DANGEROUS: Delete a database table/module entirely. This removes the table definition and all its data. This operation is IRREVERSIBLE. Table names are WITHOUT the 'cms_' prefix.",
|
||||
`Delete a table from the project. IRREVERSIBLE when dropData=true.
|
||||
|
||||
Behaviour:
|
||||
- dropData=false (default): deletes the schema (.ini.php). If the MySQL table
|
||||
has records, the backend refuses and returns recordCount so you can warn
|
||||
the user.
|
||||
- dropData=true: DROP TABLE in MySQL + delete schema. Data is permanently
|
||||
destroyed.
|
||||
- dryRun=true: does not delete anything, only reports recordCount. Use as a
|
||||
pre-flight check before asking the user for confirmation.
|
||||
|
||||
Table names are WITHOUT the 'cms_' prefix.`,
|
||||
withAuthParams({
|
||||
tableName: z.string().describe("Name of the table/module to delete (without 'cms_' prefix, e.g., 'equipo')"),
|
||||
tableName: z.string().describe("Table name without 'cms_' prefix"),
|
||||
dropData: z.boolean().optional().describe("If true, DROP the MySQL table. Default false."),
|
||||
dryRun: z.boolean().optional().describe("If true, only report recordCount without deleting. Default false."),
|
||||
}),
|
||||
{ readOnlyHint: false, destructiveHint: true },
|
||||
withAuth(async ({ tableName }, extra) => {
|
||||
withAuth(async ({ tableName, dropData, dryRun }, _extra) => {
|
||||
try {
|
||||
// Validate required parameters
|
||||
const validationError = validateRequired({ tableName }, ['tableName'], 'delete_table');
|
||||
if (validationError) return validationError;
|
||||
|
||||
// Build delete table parameters using centralized builder
|
||||
const params = FormParamsBuilder.buildTableDeleteParams(tableName);
|
||||
const credentials = await getSessionCredentials(extra.sessionId);
|
||||
|
||||
// Delete table via Acai CMS admin using centralized HTTP client
|
||||
const response = await AcaiHttpClient.postAdminForm(
|
||||
credentials.website,
|
||||
params,
|
||||
credentials.token
|
||||
);
|
||||
|
||||
// Check for API errors
|
||||
const apiError = handleApiResponse(response.data, 'delete_table');
|
||||
if (apiError) return apiError;
|
||||
|
||||
return {
|
||||
content: [{
|
||||
type: "text",
|
||||
text: JSON.stringify({
|
||||
success: true,
|
||||
message: `Table '${tableName}' deleted successfully`
|
||||
}, null, 2)
|
||||
}],
|
||||
const body = {
|
||||
tableName,
|
||||
confirm: true,
|
||||
dropData: dropData === true,
|
||||
dryRun: dryRun === true,
|
||||
};
|
||||
const { mcp } = await callSchemaEndpoint("/api/schema/delete-table", body);
|
||||
return mcp;
|
||||
} catch (error) {
|
||||
return handleToolError(error, 'delete_table', { tableName });
|
||||
return handleToolError(error, "delete_table", { tableName, dropData: dropData === true, dryRun: dryRun === true });
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user