Skip to main content
Glama

clear_all_tasks

Clear unfinished tasks and reset the task list on mcp-chain-of-thought server. Use this tool to remove all pending tasks, ensuring a clean slate for new tasks.

Instructions

Clear unfinished tasks and reset the task list

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
confirmYesConfirm to delete all unfinished tasks (this operation is irreversible)

Implementation Reference

  • The handler function for the 'clear_all_tasks' tool. Validates the confirm parameter, checks if tasks exist, invokes the modelClearAllTasks function to perform the clearing, and returns a formatted response using prompts.
    export async function clearAllTasks({ confirm, }: z.infer<typeof clearAllTasksSchema>) { // Security check: If not confirmed, refuse operation if (!confirm) { return { content: [ { type: "text" as const, text: getClearAllTasksPrompt({ confirm: false }), }, ], }; } // Check if there are really tasks to clear const allTasks = await getAllTasks(); if (allTasks.length === 0) { return { content: [ { type: "text" as const, text: getClearAllTasksPrompt({ isEmpty: true }), }, ], }; } // Execute clear operation const result = await modelClearAllTasks(); return { content: [ { type: "text" as const, text: getClearAllTasksPrompt({ success: result.success, message: result.message, backupFile: result.backupFile, }), }, ], isError: !result.success, }; }
  • Zod schema defining the input parameters for the clear_all_tasks tool, requiring explicit confirmation via a boolean flag.
    export const clearAllTasksSchema = z.object({ confirm: z .boolean() .refine((val) => val === true, { message: "Must clearly confirm the clear operation, please set the confirm parameter to true to confirm this dangerous operation", }) .describe("Confirm to delete all unfinished tasks (this operation is irreversible)"), });
  • src/index.ts:290-296 (registration)
    Registration of the 'clear_all_tasks' tool in the MCP server's list of tools, including name, description from MD template, and input schema conversion.
    { name: "clear_all_tasks", description: loadPromptFromTemplate( "toolsDescription/clearAllTasks.md" ), inputSchema: zodToJsonSchema(clearAllTasksSchema), },
  • Core helper function (aliased as modelClearAllTasks) that implements the task clearing logic: backs up completed tasks to a timestamped JSON file in the memory directory and clears all unfinished tasks from the main tasks.json file.
    export async function clearAllTasks(): Promise<{ success: boolean; message: string; backupFile?: string; }> { try { // Ensure data directory exists await ensureDataDir(); // Read existing tasks const allTasks = await readTasks(); // If there are no tasks, return directly if (allTasks.length === 0) { return { success: true, message: "No tasks need to be cleared" }; } // Filter out completed tasks const completedTasks = allTasks.filter( (task) => task.status === TaskStatus.COMPLETED ); // Create backup file name const timestamp = new Date() .toISOString() .replace(/:/g, "-") .replace(/\..+/, ""); const backupFileName = `tasks_memory_${timestamp}.json`; // Ensure memory directory exists const MEMORY_DIR = path.join(DATA_DIR, "memory"); try { await fs.access(MEMORY_DIR); } catch (error) { await fs.mkdir(MEMORY_DIR, { recursive: true }); } // Create memory directory backup path const memoryFilePath = path.join(MEMORY_DIR, backupFileName); // Write to memory directory at the same time (only include completed tasks) await fs.writeFile( memoryFilePath, JSON.stringify({ tasks: completedTasks }, null, 2) ); // Clear task file await writeTasks([]); return { success: true, message: `All tasks cleared successfully, ${allTasks.length} tasks deleted, ${completedTasks.length} completed tasks backed up to memory directory`, backupFile: backupFileName, }; } catch (error) { return { success: false, message: `Error clearing tasks: ${ error instanceof Error ? error.message : String(error) }`, }; } }
  • Helper function that generates context-aware prompts for the clear_all_tasks tool responses, handling cases like unconfirmed, empty tasks, success/failure with backup info.
    export function getClearAllTasksPrompt( params: ClearAllTasksPromptParams ): string { const { confirm, success, message, backupFile, isEmpty } = params; // Handle unconfirmed case if (confirm === false) { const cancelTemplate = loadPromptFromTemplate("clearAllTasks/cancel.md"); return generatePrompt(cancelTemplate, {}); } // Handle case when no tasks need to be cleared if (isEmpty) { const emptyTemplate = loadPromptFromTemplate("clearAllTasks/empty.md"); return generatePrompt(emptyTemplate, {}); } // Handle successful or failed clearing const responseTitle = success ? "Success" : "Failure"; // Generate backupInfo using template const backupInfo = backupFile ? generatePrompt(loadPromptFromTemplate("clearAllTasks/backupInfo.md"), { backupFile, }) : ""; const indexTemplate = loadPromptFromTemplate("clearAllTasks/index.md"); const prompt = generatePrompt(indexTemplate, { responseTitle, message, backupInfo, }); // Load possible custom prompt return loadPrompt(prompt, "CLEAR_ALL_TASKS"); }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/liorfranko/mcp-chain-of-thought'

If you have feedback or need assistance with the MCP directory API, please join our Discord server