Initial commit
This commit is contained in:
46
mcp-server/tools/files/delete.js
Normal file
46
mcp-server/tools/files/delete.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import { z } from "zod";
|
||||
import { handleToolError, validateRequired } from "../helpers/errorHandler.js";
|
||||
import { getCurrentProjectInfo, callLocalFileEndpoint, buildLocalFileErrorResponse } from "./helpers.js";
|
||||
|
||||
export function registerAcaiDeleteTool(server) {
|
||||
server.tool(
|
||||
"acai-delete",
|
||||
"Delete a file inside the project. Destructive operation.",
|
||||
{
|
||||
file_path: z.string().describe("Path relative to the project root"),
|
||||
expected_sha256: z.string().optional().describe("Optional safety check before deletion"),
|
||||
},
|
||||
{ readOnlyHint: false, destructiveHint: true },
|
||||
async ({ file_path, expected_sha256 }) => {
|
||||
try {
|
||||
const validationError = validateRequired({ file_path }, ["file_path"], "acai-delete");
|
||||
if (validationError) return validationError;
|
||||
|
||||
const { projectSlug, projectDir } = getCurrentProjectInfo();
|
||||
const result = await callLocalFileEndpoint("POST", "/api/files/delete", {
|
||||
project: projectSlug,
|
||||
projectDir: projectDir,
|
||||
relativePath: file_path,
|
||||
expectedSha256: expected_sha256 || "",
|
||||
});
|
||||
if (!result.data?.success) {
|
||||
return buildLocalFileErrorResponse("acai-delete", result, { file_path });
|
||||
}
|
||||
const data = result.data;
|
||||
|
||||
return {
|
||||
content: [{
|
||||
type: "text",
|
||||
text: JSON.stringify({
|
||||
success: true,
|
||||
file_path: data.filePath,
|
||||
deleted: data.deleted,
|
||||
}, null, 2),
|
||||
}],
|
||||
};
|
||||
} catch (error) {
|
||||
return handleToolError(error, "acai-delete", { file_path });
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user