Initial commit
This commit is contained in:
52
mcp-server/tools/tables/delete.js
Normal file
52
mcp-server/tools/tables/delete.js
Normal file
@@ -0,0 +1,52 @@
|
||||
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 { withAuthParams } from "../helpers/authSchema.js";
|
||||
|
||||
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.",
|
||||
withAuthParams({
|
||||
tableName: z.string().describe("Name of the table/module to delete (without 'cms_' prefix, e.g., 'equipo')"),
|
||||
}),
|
||||
{ readOnlyHint: false, destructiveHint: true },
|
||||
withAuth(async ({ tableName }, 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)
|
||||
}],
|
||||
};
|
||||
} catch (error) {
|
||||
return handleToolError(error, 'delete_table', { tableName });
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user