-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
executable file
·1031 lines (960 loc) · 28.2 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env node
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
ListToolsRequestSchema,
CallToolRequestSchema,
ListResourceTemplatesRequestSchema,
ListResourcesRequestSchema,
ReadResourceRequestSchema,
ResourceTemplate,
Tool,
ListPromptsRequestSchema,
GetPromptRequestSchema,
Prompt,
} from "@modelcontextprotocol/sdk/types.js";
import axios from "axios";
import { z } from "zod";
import dotenv from "dotenv";
import { readFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
dotenv.config();
const token = process.env.DART_TOKEN;
if (!token) {
console.error("DART_TOKEN environment variable is required");
process.exit(1);
}
const hostBase = process.env.DART_HOST || "https://app.itsdart.com";
const host = `${hostBase}/api/v0/public`;
const headers = {
Authorization: `Bearer ${token}`,
};
const filename = fileURLToPath(import.meta.url);
const packageJson = JSON.parse(
readFileSync(join(dirname(filename), "..", "package.json"), "utf-8"),
);
// Task schemas
const AssigneeSchema = z.object({
name: z.string(),
email: z.string(),
});
const TaskCreateSchema = z.object({
title: z.string(),
description: z.string().optional(),
dartboard: z.string().optional(),
status: z.string().optional(),
priority: z.string().nullable().optional(),
size: z.number().nullable().optional(),
startAt: z.string().nullable().optional(),
dueAt: z.string().nullable().optional(),
assignees: z.array(z.string()).optional(),
assignee: z.string().optional(),
tags: z.array(z.string()).optional(),
parent: z.string().nullable().optional(),
});
const TaskUpdateSchema = TaskCreateSchema.extend({
id: z.string(),
});
const TaskSchema = TaskUpdateSchema.extend({
permalink: z.string(),
dartboard: z.string(),
status: z.string(),
});
const WrappedTaskCreateSchema = z.object({
item: TaskCreateSchema,
});
const WrappedTaskUpdateSchema = z.object({
item: TaskUpdateSchema,
});
const WrappedTaskSchema = z.object({
item: TaskSchema,
});
const TaskIdSchema = z.object({
id: z
.string()
.regex(/^[a-zA-Z0-9]{12}$/, "Task ID must be 12 alphanumeric characters"),
});
// Doc schemas
const DocCreateSchema = z.object({
title: z.string(),
text: z.string().optional(),
folder: z.string().optional(),
});
const DocUpdateSchema = DocCreateSchema.extend({
id: z.string(),
});
const DocSchema = DocUpdateSchema.extend({
permalink: z.string(),
folder: z.string(),
});
const WrappedDocCreateSchema = z.object({
item: DocCreateSchema,
});
const WrappedDocUpdateSchema = z.object({
item: DocUpdateSchema,
});
const WrappedDocSchema = z.object({
item: DocSchema,
});
const DocIdSchema = z.object({
id: z
.string()
.regex(/^[a-zA-Z0-9]{12}$/, "Doc ID must be 12 alphanumeric characters"),
});
// Request schemas
const TaskListParamsSchema = z.object({
assignee: z.string().optional(),
assignee_duid: z.string().optional(),
dartboard: z.string().optional(),
dartboard_duid: z.string().optional(),
description: z.string().optional(),
due_at_before: z.string().optional(),
due_at_after: z.string().optional(),
duids: z.string().optional(),
in_trash: z.boolean().optional(),
is_draft: z.boolean().optional(),
kind: z.string().optional(),
limit: z.number().optional(),
offset: z.number().optional(),
priority: z.string().optional(),
size: z.number().optional(),
start_at_before: z.string().optional(),
start_at_after: z.string().optional(),
status: z.string().optional(),
status_duid: z.string().optional(),
subscriber_duid: z.string().optional(),
tag: z.string().optional(),
title: z.string().optional(),
});
type TaskListParams = z.infer<typeof TaskListParamsSchema>;
const DocListParamsSchema = z.object({
folder: z.string().optional(),
folder_duid: z.string().optional(),
duids: z.string().optional(),
in_trash: z.boolean().optional(),
is_draft: z.boolean().optional(),
limit: z.number().optional(),
offset: z.number().optional(),
s: z.string().optional(),
text: z.string().optional(),
title: z.string().optional(),
});
type DocListParams = z.infer<typeof DocListParamsSchema>;
// Response schemas
const ConfigResponseSchema = z.object({
today: z.string(),
assignees: z.array(AssigneeSchema),
dartboards: z.array(z.string()),
folders: z.array(z.string()),
statuses: z.array(z.string()),
tags: z.array(z.string()),
priorities: z.array(z.string()),
sizes: z.array(z.number()),
});
const PaginationResponseSchema = z.object({
count: z.number(),
next: z.string().nullable(),
previous: z.string().nullable(),
});
const TaskListResponseSchema = PaginationResponseSchema.extend({
results: z.array(TaskSchema),
});
const DocListResponseSchema = PaginationResponseSchema.extend({
results: z.array(DocSchema),
});
// Server resources
const createTaskPrompt: Prompt = {
name: "create-task",
description: "Create a new task in Dart",
arguments: [
{
name: "title",
description: "Title of the task",
required: true,
},
{
name: "description",
description: "Description of the task",
required: false,
},
{
name: "status",
description: "Status of the task",
required: false,
},
{
name: "priority",
description: "Priority of the task",
required: false,
},
{
name: "assignee",
description: "Email of the assignee",
required: false,
},
],
};
const createDocPrompt: Prompt = {
name: "create-doc",
description: "Create a new document in Dart",
arguments: [
{
name: "title",
description: "Title of the document",
required: true,
},
{
name: "text",
description: "Content of the document",
required: false,
},
{
name: "folder",
description: "Folder to place the document in",
required: false,
},
],
};
const summarizeTasksPrompt: Prompt = {
name: "summarize-tasks",
description: "Get a summary of tasks with optional filtering",
arguments: [
{
name: "status",
description: "Filter by status (e.g., 'In Progress', 'Done')",
required: false,
},
{
name: "assignee",
description: "Filter by assignee email",
required: false,
},
],
};
const configResourceTemplate: ResourceTemplate = {
uriTemplate: "dart-config:",
name: "Dart config",
description:
"Information about the authenticated user associated with the API key, including their role, teams, and settings.",
parameters: {},
examples: ["dart-config:"],
};
const taskResourceTemplate: ResourceTemplate = {
uriTemplate: "dart-task:///{taskId}",
name: "Dart task",
description:
"A Dart task with its title, description, status, priority, dates, and more. Use this to fetch detailed information about a specific task.",
parameters: {
taskId: {
type: "string",
description: "The unique identifier of the Dart task",
},
},
examples: ["dart-task:///9q5qtB8n2Qn6"],
};
const docResourceTemplate: ResourceTemplate = {
uriTemplate: "dart-doc:///{docId}",
name: "Dart doc",
description:
"A Dart doc with its title, text content, and folder. Use this to fetch detailed information about a specific doc.",
parameters: {
docId: {
type: "string",
description: "The unique identifier of the Dart doc",
},
},
examples: ["dart-doc:///9q5qtB8n2Qn6"],
};
const getConfigTool: Tool = {
name: "get_config",
description:
"Get information about the user's space, including all of the possible values that can be provided to other endpoints. This includes available assignees, dartboards, folders, statuses, tags, priorities, and sizes.",
inputSchema: {
type: "object",
properties: {},
required: [],
},
};
const listTasksTool: Tool = {
name: "list_tasks",
description:
"List tasks from Dart with optional filtering parameters. You can filter by assignee, status, dartboard, priority, due date, and more.",
inputSchema: {
type: "object",
properties: {
assignee: {
type: "string",
description: "Filter by assignee name or email",
},
assignee_duid: {
type: "string",
description: "Filter by assignee DUID",
},
dartboard: {
type: "string",
description: "Filter by dartboard title",
},
dartboard_duid: {
type: "string",
description: "Filter by dartboard DUID",
},
description: {
type: "string",
description: "Filter by description content",
},
due_at_before: {
type: "string",
description: "Filter by due date before (ISO format)",
},
due_at_after: {
type: "string",
description: "Filter by due date after (ISO format)",
},
duids: { type: "string", description: "Filter by DUIDs" },
in_trash: { type: "boolean", description: "Filter by trash status" },
is_draft: { type: "boolean", description: "Filter by draft status" },
kind: { type: "string", description: "Filter by task kind" },
limit: { type: "number", description: "Number of results per page" },
offset: {
type: "number",
description: "Initial index for pagination",
},
priority: { type: "string", description: "Filter by priority" },
size: { type: "number", description: "Filter by task size" },
start_at_before: {
type: "string",
description: "Filter by start date before (ISO format)",
},
start_at_after: {
type: "string",
description: "Filter by start date after (ISO format)",
},
status: { type: "string", description: "Filter by status" },
status_duid: { type: "string", description: "Filter by status DUID" },
subscriber_duid: {
type: "string",
description: "Filter by subscriber DUID",
},
tag: { type: "string", description: "Filter by tag" },
title: { type: "string", description: "Filter by title" },
},
required: [],
},
};
const createTaskTool: Tool = {
name: "create_task",
description:
"Create a new task in Dart. You can specify title, description, status, priority, size, dates, dartboard, assignees, tags, and parent task.",
inputSchema: {
type: "object",
properties: {
title: {
type: "string",
description: "The title of the task (required)",
},
description: {
type: "string",
description:
"A longer description of the task, which can include markdown formatting",
},
status: {
type: "string",
description: "The status from the list of available statuses",
},
priority: {
type: "string",
description: "The priority (Critical, High, Medium, or Low)",
},
size: {
type: "number",
description: "A number that represents the amount of work needed",
},
startAt: {
type: "string",
description:
"The start date in ISO format (should be at 9:00am in user's timezone)",
},
dueAt: {
type: "string",
description:
"The due date in ISO format (should be at 9:00am in user's timezone)",
},
dartboard: {
type: "string",
description: "The title of the dartboard (project or list of tasks)",
},
assignees: {
type: "array",
items: { type: "string" },
description:
"Array of assignee names or emails (if workspace allows multiple assignees)",
},
assignee: {
type: "string",
description:
"Single assignee name or email (if workspace doesn't allow multiple assignees)",
},
tags: {
type: "array",
items: { type: "string" },
description: "Array of tags to apply to the task",
},
parent: {
type: "string",
description: "The ID of the parent task",
},
},
required: ["title"],
},
};
const getTaskTool: Tool = {
name: "get_task",
description:
"Retrieve an existing task by its ID. Returns the task's information including title, description, status, priority, dates, and more.",
inputSchema: {
type: "object",
properties: {
id: {
type: "string",
description: "The 12-character alphanumeric ID of the task",
pattern: "^[a-zA-Z0-9]{12}$",
},
},
required: ["id"],
},
};
const updateTaskTool: Tool = {
name: "update_task",
description:
"Update an existing task. You can modify any of its properties including title, description, status, priority, dates, assignees, and more.",
inputSchema: {
type: "object",
properties: {
id: {
type: "string",
description: "The 12-character alphanumeric ID of the task",
pattern: "^[a-zA-Z0-9]{12}$",
},
title: {
type: "string",
description: "The title of the task",
},
description: {
type: "string",
description:
"A longer description of the task, which can include markdown formatting",
},
status: {
type: "string",
description: "The status from the list of available statuses",
},
priority: {
type: "string",
description: "The priority (Critical, High, Medium, or Low)",
},
size: {
type: "number",
description: "A number that represents the amount of work needed",
},
startAt: {
type: "string",
description:
"The start date in ISO format (should be at 9:00am in user's timezone)",
},
dueAt: {
type: "string",
description:
"The due date in ISO format (should be at 9:00am in user's timezone)",
},
dartboard: {
type: "string",
description: "The title of the dartboard (project or list of tasks)",
},
assignees: {
type: "array",
items: { type: "string" },
description:
"Array of assignee names or emails (if workspace allows multiple assignees)",
},
assignee: {
type: "string",
description:
"Single assignee name or email (if workspace doesn't allow multiple assignees)",
},
tags: {
type: "array",
items: { type: "string" },
description: "Array of tags to apply to the task",
},
parent: {
type: "string",
description: "The ID of the parent task",
},
},
required: ["id"],
},
};
const deleteTaskTool: Tool = {
name: "delete_task",
description:
"Move an existing task to the trash, where it can be recovered if needed. Nothing else about the task will be changed.",
inputSchema: {
type: "object",
properties: {
id: {
type: "string",
description: "The 12-character alphanumeric ID of the task",
pattern: "^[a-zA-Z0-9]{12}$",
},
},
required: ["id"],
},
};
const listDocsTool: Tool = {
name: "list_docs",
description:
"List docs from Dart with optional filtering parameters. You can filter by folder, title, text content, and more.",
inputSchema: {
type: "object",
properties: {
folder: {
type: "string",
description: "Filter by folder title",
},
folder_duid: {
type: "string",
description: "Filter by folder DUID",
},
duids: {
type: "string",
description: "Filter by DUIDs",
},
in_trash: {
type: "boolean",
description: "Filter by trash status",
},
is_draft: {
type: "boolean",
description: "Filter by draft status",
},
limit: {
type: "number",
description: "Number of results per page",
},
offset: {
type: "number",
description: "Initial index for pagination",
},
s: {
type: "string",
description: "Search by title, text, or folder title",
},
text: {
type: "string",
description: "Filter by text content",
},
title: {
type: "string",
description: "Filter by title",
},
},
required: [],
},
};
const createDocTool: Tool = {
name: "create_doc",
description:
"Create a new doc in Dart. You can specify title, text content, and folder.",
inputSchema: {
type: "object",
properties: {
title: {
type: "string",
description: "The title of the doc (required)",
},
text: {
type: "string",
description:
"The text content of the doc, which can include markdown formatting",
},
folder: {
type: "string",
description: "The title of the folder to place the doc in",
},
},
required: ["title"],
},
};
const getDocTool: Tool = {
name: "get_doc",
description:
"Retrieve an existing doc by its ID. Returns the doc's information including title, text content, folder, and more.",
inputSchema: {
type: "object",
properties: {
id: {
type: "string",
description: "The 12-character alphanumeric ID of the doc",
pattern: "^[a-zA-Z0-9]{12}$",
},
},
required: ["id"],
},
};
const updateDocTool: Tool = {
name: "update_doc",
description:
"Update an existing doc. You can modify its title, text content, and folder.",
inputSchema: {
type: "object",
properties: {
id: {
type: "string",
description: "The 12-character alphanumeric ID of the doc",
pattern: "^[a-zA-Z0-9]{12}$",
},
title: {
type: "string",
description: "The title of the doc",
},
text: {
type: "string",
description:
"The text content of the doc, which can include markdown formatting",
},
folder: {
type: "string",
description: "The title of the folder to place the doc in",
},
},
required: ["id"],
},
};
const deleteDocTool: Tool = {
name: "delete_doc",
description:
"Move an existing doc to the trash, where it can be recovered if needed. Nothing else about the doc will be changed.",
inputSchema: {
type: "object",
properties: {
id: {
type: "string",
description: "The 12-character alphanumeric ID of the doc",
pattern: "^[a-zA-Z0-9]{12}$",
},
},
required: ["id"],
},
};
// Client functions
const listTasks = async (params?: TaskListParams) => {
const response = await axios.get(`${host}/tasks/list`, { headers, params });
return TaskListResponseSchema.parse(response.data);
};
const listDocs = async (params?: DocListParams) => {
const response = await axios.get(`${host}/docs/list`, { headers, params });
return DocListResponseSchema.parse(response.data);
};
const getConfig = async () => {
const response = await axios.get(`${host}/config`, { headers });
return ConfigResponseSchema.parse(response.data);
};
const getTask = async (id: string) => {
const response = await axios.get(`${host}/tasks/${id}`, { headers });
return WrappedTaskSchema.parse(response.data);
};
const getDoc = async (id: string) => {
const response = await axios.get(`${host}/docs/${id}`, { headers });
return WrappedDocSchema.parse(response.data);
};
// Server
const server = new Server(
{
name: "dart-mcp",
version: packageJson.version,
},
{
capabilities: {
prompts: {},
resources: {},
tools: {},
},
},
);
server.setRequestHandler(ListPromptsRequestSchema, async () => ({
prompts: [createTaskPrompt, createDocPrompt, summarizeTasksPrompt],
}));
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
const promptName = request.params.name;
if (promptName === "create-task") {
const title = request.params.arguments?.title || "(no title)";
const description = request.params.arguments?.description || "";
const status = request.params.arguments?.status || "";
const priority = request.params.arguments?.priority || "";
const assignee = request.params.arguments?.assignee || "";
return {
description: "Create a new task in Dart",
messages: [
{
role: "user",
content: {
type: "text",
text: `Create a new task in Dart with the following details:
Title: ${title}
${description ? `Description: ${description}` : ""}
${status ? `Status: ${status}` : ""}
${priority ? `Priority: ${priority}` : ""}
${assignee ? `Assignee: ${assignee}` : ""}`,
},
},
],
};
}
if (promptName === "create-doc") {
const title = request.params.arguments?.title || "(no title)";
const text = request.params.arguments?.text || "";
const folder = request.params.arguments?.folder || "";
return {
description: "Create a new document in Dart",
messages: [
{
role: "user",
content: {
type: "text",
text: `Create a new document in Dart with the following details:
Title: ${title}
${text ? `Content: ${text}` : ""}
${folder ? `Folder: ${folder}` : ""}`,
},
},
],
};
}
if (promptName === "summarize-tasks") {
const status = request.params.arguments?.status || "";
const assignee = request.params.arguments?.assignee || "";
return {
description: "Get a summary of tasks with optional filtering",
messages: [
{
role: "user",
content: {
type: "text",
text: `Summarize the tasks in Dart${status ? ` with status "${status}"` : ""}${assignee ? ` assigned to ${assignee}` : ""}.
Please include the total count, group by status, and list any high priority items.`,
},
},
],
};
}
throw new Error(`Unknown prompt: ${promptName}`);
});
server.setRequestHandler(ListResourceTemplatesRequestSchema, async () => ({
resourceTemplates: [
configResourceTemplate,
taskResourceTemplate,
docResourceTemplate,
],
}));
server.setRequestHandler(ListResourcesRequestSchema, async () => {
const tasks = await listTasks();
const taskResources = tasks.results.map((task) => ({
uri: `dart-task:///${task.id}`,
name: task.title,
description: task.description,
}));
const docs = await listDocs();
const docResources = docs.results.map((doc) => ({
uri: `dart-doc:///${doc.id}`,
name: doc.title,
description: doc.text,
}));
return { resources: [...taskResources, ...docResources] };
});
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
const { uri } = request.params;
const url = new URL(uri);
const path = url.pathname.replace(/^\//, "");
const { protocol } = url;
if (protocol === "dart-config") {
const config = await getConfig();
return {
contents: [
{
uri,
mimeType: "application/json",
text: JSON.stringify(config, null, 2),
},
],
};
}
if (protocol === "dart-task:") {
const task = await getTask(path);
return {
contents: [
{
uri,
mimeType: "application/json",
text: JSON.stringify(task, null, 2),
},
],
};
}
if (protocol === "dart-doc:") {
const doc = await getDoc(path);
return {
contents: [
{
uri,
mimeType: "application/json",
text: JSON.stringify(doc, null, 2),
},
],
};
}
throw new Error(`Unknown resource: ${uri}`);
});
server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [
getConfigTool,
listTasksTool,
createTaskTool,
getTaskTool,
updateTaskTool,
deleteTaskTool,
listDocsTool,
createDocTool,
getDocTool,
updateDocTool,
deleteDocTool,
],
}));
server.setRequestHandler(CallToolRequestSchema, async (request) => {
try {
if (!request.params.arguments) {
throw new Error("Arguments are required");
}
switch (request.params.name) {
case "get_config": {
const config = await getConfig();
return {
content: [{ type: "text", text: JSON.stringify(config, null, 2) }],
};
}
case "list_tasks": {
const params = TaskListParamsSchema.parse(request.params.arguments);
const tasks = await listTasks(params);
return {
content: [{ type: "text", text: JSON.stringify(tasks, null, 2) }],
};
}
case "create_task": {
const taskData = TaskCreateSchema.parse(request.params.arguments);
const wrappedData = WrappedTaskCreateSchema.parse({ item: taskData });
const response = await axios.post(`${host}/tasks`, wrappedData, {
headers,
});
const task = WrappedTaskSchema.parse(response.data);
return {
content: [{ type: "text", text: JSON.stringify(task, null, 2) }],
};
}
case "get_task": {
const { id } = TaskIdSchema.parse(request.params.arguments);
const task = await getTask(id);
return {
content: [{ type: "text", text: JSON.stringify(task, null, 2) }],
};
}
case "update_task": {
const taskData = TaskIdSchema.merge(TaskUpdateSchema).parse(
request.params.arguments,
);
const { id } = taskData;
const wrappedData = WrappedTaskUpdateSchema.parse({ item: taskData });
const response = await axios.put(`${host}/tasks/${id}`, wrappedData, {
headers,
});
const task = WrappedTaskSchema.parse(response.data);
return {
content: [{ type: "text", text: JSON.stringify(task, null, 2) }],
};
}
case "delete_task": {
const { id } = TaskIdSchema.parse(request.params.arguments);
const response = await axios.delete(`${host}/tasks/${id}`, { headers });
const task = WrappedTaskSchema.parse(response.data);
return {
content: [{ type: "text", text: JSON.stringify(task, null, 2) }],
};
}
case "list_docs": {
const params = DocListParamsSchema.parse(request.params.arguments);
const docs = await listDocs(params);
return {
content: [{ type: "text", text: JSON.stringify(docs, null, 2) }],
};
}
case "create_doc": {
const docData = DocCreateSchema.parse(request.params.arguments);
const wrappedData = WrappedDocCreateSchema.parse({ item: docData });
const response = await axios.post(`${host}/docs`, wrappedData, {
headers,
});
const doc = WrappedDocSchema.parse(response.data);
return {
content: [{ type: "text", text: JSON.stringify(doc, null, 2) }],
};
}
case "get_doc": {
const { id } = DocIdSchema.parse(request.params.arguments);
const doc = await getDoc(id);
return {
content: [{ type: "text", text: JSON.stringify(doc, null, 2) }],
};
}
case "update_doc": {
const docData = DocIdSchema.merge(DocUpdateSchema).parse(
request.params.arguments,
);
const { id } = docData;
const wrappedData = WrappedDocUpdateSchema.parse({ item: docData });
const response = await axios.put(`${host}/docs/${id}`, wrappedData, {
headers,
});
const doc = WrappedDocSchema.parse(response.data);
return {
content: [{ type: "text", text: JSON.stringify(doc, null, 2) }],
};
}
case "delete_doc": {