deleteProject
Permanently deletes a project, including all associated tasks and dependencies, using the project ID. Returns a success confirmation. Ensure the action is intended, as it cannot be undone.
Instructions
Permanently deletes a project and ALL associated tasks and dependencies. Requires the project ID. This is a highly destructive operation and cannot be undone. Returns a success confirmation upon completion.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | The unique identifier (UUID) of the project to permanently delete. This project must exist. |
Implementation Reference
- src/tools/deleteProjectTool.ts:16-43 (handler)The MCP tool handler: processRequest function executes the deleteProject logic by calling ProjectService.deleteProject, logs actions, returns JSON success response, and maps errors to McpError types.const processRequest = async (args: DeleteProjectArgs): Promise<{ content: { type: 'text', text: string }[] }> => { logger.warn(`[${TOOL_NAME}] Received request to DELETE project ${args.project_id}. This is a destructive operation.`); // Log deletion intent clearly try { // Call the service method to delete the project const success = await projectService.deleteProject(args.project_id); // Format the successful response logger.info(`[${TOOL_NAME}] Successfully deleted project ${args.project_id}`); return { content: [{ type: "text" as const, text: JSON.stringify({ success: success }) // Return true if deleted }] }; } catch (error: unknown) { // Handle potential errors according to systemPatterns.md mapping logger.error(`[${TOOL_NAME}] Error processing request:`, error); if (error instanceof NotFoundError) { // Project not found - Map to InvalidParams as per convention throw new McpError(ErrorCode.InvalidParams, error.message); } else { // Generic internal error const message = error instanceof Error ? error.message : 'An unknown error occurred while deleting the project.'; throw new McpError(ErrorCode.InternalError, message); } } };
- Defines the tool name 'deleteProject', description, Zod input schema TOOL_PARAMS requiring project_id UUID, and inferred DeleteProjectArgs type.export const TOOL_NAME = "deleteProject"; export const TOOL_DESCRIPTION = ` Permanently deletes a project and ALL associated tasks and dependencies. Requires the project ID. This is a highly destructive operation and cannot be undone. Returns a success confirmation upon completion. `; // Zod schema for the parameters, matching FR-013 export const TOOL_PARAMS = z.object({ project_id: z.string() .uuid("The project_id must be a valid UUID.") .describe("The unique identifier (UUID) of the project to permanently delete. This project must exist."), // Required, UUID format }); // Define the expected type for arguments based on the Zod schema export type DeleteProjectArgs = z.infer<typeof TOOL_PARAMS>;
- src/tools/deleteProjectTool.ts:45-48 (registration)Registers the deleteProject tool on the McpServer instance using server.tool() with name, description, params schema, and handler.// Register the tool with the server server.tool(TOOL_NAME, TOOL_DESCRIPTION, TOOL_PARAMS.shape, processRequest); // Using .shape as this schema doesn't use .refine() logger.info(`[${TOOL_NAME}] Tool registered successfully.`);
- src/tools/index.ts:64-64 (registration)Central registration: calls deleteProjectTool(server, projectService) from within registerTools() to register the tool.deleteProjectTool(server, projectService); // Register deleteProject tool (uses ProjectService)
- ProjectService.deleteProject: validates project exists, calls repository to delete (cascades to tasks/dependencies), returns true on success.public async deleteProject(projectId: string): Promise<boolean> { logger.info(`[ProjectService] Attempting to delete project: ${projectId}`); // 1. Validate Project Existence *before* attempting delete const projectExists = this.projectRepository.findById(projectId); if (!projectExists) { logger.warn(`[ProjectService] Project not found for deletion: ${projectId}`); throw new NotFoundError(`Project with ID ${projectId} not found.`); } // 2. Call Repository delete method try { // The repository method handles the actual DELETE operation on the projects table. // Cascade delete defined in the schema handles tasks and dependencies. const deletedCount = this.projectRepository.deleteProject(projectId); if (deletedCount !== 1) { // This shouldn't happen if findById succeeded, but log a warning if it does. logger.warn(`[ProjectService] Expected to delete 1 project, but repository reported ${deletedCount} deletions for project ${projectId}.`); // Still return true as the project is gone, but log indicates potential issue. } logger.info(`[ProjectService] Successfully deleted project ${projectId} and associated data.`); return true; // Indicate success } catch (error) { logger.error(`[ProjectService] Error deleting project ${projectId}:`, error); throw error; // Re-throw database or other errors } }