@pimzino/agentic-tools-mcp
Version:
A comprehensive MCP server for task management and agent memories with JSON file storage
87 lines (84 loc) • 3.19 kB
JavaScript
import { z } from 'zod';
/**
* Delete a subtask
*
* @param storage - Storage instance
* @returns MCP tool handler for deleting subtasks
*/
export function createDeleteSubtaskTool(storage) {
return {
name: 'delete_subtask',
description: 'Delete a subtask. This action cannot be undone.',
inputSchema: {
id: z.string(),
confirm: z.boolean()
},
handler: async ({ id, confirm }) => {
try {
// Validate inputs
if (!id || id.trim().length === 0) {
return {
content: [{
type: 'text',
text: 'Error: Subtask ID is required.'
}],
isError: true
};
}
if (confirm !== true) {
return {
content: [{
type: 'text',
text: 'Error: You must set confirm to true to delete a subtask.'
}],
isError: true
};
}
const subtask = await storage.getSubtask(id.trim());
if (!subtask) {
return {
content: [{
type: 'text',
text: `Error: Subtask with ID "${id}" not found. Use list_subtasks to see all available subtasks.`
}],
isError: true
};
}
// Get task and project information for display
const task = await storage.getTask(subtask.taskId);
const project = await storage.getProject(subtask.projectId);
const taskName = task ? task.name : 'Unknown Task';
const projectName = project ? project.name : 'Unknown Project';
const deleted = await storage.deleteSubtask(id);
if (!deleted) {
return {
content: [{
type: 'text',
text: `Error: Failed to delete subtask with ID "${id}".`
}],
isError: true
};
}
return {
content: [{
type: 'text',
text: `✅ Subtask deleted successfully!
**Deleted:** "${subtask.name}" (ID: ${subtask.id})
**Task:** ${taskName}
**Project:** ${projectName}
This action cannot be undone. The subtask has been permanently removed.`
}]
};
}
catch (error) {
return {
content: [{
type: 'text',
text: `Error deleting subtask: ${error instanceof Error ? error.message : 'Unknown error'}`
}],
isError: true
};
}
}
};
}