@west10tech/notion-mcp 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +120 -0
  2. package/dist/clients/notion-client.d.ts +53 -0
  3. package/dist/clients/notion-client.d.ts.map +1 -0
  4. package/dist/clients/notion-client.js +2950 -0
  5. package/dist/clients/notion-client.js.map +1 -0
  6. package/dist/config.d.ts +21 -0
  7. package/dist/config.d.ts.map +1 -0
  8. package/dist/config.js +58 -0
  9. package/dist/config.js.map +1 -0
  10. package/dist/index.d.ts +3 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +163 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/services/log-batcher.d.ts +44 -0
  15. package/dist/services/log-batcher.d.ts.map +1 -0
  16. package/dist/services/log-batcher.js +81 -0
  17. package/dist/services/log-batcher.js.map +1 -0
  18. package/dist/services/log-shipper.d.ts +104 -0
  19. package/dist/services/log-shipper.d.ts.map +1 -0
  20. package/dist/services/log-shipper.js +384 -0
  21. package/dist/services/log-shipper.js.map +1 -0
  22. package/dist/services/logger.d.ts +92 -0
  23. package/dist/services/logger.d.ts.map +1 -0
  24. package/dist/services/logger.js +224 -0
  25. package/dist/services/logger.js.map +1 -0
  26. package/dist/services/progress-reporter.d.ts +64 -0
  27. package/dist/services/progress-reporter.d.ts.map +1 -0
  28. package/dist/services/progress-reporter.js +192 -0
  29. package/dist/services/progress-reporter.js.map +1 -0
  30. package/dist/services/request-tracker.d.ts +55 -0
  31. package/dist/services/request-tracker.d.ts.map +1 -0
  32. package/dist/services/request-tracker.js +184 -0
  33. package/dist/services/request-tracker.js.map +1 -0
  34. package/dist/tools/notion-tools.d.ts +21 -0
  35. package/dist/tools/notion-tools.d.ts.map +1 -0
  36. package/dist/tools/notion-tools.js +1146 -0
  37. package/dist/tools/notion-tools.js.map +1 -0
  38. package/dist/types.d.ts +25 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/types.js +2 -0
  41. package/dist/types.js.map +1 -0
  42. package/package.json +57 -0
@@ -0,0 +1,1146 @@
1
+ import { Logger } from '../services/logger.js';
2
+ export class NotionTools {
3
+ constructor(client) {
4
+ this.initialized = false;
5
+ this.client = client;
6
+ // Get logger from client if available, otherwise create fallback
7
+ this.logger = client.logger || new Logger({
8
+ logLevel: 'ERROR',
9
+ component: 'tools',
10
+ enableConsole: true,
11
+ enableShipping: false,
12
+ serverName: ''
13
+ });
14
+ }
15
+ async ensureInitialized() {
16
+ if (!this.initialized) {
17
+ // Log tools initialization now that client is ready
18
+ this.logger.info('TOOLS_INIT', 'Tools instance initialization started', {
19
+ integration: 'notion',
20
+ isOAuth: false
21
+ });
22
+ this.logger.info('CLIENT_INITIALIZATION', 'Starting client initialization', {
23
+ isOAuth: false
24
+ });
25
+ this.initialized = true;
26
+ this.logger.info('CLIENT_INITIALIZATION', 'Client initialization completed', {
27
+ initialized: this.initialized
28
+ });
29
+ }
30
+ }
31
+ getToolDefinitions() {
32
+ return [
33
+ {
34
+ name: 'notion_list_databases',
35
+ description: '⚠️ DEPRECATED: This endpoint is deprecated by Notion API. Use the search endpoint with database filter instead.',
36
+ inputSchema: {
37
+ type: 'object',
38
+ properties: {
39
+ start_cursor: {
40
+ type: 'string',
41
+ description: 'Pagination cursor'
42
+ },
43
+ page_size: {
44
+ type: 'number',
45
+ description: 'Number of results per page (max 100)'
46
+ }
47
+ },
48
+ required: []
49
+ }
50
+ },
51
+ {
52
+ name: 'notion_get_database',
53
+ description: 'Get database by ID',
54
+ inputSchema: {
55
+ type: 'object',
56
+ properties: {
57
+ database_id: {
58
+ type: 'string',
59
+ description: 'Database ID to fetch'
60
+ }
61
+ },
62
+ required: ['database_id']
63
+ }
64
+ },
65
+ {
66
+ name: 'notion_query_database',
67
+ description: 'Query database pages',
68
+ inputSchema: {
69
+ type: 'object',
70
+ properties: {
71
+ database_id: {
72
+ type: 'string',
73
+ description: 'Database ID to query'
74
+ },
75
+ filter: {
76
+ type: 'object',
77
+ description: 'Filter object to apply'
78
+ },
79
+ sorts: {
80
+ type: 'array',
81
+ description: 'Array of sort objects'
82
+ },
83
+ start_cursor: {
84
+ type: 'string',
85
+ description: 'Pagination cursor'
86
+ },
87
+ page_size: {
88
+ type: 'number',
89
+ description: 'Number of results per page (max 100)'
90
+ }
91
+ },
92
+ required: ['database_id']
93
+ }
94
+ },
95
+ {
96
+ name: 'notion_create_database',
97
+ description: 'Create a new database',
98
+ inputSchema: {
99
+ type: 'object',
100
+ properties: {
101
+ parent: {
102
+ type: 'object',
103
+ description: 'Parent page object'
104
+ },
105
+ title: {
106
+ type: 'array',
107
+ description: 'Array of rich text objects for title'
108
+ },
109
+ properties: {
110
+ type: 'object',
111
+ description: 'Database properties schema'
112
+ },
113
+ icon: {
114
+ type: 'object',
115
+ description: 'Database icon object'
116
+ },
117
+ cover: {
118
+ type: 'object',
119
+ description: 'Database cover object'
120
+ }
121
+ },
122
+ required: ['parent', 'title', 'properties']
123
+ }
124
+ },
125
+ {
126
+ name: 'notion_update_database',
127
+ description: 'Update database properties',
128
+ inputSchema: {
129
+ type: 'object',
130
+ properties: {
131
+ database_id: {
132
+ type: 'string',
133
+ description: 'Database ID to update'
134
+ },
135
+ title: {
136
+ type: 'array',
137
+ description: 'Array of rich text objects for title'
138
+ },
139
+ properties: {
140
+ type: 'object',
141
+ description: 'Database properties to update'
142
+ },
143
+ icon: {
144
+ type: 'object',
145
+ description: 'Database icon object'
146
+ },
147
+ cover: {
148
+ type: 'object',
149
+ description: 'Database cover object'
150
+ }
151
+ },
152
+ required: ['database_id']
153
+ }
154
+ },
155
+ {
156
+ name: 'notion_get_page',
157
+ description: 'Get page by ID',
158
+ inputSchema: {
159
+ type: 'object',
160
+ properties: {
161
+ page_id: {
162
+ type: 'string',
163
+ description: 'Page ID to fetch'
164
+ }
165
+ },
166
+ required: ['page_id']
167
+ }
168
+ },
169
+ {
170
+ name: 'notion_create_page',
171
+ description: 'Create a new page. Note: Creating pages directly in workspace root requires special permissions - use database or page parents instead.',
172
+ inputSchema: {
173
+ type: 'object',
174
+ properties: {
175
+ parent: {
176
+ type: 'object',
177
+ description: 'Parent object (database or page)'
178
+ },
179
+ properties: {
180
+ type: 'object',
181
+ description: 'Page properties (required for database pages)'
182
+ },
183
+ children: {
184
+ type: 'array',
185
+ description: 'Array of block objects for page content'
186
+ },
187
+ icon: {
188
+ type: 'object',
189
+ description: 'Page icon object'
190
+ },
191
+ cover: {
192
+ type: 'object',
193
+ description: 'Page cover object'
194
+ }
195
+ },
196
+ required: ['parent']
197
+ }
198
+ },
199
+ {
200
+ name: 'notion_update_page',
201
+ description: 'Update page properties',
202
+ inputSchema: {
203
+ type: 'object',
204
+ properties: {
205
+ page_id: {
206
+ type: 'string',
207
+ description: 'Page ID to update'
208
+ },
209
+ properties: {
210
+ type: 'object',
211
+ description: 'Page properties to update'
212
+ },
213
+ archived: {
214
+ type: 'boolean',
215
+ description: 'Archive or unarchive the page'
216
+ },
217
+ icon: {
218
+ type: 'object',
219
+ description: 'Page icon object'
220
+ },
221
+ cover: {
222
+ type: 'object',
223
+ description: 'Page cover object'
224
+ }
225
+ },
226
+ required: ['page_id']
227
+ }
228
+ },
229
+ {
230
+ name: 'notion_get_page_property',
231
+ description: 'Get page property by ID',
232
+ inputSchema: {
233
+ type: 'object',
234
+ properties: {
235
+ page_id: {
236
+ type: 'string',
237
+ description: 'Page ID containing the property'
238
+ },
239
+ property_id: {
240
+ type: 'string',
241
+ description: 'Property ID to fetch'
242
+ },
243
+ start_cursor: {
244
+ type: 'string',
245
+ description: 'Pagination cursor'
246
+ },
247
+ page_size: {
248
+ type: 'number',
249
+ description: 'Number of results per page (max 100)'
250
+ }
251
+ },
252
+ required: ['page_id', 'property_id']
253
+ }
254
+ },
255
+ {
256
+ name: 'notion_get_block_children',
257
+ description: 'Get block children',
258
+ inputSchema: {
259
+ type: 'object',
260
+ properties: {
261
+ block_id: {
262
+ type: 'string',
263
+ description: 'Block ID to get children for'
264
+ },
265
+ start_cursor: {
266
+ type: 'string',
267
+ description: 'Pagination cursor'
268
+ },
269
+ page_size: {
270
+ type: 'number',
271
+ description: 'Number of results per page (max 100)'
272
+ }
273
+ },
274
+ required: ['block_id']
275
+ }
276
+ },
277
+ {
278
+ name: 'notion_append_block_children',
279
+ description: 'Append blocks to a parent block',
280
+ inputSchema: {
281
+ type: 'object',
282
+ properties: {
283
+ block_id: {
284
+ type: 'string',
285
+ description: 'Parent block ID'
286
+ },
287
+ children: {
288
+ type: 'array',
289
+ description: 'Array of block objects to append'
290
+ }
291
+ },
292
+ required: ['block_id', 'children']
293
+ }
294
+ },
295
+ {
296
+ name: 'notion_get_block',
297
+ description: 'Get block by ID',
298
+ inputSchema: {
299
+ type: 'object',
300
+ properties: {
301
+ block_id: {
302
+ type: 'string',
303
+ description: 'Block ID to fetch'
304
+ }
305
+ },
306
+ required: ['block_id']
307
+ }
308
+ },
309
+ {
310
+ name: 'notion_update_block',
311
+ description: 'Update block content',
312
+ inputSchema: {
313
+ type: 'object',
314
+ properties: {
315
+ block_id: {
316
+ type: 'string',
317
+ description: 'Block ID to update'
318
+ },
319
+ paragraph: {
320
+ type: 'object',
321
+ description: 'Updated paragraph block content'
322
+ },
323
+ heading_1: {
324
+ type: 'object',
325
+ description: 'Updated heading 1 block content'
326
+ },
327
+ heading_2: {
328
+ type: 'object',
329
+ description: 'Updated heading 2 block content'
330
+ },
331
+ heading_3: {
332
+ type: 'object',
333
+ description: 'Updated heading 3 block content'
334
+ },
335
+ bulleted_list_item: {
336
+ type: 'object',
337
+ description: 'Updated bulleted list item content'
338
+ },
339
+ numbered_list_item: {
340
+ type: 'object',
341
+ description: 'Updated numbered list item content'
342
+ },
343
+ to_do: {
344
+ type: 'object',
345
+ description: 'Updated to-do block content'
346
+ },
347
+ toggle: {
348
+ type: 'object',
349
+ description: 'Updated toggle block content'
350
+ },
351
+ code: {
352
+ type: 'object',
353
+ description: 'Updated code block content'
354
+ },
355
+ embed: {
356
+ type: 'object',
357
+ description: 'Updated embed block content'
358
+ },
359
+ image: {
360
+ type: 'object',
361
+ description: 'Updated image block content'
362
+ },
363
+ video: {
364
+ type: 'object',
365
+ description: 'Updated video block content'
366
+ },
367
+ file: {
368
+ type: 'object',
369
+ description: 'Updated file block content'
370
+ },
371
+ pdf: {
372
+ type: 'object',
373
+ description: 'Updated PDF block content'
374
+ },
375
+ bookmark: {
376
+ type: 'object',
377
+ description: 'Updated bookmark block content'
378
+ },
379
+ callout: {
380
+ type: 'object',
381
+ description: 'Updated callout block content'
382
+ },
383
+ quote: {
384
+ type: 'object',
385
+ description: 'Updated quote block content'
386
+ },
387
+ equation: {
388
+ type: 'object',
389
+ description: 'Updated equation block content'
390
+ },
391
+ divider: {
392
+ type: 'object',
393
+ description: 'Updated divider block content'
394
+ },
395
+ table_of_contents: {
396
+ type: 'object',
397
+ description: 'Updated table of contents block content'
398
+ },
399
+ column: {
400
+ type: 'object',
401
+ description: 'Updated column block content'
402
+ },
403
+ column_list: {
404
+ type: 'object',
405
+ description: 'Updated column list block content'
406
+ },
407
+ link_preview: {
408
+ type: 'object',
409
+ description: 'Updated link preview block content'
410
+ },
411
+ synced_block: {
412
+ type: 'object',
413
+ description: 'Updated synced block content'
414
+ },
415
+ table: {
416
+ type: 'object',
417
+ description: 'Updated table block content'
418
+ },
419
+ table_row: {
420
+ type: 'object',
421
+ description: 'Updated table row block content'
422
+ },
423
+ archived: {
424
+ type: 'boolean',
425
+ description: 'Archive or unarchive the block'
426
+ }
427
+ },
428
+ required: ['block_id']
429
+ }
430
+ },
431
+ {
432
+ name: 'notion_delete_block',
433
+ description: 'Delete a block',
434
+ inputSchema: {
435
+ type: 'object',
436
+ properties: {
437
+ block_id: {
438
+ type: 'string',
439
+ description: 'Block ID to delete'
440
+ }
441
+ },
442
+ required: ['block_id']
443
+ }
444
+ },
445
+ {
446
+ name: 'notion_list_users',
447
+ description: 'List all users',
448
+ inputSchema: {
449
+ type: 'object',
450
+ properties: {
451
+ start_cursor: {
452
+ type: 'string',
453
+ description: 'Pagination cursor'
454
+ },
455
+ page_size: {
456
+ type: 'number',
457
+ description: 'Number of results per page (max 100)'
458
+ }
459
+ },
460
+ required: []
461
+ }
462
+ },
463
+ {
464
+ name: 'notion_get_user',
465
+ description: 'Get user by ID',
466
+ inputSchema: {
467
+ type: 'object',
468
+ properties: {
469
+ user_id: {
470
+ type: 'string',
471
+ description: 'User ID to fetch'
472
+ }
473
+ },
474
+ required: ['user_id']
475
+ }
476
+ },
477
+ {
478
+ name: 'notion_get_me',
479
+ description: 'Get current bot user',
480
+ inputSchema: {
481
+ type: 'object',
482
+ properties: {},
483
+ required: []
484
+ }
485
+ },
486
+ {
487
+ name: 'notion_search',
488
+ description: 'Search pages and databases',
489
+ inputSchema: {
490
+ type: 'object',
491
+ properties: {
492
+ query: {
493
+ type: 'string',
494
+ description: 'Search query string'
495
+ },
496
+ sort: {
497
+ type: 'object',
498
+ description: 'Sort configuration'
499
+ },
500
+ filter: {
501
+ type: 'object',
502
+ description: 'Filter configuration'
503
+ },
504
+ start_cursor: {
505
+ type: 'string',
506
+ description: 'Pagination cursor'
507
+ },
508
+ page_size: {
509
+ type: 'number',
510
+ description: 'Number of results per page (max 100)'
511
+ }
512
+ },
513
+ required: []
514
+ }
515
+ },
516
+ {
517
+ name: 'notion_create_comment',
518
+ description: 'Create a comment on a page or block',
519
+ inputSchema: {
520
+ type: 'object',
521
+ properties: {
522
+ parent: {
523
+ type: 'object',
524
+ description: 'Parent object (page or block)'
525
+ },
526
+ rich_text: {
527
+ type: 'array',
528
+ description: 'Array of rich text objects for comment content'
529
+ }
530
+ },
531
+ required: ['parent', 'rich_text']
532
+ }
533
+ },
534
+ {
535
+ name: 'notion_get_comments',
536
+ description: 'Get comments for a page or block',
537
+ inputSchema: {
538
+ type: 'object',
539
+ properties: {
540
+ block_id: {
541
+ type: 'string',
542
+ description: 'Block ID to get comments for'
543
+ },
544
+ start_cursor: {
545
+ type: 'string',
546
+ description: 'Pagination cursor'
547
+ },
548
+ page_size: {
549
+ type: 'number',
550
+ description: 'Number of results per page (max 100)'
551
+ }
552
+ },
553
+ required: ['block_id']
554
+ }
555
+ }
556
+ ];
557
+ }
558
+ canHandle(toolName) {
559
+ const supportedTools = [
560
+ 'notion_list_databases',
561
+ 'notion_get_database',
562
+ 'notion_query_database',
563
+ 'notion_create_database',
564
+ 'notion_update_database',
565
+ 'notion_get_page',
566
+ 'notion_create_page',
567
+ 'notion_update_page',
568
+ 'notion_get_page_property',
569
+ 'notion_get_block_children',
570
+ 'notion_append_block_children',
571
+ 'notion_get_block',
572
+ 'notion_update_block',
573
+ 'notion_delete_block',
574
+ 'notion_list_users',
575
+ 'notion_get_user',
576
+ 'notion_get_me',
577
+ 'notion_search',
578
+ 'notion_create_comment',
579
+ 'notion_get_comments'
580
+ ];
581
+ return supportedTools.includes(toolName);
582
+ }
583
+ async executeTool(name, args, context, progressReporter) {
584
+ const startTime = Date.now();
585
+ this.logger.logToolStart(name, args);
586
+ // Check for early cancellation
587
+ if (context?.abortController.signal.aborted) {
588
+ this.logger.info('TOOL_CANCELLED_EARLY', 'Tool execution cancelled before start', {
589
+ tool: name,
590
+ requestId: context.requestId
591
+ });
592
+ throw new Error('Request was cancelled');
593
+ }
594
+ await this.ensureInitialized();
595
+ // Validate tool is supported
596
+ if (!this.canHandle(name)) {
597
+ this.logger.error('TOOL_ERROR', 'Unknown tool requested', {
598
+ tool: name,
599
+ supportedTools: ['notion_list_databases', 'notion_get_database', 'notion_query_database', 'notion_create_database', 'notion_update_database', 'notion_get_page', 'notion_create_page', 'notion_update_page', 'notion_get_page_property', 'notion_get_block_children', 'notion_append_block_children', 'notion_get_block', 'notion_update_block', 'notion_delete_block', 'notion_list_users', 'notion_get_user', 'notion_get_me', 'notion_search', 'notion_create_comment', 'notion_get_comments']
600
+ });
601
+ throw new Error(`Unknown tool: ${name}`);
602
+ }
603
+ // Validate required parameters
604
+ this.logger.debug('PARAM_VALIDATION', 'Validating tool parameters', {
605
+ tool: name,
606
+ providedArgs: Object.keys(args || {})
607
+ });
608
+ try {
609
+ let result;
610
+ // Create request options with cancellation and progress support
611
+ const requestOptions = {
612
+ signal: context?.abortController.signal,
613
+ onProgress: context?.progressToken && progressReporter ?
614
+ progressReporter.createProgressCallback(context.progressToken) :
615
+ undefined
616
+ };
617
+ switch (name) {
618
+ case 'notion_list_databases':
619
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
620
+ tool: 'notion_list_databases',
621
+ clientMethod: 'listDatabases',
622
+ hasAbortSignal: !!requestOptions.signal,
623
+ hasProgressCallback: !!requestOptions.onProgress
624
+ });
625
+ // Report initial progress
626
+ if (context?.progressToken && progressReporter) {
627
+ await progressReporter.report(context.progressToken, {
628
+ progress: 0,
629
+ total: 100,
630
+ message: `Starting list_databases operation...`
631
+ });
632
+ }
633
+ result = await this.client.listDatabases(args, requestOptions);
634
+ // Report completion
635
+ if (context?.progressToken && progressReporter) {
636
+ await progressReporter.report(context.progressToken, {
637
+ progress: 100,
638
+ total: 100,
639
+ message: `Completed list_databases operation`
640
+ });
641
+ }
642
+ break;
643
+ case 'notion_get_database':
644
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
645
+ tool: 'notion_get_database',
646
+ clientMethod: 'getDatabase',
647
+ hasAbortSignal: !!requestOptions.signal,
648
+ hasProgressCallback: !!requestOptions.onProgress
649
+ });
650
+ // Report initial progress
651
+ if (context?.progressToken && progressReporter) {
652
+ await progressReporter.report(context.progressToken, {
653
+ progress: 0,
654
+ total: 100,
655
+ message: `Starting get_database operation...`
656
+ });
657
+ }
658
+ result = await this.client.getDatabase(args, requestOptions);
659
+ // Report completion
660
+ if (context?.progressToken && progressReporter) {
661
+ await progressReporter.report(context.progressToken, {
662
+ progress: 100,
663
+ total: 100,
664
+ message: `Completed get_database operation`
665
+ });
666
+ }
667
+ break;
668
+ case 'notion_query_database':
669
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
670
+ tool: 'notion_query_database',
671
+ clientMethod: 'queryDatabase',
672
+ hasAbortSignal: !!requestOptions.signal,
673
+ hasProgressCallback: !!requestOptions.onProgress
674
+ });
675
+ // Report initial progress
676
+ if (context?.progressToken && progressReporter) {
677
+ await progressReporter.report(context.progressToken, {
678
+ progress: 0,
679
+ total: 100,
680
+ message: `Starting query_database operation...`
681
+ });
682
+ }
683
+ result = await this.client.queryDatabase(args, requestOptions);
684
+ // Report completion
685
+ if (context?.progressToken && progressReporter) {
686
+ await progressReporter.report(context.progressToken, {
687
+ progress: 100,
688
+ total: 100,
689
+ message: `Completed query_database operation`
690
+ });
691
+ }
692
+ break;
693
+ case 'notion_create_database':
694
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
695
+ tool: 'notion_create_database',
696
+ clientMethod: 'createDatabase',
697
+ hasAbortSignal: !!requestOptions.signal,
698
+ hasProgressCallback: !!requestOptions.onProgress
699
+ });
700
+ // Report initial progress
701
+ if (context?.progressToken && progressReporter) {
702
+ await progressReporter.report(context.progressToken, {
703
+ progress: 0,
704
+ total: 100,
705
+ message: `Starting create_database operation...`
706
+ });
707
+ }
708
+ result = await this.client.createDatabase(args, requestOptions);
709
+ // Report completion
710
+ if (context?.progressToken && progressReporter) {
711
+ await progressReporter.report(context.progressToken, {
712
+ progress: 100,
713
+ total: 100,
714
+ message: `Completed create_database operation`
715
+ });
716
+ }
717
+ break;
718
+ case 'notion_update_database':
719
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
720
+ tool: 'notion_update_database',
721
+ clientMethod: 'updateDatabase',
722
+ hasAbortSignal: !!requestOptions.signal,
723
+ hasProgressCallback: !!requestOptions.onProgress
724
+ });
725
+ // Report initial progress
726
+ if (context?.progressToken && progressReporter) {
727
+ await progressReporter.report(context.progressToken, {
728
+ progress: 0,
729
+ total: 100,
730
+ message: `Starting update_database operation...`
731
+ });
732
+ }
733
+ result = await this.client.updateDatabase(args, requestOptions);
734
+ // Report completion
735
+ if (context?.progressToken && progressReporter) {
736
+ await progressReporter.report(context.progressToken, {
737
+ progress: 100,
738
+ total: 100,
739
+ message: `Completed update_database operation`
740
+ });
741
+ }
742
+ break;
743
+ case 'notion_get_page':
744
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
745
+ tool: 'notion_get_page',
746
+ clientMethod: 'getPage',
747
+ hasAbortSignal: !!requestOptions.signal,
748
+ hasProgressCallback: !!requestOptions.onProgress
749
+ });
750
+ // Report initial progress
751
+ if (context?.progressToken && progressReporter) {
752
+ await progressReporter.report(context.progressToken, {
753
+ progress: 0,
754
+ total: 100,
755
+ message: `Starting get_page operation...`
756
+ });
757
+ }
758
+ result = await this.client.getPage(args, requestOptions);
759
+ // Report completion
760
+ if (context?.progressToken && progressReporter) {
761
+ await progressReporter.report(context.progressToken, {
762
+ progress: 100,
763
+ total: 100,
764
+ message: `Completed get_page operation`
765
+ });
766
+ }
767
+ break;
768
+ case 'notion_create_page':
769
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
770
+ tool: 'notion_create_page',
771
+ clientMethod: 'createPage',
772
+ hasAbortSignal: !!requestOptions.signal,
773
+ hasProgressCallback: !!requestOptions.onProgress
774
+ });
775
+ // Report initial progress
776
+ if (context?.progressToken && progressReporter) {
777
+ await progressReporter.report(context.progressToken, {
778
+ progress: 0,
779
+ total: 100,
780
+ message: `Starting create_page operation...`
781
+ });
782
+ }
783
+ result = await this.client.createPage(args, requestOptions);
784
+ // Report completion
785
+ if (context?.progressToken && progressReporter) {
786
+ await progressReporter.report(context.progressToken, {
787
+ progress: 100,
788
+ total: 100,
789
+ message: `Completed create_page operation`
790
+ });
791
+ }
792
+ break;
793
+ case 'notion_update_page':
794
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
795
+ tool: 'notion_update_page',
796
+ clientMethod: 'updatePage',
797
+ hasAbortSignal: !!requestOptions.signal,
798
+ hasProgressCallback: !!requestOptions.onProgress
799
+ });
800
+ // Report initial progress
801
+ if (context?.progressToken && progressReporter) {
802
+ await progressReporter.report(context.progressToken, {
803
+ progress: 0,
804
+ total: 100,
805
+ message: `Starting update_page operation...`
806
+ });
807
+ }
808
+ result = await this.client.updatePage(args, requestOptions);
809
+ // Report completion
810
+ if (context?.progressToken && progressReporter) {
811
+ await progressReporter.report(context.progressToken, {
812
+ progress: 100,
813
+ total: 100,
814
+ message: `Completed update_page operation`
815
+ });
816
+ }
817
+ break;
818
+ case 'notion_get_page_property':
819
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
820
+ tool: 'notion_get_page_property',
821
+ clientMethod: 'getPageProperty',
822
+ hasAbortSignal: !!requestOptions.signal,
823
+ hasProgressCallback: !!requestOptions.onProgress
824
+ });
825
+ // Report initial progress
826
+ if (context?.progressToken && progressReporter) {
827
+ await progressReporter.report(context.progressToken, {
828
+ progress: 0,
829
+ total: 100,
830
+ message: `Starting get_page_property operation...`
831
+ });
832
+ }
833
+ result = await this.client.getPageProperty(args, requestOptions);
834
+ // Report completion
835
+ if (context?.progressToken && progressReporter) {
836
+ await progressReporter.report(context.progressToken, {
837
+ progress: 100,
838
+ total: 100,
839
+ message: `Completed get_page_property operation`
840
+ });
841
+ }
842
+ break;
843
+ case 'notion_get_block_children':
844
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
845
+ tool: 'notion_get_block_children',
846
+ clientMethod: 'getBlockChildren',
847
+ hasAbortSignal: !!requestOptions.signal,
848
+ hasProgressCallback: !!requestOptions.onProgress
849
+ });
850
+ // Report initial progress
851
+ if (context?.progressToken && progressReporter) {
852
+ await progressReporter.report(context.progressToken, {
853
+ progress: 0,
854
+ total: 100,
855
+ message: `Starting get_block_children operation...`
856
+ });
857
+ }
858
+ result = await this.client.getBlockChildren(args, requestOptions);
859
+ // Report completion
860
+ if (context?.progressToken && progressReporter) {
861
+ await progressReporter.report(context.progressToken, {
862
+ progress: 100,
863
+ total: 100,
864
+ message: `Completed get_block_children operation`
865
+ });
866
+ }
867
+ break;
868
+ case 'notion_append_block_children':
869
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
870
+ tool: 'notion_append_block_children',
871
+ clientMethod: 'appendBlockChildren',
872
+ hasAbortSignal: !!requestOptions.signal,
873
+ hasProgressCallback: !!requestOptions.onProgress
874
+ });
875
+ // Report initial progress
876
+ if (context?.progressToken && progressReporter) {
877
+ await progressReporter.report(context.progressToken, {
878
+ progress: 0,
879
+ total: 100,
880
+ message: `Starting append_block_children operation...`
881
+ });
882
+ }
883
+ result = await this.client.appendBlockChildren(args, requestOptions);
884
+ // Report completion
885
+ if (context?.progressToken && progressReporter) {
886
+ await progressReporter.report(context.progressToken, {
887
+ progress: 100,
888
+ total: 100,
889
+ message: `Completed append_block_children operation`
890
+ });
891
+ }
892
+ break;
893
+ case 'notion_get_block':
894
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
895
+ tool: 'notion_get_block',
896
+ clientMethod: 'getBlock',
897
+ hasAbortSignal: !!requestOptions.signal,
898
+ hasProgressCallback: !!requestOptions.onProgress
899
+ });
900
+ // Report initial progress
901
+ if (context?.progressToken && progressReporter) {
902
+ await progressReporter.report(context.progressToken, {
903
+ progress: 0,
904
+ total: 100,
905
+ message: `Starting get_block operation...`
906
+ });
907
+ }
908
+ result = await this.client.getBlock(args, requestOptions);
909
+ // Report completion
910
+ if (context?.progressToken && progressReporter) {
911
+ await progressReporter.report(context.progressToken, {
912
+ progress: 100,
913
+ total: 100,
914
+ message: `Completed get_block operation`
915
+ });
916
+ }
917
+ break;
918
+ case 'notion_update_block':
919
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
920
+ tool: 'notion_update_block',
921
+ clientMethod: 'updateBlock',
922
+ hasAbortSignal: !!requestOptions.signal,
923
+ hasProgressCallback: !!requestOptions.onProgress
924
+ });
925
+ // Report initial progress
926
+ if (context?.progressToken && progressReporter) {
927
+ await progressReporter.report(context.progressToken, {
928
+ progress: 0,
929
+ total: 100,
930
+ message: `Starting update_block operation...`
931
+ });
932
+ }
933
+ result = await this.client.updateBlock(args, requestOptions);
934
+ // Report completion
935
+ if (context?.progressToken && progressReporter) {
936
+ await progressReporter.report(context.progressToken, {
937
+ progress: 100,
938
+ total: 100,
939
+ message: `Completed update_block operation`
940
+ });
941
+ }
942
+ break;
943
+ case 'notion_delete_block':
944
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
945
+ tool: 'notion_delete_block',
946
+ clientMethod: 'deleteBlock',
947
+ hasAbortSignal: !!requestOptions.signal,
948
+ hasProgressCallback: !!requestOptions.onProgress
949
+ });
950
+ // Report initial progress
951
+ if (context?.progressToken && progressReporter) {
952
+ await progressReporter.report(context.progressToken, {
953
+ progress: 0,
954
+ total: 100,
955
+ message: `Starting delete_block operation...`
956
+ });
957
+ }
958
+ result = await this.client.deleteBlock(args, requestOptions);
959
+ // Report completion
960
+ if (context?.progressToken && progressReporter) {
961
+ await progressReporter.report(context.progressToken, {
962
+ progress: 100,
963
+ total: 100,
964
+ message: `Completed delete_block operation`
965
+ });
966
+ }
967
+ break;
968
+ case 'notion_list_users':
969
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
970
+ tool: 'notion_list_users',
971
+ clientMethod: 'listUsers',
972
+ hasAbortSignal: !!requestOptions.signal,
973
+ hasProgressCallback: !!requestOptions.onProgress
974
+ });
975
+ // Report initial progress
976
+ if (context?.progressToken && progressReporter) {
977
+ await progressReporter.report(context.progressToken, {
978
+ progress: 0,
979
+ total: 100,
980
+ message: `Starting list_users operation...`
981
+ });
982
+ }
983
+ result = await this.client.listUsers(args, requestOptions);
984
+ // Report completion
985
+ if (context?.progressToken && progressReporter) {
986
+ await progressReporter.report(context.progressToken, {
987
+ progress: 100,
988
+ total: 100,
989
+ message: `Completed list_users operation`
990
+ });
991
+ }
992
+ break;
993
+ case 'notion_get_user':
994
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
995
+ tool: 'notion_get_user',
996
+ clientMethod: 'getUser',
997
+ hasAbortSignal: !!requestOptions.signal,
998
+ hasProgressCallback: !!requestOptions.onProgress
999
+ });
1000
+ // Report initial progress
1001
+ if (context?.progressToken && progressReporter) {
1002
+ await progressReporter.report(context.progressToken, {
1003
+ progress: 0,
1004
+ total: 100,
1005
+ message: `Starting get_user operation...`
1006
+ });
1007
+ }
1008
+ result = await this.client.getUser(args, requestOptions);
1009
+ // Report completion
1010
+ if (context?.progressToken && progressReporter) {
1011
+ await progressReporter.report(context.progressToken, {
1012
+ progress: 100,
1013
+ total: 100,
1014
+ message: `Completed get_user operation`
1015
+ });
1016
+ }
1017
+ break;
1018
+ case 'notion_get_me':
1019
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
1020
+ tool: 'notion_get_me',
1021
+ clientMethod: 'getMe',
1022
+ hasAbortSignal: !!requestOptions.signal,
1023
+ hasProgressCallback: !!requestOptions.onProgress
1024
+ });
1025
+ // Report initial progress
1026
+ if (context?.progressToken && progressReporter) {
1027
+ await progressReporter.report(context.progressToken, {
1028
+ progress: 0,
1029
+ total: 100,
1030
+ message: `Starting get_me operation...`
1031
+ });
1032
+ }
1033
+ result = await this.client.getMe(args, requestOptions);
1034
+ // Report completion
1035
+ if (context?.progressToken && progressReporter) {
1036
+ await progressReporter.report(context.progressToken, {
1037
+ progress: 100,
1038
+ total: 100,
1039
+ message: `Completed get_me operation`
1040
+ });
1041
+ }
1042
+ break;
1043
+ case 'notion_search':
1044
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
1045
+ tool: 'notion_search',
1046
+ clientMethod: 'search',
1047
+ hasAbortSignal: !!requestOptions.signal,
1048
+ hasProgressCallback: !!requestOptions.onProgress
1049
+ });
1050
+ // Report initial progress
1051
+ if (context?.progressToken && progressReporter) {
1052
+ await progressReporter.report(context.progressToken, {
1053
+ progress: 0,
1054
+ total: 100,
1055
+ message: `Starting search operation...`
1056
+ });
1057
+ }
1058
+ result = await this.client.search(args, requestOptions);
1059
+ // Report completion
1060
+ if (context?.progressToken && progressReporter) {
1061
+ await progressReporter.report(context.progressToken, {
1062
+ progress: 100,
1063
+ total: 100,
1064
+ message: `Completed search operation`
1065
+ });
1066
+ }
1067
+ break;
1068
+ case 'notion_create_comment':
1069
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
1070
+ tool: 'notion_create_comment',
1071
+ clientMethod: 'createComment',
1072
+ hasAbortSignal: !!requestOptions.signal,
1073
+ hasProgressCallback: !!requestOptions.onProgress
1074
+ });
1075
+ // Report initial progress
1076
+ if (context?.progressToken && progressReporter) {
1077
+ await progressReporter.report(context.progressToken, {
1078
+ progress: 0,
1079
+ total: 100,
1080
+ message: `Starting create_comment operation...`
1081
+ });
1082
+ }
1083
+ result = await this.client.createComment(args, requestOptions);
1084
+ // Report completion
1085
+ if (context?.progressToken && progressReporter) {
1086
+ await progressReporter.report(context.progressToken, {
1087
+ progress: 100,
1088
+ total: 100,
1089
+ message: `Completed create_comment operation`
1090
+ });
1091
+ }
1092
+ break;
1093
+ case 'notion_get_comments':
1094
+ this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
1095
+ tool: 'notion_get_comments',
1096
+ clientMethod: 'getComments',
1097
+ hasAbortSignal: !!requestOptions.signal,
1098
+ hasProgressCallback: !!requestOptions.onProgress
1099
+ });
1100
+ // Report initial progress
1101
+ if (context?.progressToken && progressReporter) {
1102
+ await progressReporter.report(context.progressToken, {
1103
+ progress: 0,
1104
+ total: 100,
1105
+ message: `Starting get_comments operation...`
1106
+ });
1107
+ }
1108
+ result = await this.client.getComments(args, requestOptions);
1109
+ // Report completion
1110
+ if (context?.progressToken && progressReporter) {
1111
+ await progressReporter.report(context.progressToken, {
1112
+ progress: 100,
1113
+ total: 100,
1114
+ message: `Completed get_comments operation`
1115
+ });
1116
+ }
1117
+ break;
1118
+ default:
1119
+ throw new Error(`Unknown tool: ${name}`);
1120
+ }
1121
+ const duration = Date.now() - startTime;
1122
+ this.logger.logToolSuccess(name, duration, result);
1123
+ // Return raw result for non-OAuth templates
1124
+ return result;
1125
+ }
1126
+ catch (error) {
1127
+ const duration = Date.now() - startTime;
1128
+ const errorMessage = error instanceof Error ? error.message : String(error);
1129
+ // Check if error is due to cancellation
1130
+ const isCancelled = context?.abortController.signal.aborted ||
1131
+ (error instanceof Error && error.message === 'Request was cancelled');
1132
+ if (isCancelled) {
1133
+ this.logger.info('TOOL_CANCELLED', 'Tool execution cancelled', {
1134
+ tool: name,
1135
+ duration_ms: duration,
1136
+ requestId: context?.requestId
1137
+ });
1138
+ }
1139
+ else {
1140
+ this.logger.logToolError(name, error, duration, args);
1141
+ }
1142
+ throw error;
1143
+ }
1144
+ }
1145
+ }
1146
+ //# sourceMappingURL=notion-tools.js.map