Skip to main content
Glama

get_tasks

Retrieve tasks for a specific goal with flexible options for subtask inclusion, task filtering, and detail level control.

Instructions

Get tasks for a goal. Task IDs use a dot-notation (e.g., "1", "1.1", "1.1.1"). When includeSubtasks is specified, responses will return hierarchical task objects. Otherwise, simplified task objects without createdAt, updatedAt, or parentId will be returned.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
goalIdYesID of the goal to get tasks for (number)
taskIdsNoOptional: IDs of tasks to fetch (array of strings). If null or empty, all tasks for the goal will be fetched.
includeSubtasksNoLevel of subtasks to include: "none" (only top-level tasks), "first-level" (top-level tasks and their direct children), or "recursive" (all nested subtasks). Defaults to "none".none
includeDeletedTasksNoWhether to include soft-deleted tasks in the results (boolean). Defaults to false.

Implementation Reference

  • The MCP CallToolRequestSchema handler case for 'get_tasks': extracts parameters from request, calls storage.getTasks with appropriate arguments, maps the fetched tasks to TaskResponse format (excluding internal fields like timestamps and parentId), stringifies to JSON, and returns as text content.
    case 'get_tasks': { const { goalId, taskIds, includeSubtasks = 'none', includeDeletedTasks = false } = request.params.arguments as { goalId: number; taskIds?: string[]; includeSubtasks?: 'none' | 'first-level' | 'recursive'; includeDeletedTasks?: boolean; }; // If taskIds are provided, fetch specific tasks. Otherwise, fetch all tasks for the goal. const fetchedTasks: TaskResponse[] = await storage.getTasks(goalId, taskIds && taskIds.length > 0 ? taskIds : undefined, includeSubtasks, includeDeletedTasks); // Map Task objects to TaskResponse objects to match the schema description const taskResponses: TaskResponse[] = fetchedTasks.map(task => ({ id: task.id, goalId: task.goalId, title: task.title, description: task.description, isComplete: task.isComplete, deleted: task.deleted, })); const textContent = JSON.stringify(taskResponses, null, 2); return { content: [ { type: 'text', text: textContent, }, ], }; }
  • src/index.ts:132-163 (registration)
    Tool registration in ListToolsRequestSchema handler: defines name 'get_tasks', description, and detailed inputSchema for parameters like goalId, optional taskIds, includeSubtasks levels, and includeDeletedTasks.
    { name: 'get_tasks', description: 'Get tasks for a goal. Task IDs use a dot-notation (e.g., "1", "1.1", "1.1.1"). When `includeSubtasks` is specified, responses will return hierarchical task objects. Otherwise, simplified task objects without `createdAt`, `updatedAt`, or `parentId` will be returned.', inputSchema: { type: 'object', properties: { goalId: { type: 'number', description: 'ID of the goal to get tasks for (number)', }, taskIds: { type: 'array', items: { type: 'string', }, description: 'Optional: IDs of tasks to fetch (array of strings). If null or empty, all tasks for the goal will be fetched.', }, includeSubtasks: { type: 'string', description: 'Level of subtasks to include: "none" (only top-level tasks), "first-level" (top-level tasks and their direct children), or "recursive" (all nested subtasks). Defaults to "none".', enum: ['none', 'first-level', 'recursive'], default: 'none', }, includeDeletedTasks: { type: 'boolean', description: 'Whether to include soft-deleted tasks in the results (boolean). Defaults to false.', default: false, }, }, required: ['goalId'], }, },
  • Storage helper method implementing the core getTasks logic: retrieves tasks from LokiDB for the goal, optionally filters deleted tasks, handles fetching specific taskIds or all tasks, recursively or partially includes subtasks based on includeSubtasks parameter, deduplicates, sorts hierarchically by task ID, and maps to clean TaskResponse objects excluding internal fields.
    async getTasks( goalId: number, taskIds?: string[], includeSubtasks: 'none' | 'first-level' | 'recursive' = 'none', includeDeletedTasks: boolean = false ): Promise<TaskResponse[]> { let tasksToConsider = this.tasks.find({ goalId }); // Filter out deleted tasks unless explicitly requested if (!includeDeletedTasks) { tasksToConsider = tasksToConsider.filter(task => !task.deleted); } let resultTasks: LokiTask[] = []; if (taskIds && taskIds.length > 0) { // If specific taskIds are provided, start with those tasks const initialTasks = tasksToConsider.filter(task => taskIds.includes(task.id)); resultTasks.push(...initialTasks); if (includeSubtasks === 'first-level') { // Add direct children of the initial tasks for (const task of initialTasks) { const directChildren = tasksToConsider.filter(child => child.parentId === task.id); resultTasks.push(...directChildren); } } else if (includeSubtasks === 'recursive') { // Add all recursive children of the initial tasks const addRecursiveChildren = (parentTaskId: string) => { const children = tasksToConsider.filter(child => child.parentId === parentTaskId); for (const child of children) { resultTasks.push(child); addRecursiveChildren(child.id); } }; for (const task of initialTasks) { addRecursiveChildren(task.id); } } } else { // If no specific taskIds are provided, fetch tasks based on includeSubtasks if (includeSubtasks === 'none') { resultTasks = tasksToConsider.filter(task => task.parentId === null); } else if (includeSubtasks === 'first-level') { const topLevelTasks = tasksToConsider.filter(task => task.parentId === null); resultTasks.push(...topLevelTasks); for (const task of topLevelTasks) { const directChildren = tasksToConsider.filter(child => child.parentId === task.id); resultTasks.push(...directChildren); } } else if (includeSubtasks === 'recursive') { // For recursive and no specific taskIds, return all tasks (already filtered by deleted status) resultTasks = tasksToConsider; } } // Remove duplicates and sort const uniqueResultTasks = Array.from(new Set(resultTasks)); // Sort based on task ID structure uniqueResultTasks.sort((a, b) => { const aParts = a.id.split('.').map(Number); const bParts = b.id.split('.').map(Number); for (let i = 0; i < Math.min(aParts.length, bParts.length); i++) { if (aParts[i] !== bParts[i]) { return aParts[i] - bParts[i]; } } return aParts.length - bParts.length; }); const mapToTaskResponse = (task: LokiTask): TaskResponse => { const { createdAt, updatedAt, parentId: _, $loki, meta, ...taskResponse } = task as LokiTask; return taskResponse; }; return uniqueResultTasks.map(mapToTaskResponse); }

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/hrishirc/task-orchestrator'

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