todoist_get_tasks
Retrieve tasks from Todoist with advanced filtering and pagination options, allowing users to fetch specific tasks by project, section, parent ID, label, or task IDs for precise task management.
Instructions
Get tasks with comprehensive filtering and pagination support
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cursor | No | Pagination cursor for next page (optional) | |
| ids | No | Array of task IDs to retrieve (optional) | |
| label | No | Filter tasks by label name (optional) | |
| limit | No | Maximum number of tasks to return (default: 50, max: 200) (optional) | |
| parentId | No | Filter tasks by parent ID (get subtasks) (optional) | |
| projectId | No | Filter tasks by project ID (optional) | |
| sectionId | No | Filter tasks by section ID (optional) |
Implementation Reference
- src/index.ts:1176-1211 (handler)Handler for todoist_get_tasks tool: validates arguments, constructs query parameters for Todoist API, fetches tasks handling both array and paginated responses, formats output using formatTask, and returns formatted task list with pagination info.if (name === "todoist_get_tasks") { if (!isGetTasksArgs(args)) { throw new Error("Invalid arguments for todoist_get_tasks"); } const params: any = {}; if (args.projectId) params.projectId = args.projectId; if (args.sectionId) params.sectionId = args.sectionId; if (args.parentId) params.parentId = args.parentId; if (args.label) params.label = args.label; if (args.ids && args.ids.length > 0) params.ids = args.ids; if (args.cursor) params.cursor = args.cursor; if (args.limit) params.limit = args.limit; const tasks = await todoistClient.getTasks(Object.keys(params).length > 0 ? params : {}); // Handle both array and paginated response formats let taskList: string; let nextCursor: string = ''; if (Array.isArray(tasks)) { taskList = tasks.map(formatTask).join('\n\n'); } else { const paginatedTasks = tasks as any; taskList = paginatedTasks.results?.map(formatTask).join('\n\n') || 'No tasks found'; nextCursor = paginatedTasks.nextCursor ? `\n\nNext cursor: ${paginatedTasks.nextCursor}` : ''; } return { content: [{ type: "text", text: `Tasks:\n${taskList}${nextCursor}` }], isError: false, }; }
- src/index.ts:91-129 (schema)Tool schema definition including name, description, and inputSchema with properties for filtering tasks by project, section, parent, label, specific IDs, pagination (cursor, limit).const GET_TASKS_TOOL: Tool = { name: "todoist_get_tasks", description: "Get tasks with comprehensive filtering and pagination support", inputSchema: { type: "object", properties: { projectId: { type: "string", description: "Filter tasks by project ID (optional)" }, sectionId: { type: "string", description: "Filter tasks by section ID (optional)" }, parentId: { type: "string", description: "Filter tasks by parent ID (get subtasks) (optional)" }, label: { type: "string", description: "Filter tasks by label name (optional)" }, ids: { type: "array", items: { type: "string" }, description: "Array of task IDs to retrieve (optional)" }, cursor: { type: "string", description: "Pagination cursor for next page (optional)" }, limit: { type: "number", description: "Maximum number of tasks to return (default: 50, max: 200) (optional)", default: 50 } } } };
- src/index.ts:1088-1088 (registration)Registration of the todoist_get_tasks tool (GET_TASKS_TOOL) in the array returned by ListToolsRequestSchema handler.GET_TASKS_TOOL,
- src/index.ts:776-786 (helper)Type guard function to validate arguments for todoist_get_tasks.function isGetTasksArgs(args: unknown): args is { projectId?: string; sectionId?: string; parentId?: string; label?: string; ids?: string[]; cursor?: string; limit?: number; } { return typeof args === "object" && args !== null; }
- src/index.ts:704-719 (helper)Helper function to format individual task details into a readable string used in the handler output.// Helper function to format task output function formatTask(task: any): string { let taskDetails = `- ID: ${task.id}\n Content: ${task.content}`; if (task.description) taskDetails += `\n Description: ${task.description}`; if (task.due) taskDetails += `\n Due: ${task.due.string}`; if (task.priority && task.priority > 1) taskDetails += `\n Priority: ${task.priority}`; if (task.labels && task.labels.length > 0) taskDetails += `\n Labels: ${task.labels.join(', ')}`; if (task.projectId) taskDetails += `\n Project ID: ${task.projectId}`; if (task.sectionId) taskDetails += `\n Section ID: ${task.sectionId}`; if (task.parentId) taskDetails += `\n Parent ID: ${task.parentId}`; if (task.url) taskDetails += `\n URL: ${task.url}`; if (task.commentCount > 0) taskDetails += `\n Comments: ${task.commentCount}`; if (task.createdAt) taskDetails += `\n Created At: ${task.createdAt}`; if (task.creatorId) taskDetails += `\n Creator ID: ${task.creatorId}`; return taskDetails; }