Skip to main content
Glama
108yen
by 108yen

deleteTask

Remove a specific task by its ID from the task-orchestrator-mcp server to manage task workflows efficiently.

Instructions

Delete a task by its ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesTask ID

Implementation Reference

  • The deleteTask function implements the core logic: validates ID, finds task, checks no children, removes from parent/root, persists changes, returns deleted ID.
    export function deleteTask(id: string): { id: string } { if (!id || typeof id !== "string") { throw new Error("Task ID is required and must be a string") } const tasks = readTasks() const taskToDelete = findTaskById(tasks, id) if (!taskToDelete) { throw new Error(`Task with id '${id}' not found`) } // Check if task has child tasks if (taskToDelete.tasks.length > 0) { throw new Error( `Cannot delete task '${id}' because it has child tasks. Please delete all child tasks first.`, ) } // Find and remove task from parent's tasks array or root level const parentTask = findParentTask(tasks, id) if (parentTask) { // Remove from parent's tasks array const index = parentTask.tasks.findIndex((t) => t.id === id) if (index !== -1) { parentTask.tasks.splice(index, 1) } } else { // Remove from root level const index = tasks.findIndex((t) => t.id === id) if (index !== -1) { tasks.splice(index, 1) } } writeTasks(tasks) return { id } }
  • src/tools.ts:277-318 (registration)
    Registers the deleteTask tool with the MCP server, providing description, Zod input schema (id: string), and error-handling wrapper that calls the deleteTask function.
    server.registerTool( "deleteTask", { description: "Delete a task by its ID", inputSchema: { id: z.string().describe("Task ID"), }, }, (args) => { try { const result = deleteTask(args.id) return { content: [ { text: JSON.stringify(result, null, 2), type: "text", }, ], } } catch (error) { return { content: [ { text: JSON.stringify( { error: { code: "TASK_DELETE_ERROR", message: error instanceof Error ? error.message : "Unknown error", }, }, null, 2, ), type: "text", }, ], isError: true, } } }, )
  • Zod input schema for deleteTask tool: requires 'id' as string.
    id: z.string().describe("Task ID"), },
  • Recursive helper to find task by ID in nested structure, used by deleteTask.
    export function findTaskById(tasks: Task[], id: string): Task | undefined { for (const task of tasks) { if (task.id === id) { return task } const found = findTaskById(task.tasks, id) if (found) { return found } } return undefined }
  • Recursive helper to find parent task of a given task ID, used by deleteTask to locate and remove the task.
    export function findParentTask( tasks: Task[], targetId: string, ): Task | undefined { for (const task of tasks) { // Check if target is direct child if (task.tasks.some((child) => child.id === targetId)) { return task } // Recursively search in subtasks const parentFound = findParentTask(task.tasks, targetId) if (parentFound) { return parentFound } } return undefined }

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/108yen/task-orchestrator-mcp'

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