Skip to content

Commit d0ffad1

Browse files
feat: Adds completed tasks tool (#8)
This adds a new tool that allows for fetching of completed tasks either by due date or by completion date. --------- Co-authored-by: Ernesto García <[email protected]>
1 parent 547130c commit d0ffad1

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { subtasksListForParentTask } from './tools/subtasks-list-for-parent-task
2626

2727
import { accountOverview } from './tools/account-overview'
2828
import { projectOverview } from './tools/project-overview'
29+
import { tasksListCompleted } from './tools/tasks-list-completed'
2930

3031
const tools = {
3132
projectsList,
@@ -42,6 +43,7 @@ const tools = {
4243
tasksCompleteMultiple,
4344
tasksListForProject,
4445
tasksListOverdue,
46+
tasksListCompleted,
4547
tasksSearch,
4648
tasksAddMultiple,
4749
tasksUpdateOne,

src/mcp-server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { tasksAddMultiple } from './tools/tasks-add-multiple'
2121
import { tasksCompleteMultiple } from './tools/tasks-complete-multiple'
2222
import { tasksDeleteOne } from './tools/tasks-delete-one'
2323
import { tasksListByDate } from './tools/tasks-list-by-date'
24+
import { tasksListCompleted } from './tools/tasks-list-completed'
2425
import { tasksListForProject } from './tools/tasks-list-for-project'
2526
import { tasksListForSection } from './tools/tasks-list-for-section'
2627
import { tasksListOverdue } from './tools/tasks-list-overdue'
@@ -51,6 +52,7 @@ function getMcpServer({ todoistApiKey, baseUrl }: { todoistApiKey: string; baseU
5152

5253
const todoist = new TodoistApi(todoistApiKey, baseUrl)
5354

55+
registerTool(tasksListCompleted, server, todoist)
5456
registerTool(tasksListByDate, server, todoist)
5557
registerTool(tasksListOverdue, server, todoist)
5658
registerTool(tasksListForProject, server, todoist)

src/tools/tasks-list-completed.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { z } from 'zod'
2+
import type { TodoistTool } from '../todoist-tool'
3+
import { mapTask } from './shared'
4+
5+
const ArgsSchema = {
6+
getBy: z
7+
.enum(['completion', 'due'])
8+
.default('completion')
9+
.describe(
10+
'The method to use to get the tasks: "completion" to get tasks by completion date (ie, when the task was actually completed), "due" to get tasks by due date (ie, when the task was due to be completed by).',
11+
),
12+
since: z
13+
.string()
14+
.date()
15+
.regex(/^\d{4}-\d{2}-\d{2}$/)
16+
.describe('The start date to get the tasks for. Format: YYYY-MM-DD.'),
17+
until: z
18+
.string()
19+
.date()
20+
.regex(/^\d{4}-\d{2}-\d{2}$/)
21+
.describe('The start date to get the tasks for. Format: YYYY-MM-DD.'),
22+
workspaceId: z.string().optional().describe('The ID of the workspace to get the tasks for.'),
23+
projectId: z.string().optional().describe('The ID of the project to get the tasks for.'),
24+
sectionId: z.string().optional().describe('The ID of the section to get the tasks for.'),
25+
parentId: z.string().optional().describe('The ID of the parent task to get the tasks for.'),
26+
limit: z
27+
.number()
28+
.int()
29+
.min(1)
30+
.max(200)
31+
.default(50)
32+
.describe('The maximum number of tasks to return. Default is 50, maximum is 200.'),
33+
cursor: z
34+
.string()
35+
.optional()
36+
.describe(
37+
'The cursor to get the next page of tasks (cursor is obtained from the previous call to this tool, with the same parameters).',
38+
),
39+
}
40+
41+
const tasksListCompleted = {
42+
name: 'tasks-list-completed',
43+
description: 'Get completed tasks.',
44+
parameters: ArgsSchema,
45+
async execute(args, client) {
46+
const { getBy, ...rest } = args
47+
const { items, nextCursor } =
48+
getBy === 'completion'
49+
? await client.getCompletedTasksByCompletionDate(rest)
50+
: await client.getCompletedTasksByDueDate(rest)
51+
return {
52+
tasks: items.map(mapTask),
53+
nextCursor,
54+
}
55+
},
56+
} satisfies TodoistTool<typeof ArgsSchema>
57+
58+
export { tasksListCompleted }

0 commit comments

Comments
 (0)