@mcp-monorepo/notion-query 1.2.0 → 1.3.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.
- package/dist/index.js +53 -6
- package/dist/index.js.map +1 -1
- package/dist/lib/config.d.ts +44 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +49 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/notion-syncer.d.ts +27 -0
- package/dist/lib/notion-syncer.d.ts.map +1 -0
- package/dist/lib/notion-syncer.js +212 -0
- package/dist/lib/notion-syncer.js.map +1 -0
- package/dist/lib/property-parser.d.ts +8 -10
- package/dist/lib/property-parser.d.ts.map +1 -1
- package/dist/lib/property-parser.js +102 -15
- package/dist/lib/property-parser.js.map +1 -1
- package/dist/lib/sync-state-manager.d.ts +29 -0
- package/dist/lib/sync-state-manager.d.ts.map +1 -0
- package/dist/lib/sync-state-manager.js +45 -0
- package/dist/lib/sync-state-manager.js.map +1 -0
- package/dist/local-rag/DEMO.d.ts +22 -0
- package/dist/local-rag/DEMO.d.ts.map +1 -0
- package/dist/local-rag/DEMO.js +142 -0
- package/dist/local-rag/DEMO.js.map +1 -0
- package/dist/local-rag/chunker.d.ts +24 -0
- package/dist/local-rag/chunker.d.ts.map +1 -0
- package/dist/local-rag/chunker.js +58 -0
- package/dist/local-rag/chunker.js.map +1 -0
- package/dist/local-rag/embedder.d.ts +43 -0
- package/dist/local-rag/embedder.d.ts.map +1 -0
- package/dist/local-rag/embedder.js +74 -0
- package/dist/local-rag/embedder.js.map +1 -0
- package/dist/local-rag/embedder.service.d.ts +15 -0
- package/dist/local-rag/embedder.service.d.ts.map +1 -0
- package/dist/local-rag/embedder.service.js +84 -0
- package/dist/local-rag/embedder.service.js.map +1 -0
- package/dist/local-rag/embedder.worker.d.ts +2 -0
- package/dist/local-rag/embedder.worker.d.ts.map +1 -0
- package/dist/local-rag/embedder.worker.js +34 -0
- package/dist/local-rag/embedder.worker.js.map +1 -0
- package/dist/local-rag/errors.d.ts +31 -0
- package/dist/local-rag/errors.d.ts.map +1 -0
- package/dist/local-rag/errors.js +47 -0
- package/dist/local-rag/errors.js.map +1 -0
- package/dist/local-rag/html-parser.d.ts +2 -0
- package/dist/local-rag/html-parser.d.ts.map +1 -0
- package/dist/local-rag/html-parser.js +32 -0
- package/dist/local-rag/html-parser.js.map +1 -0
- package/dist/local-rag/index.d.ts +67 -0
- package/dist/local-rag/index.d.ts.map +1 -0
- package/dist/local-rag/index.js +410 -0
- package/dist/local-rag/index.js.map +1 -0
- package/dist/local-rag/parser.d.ts +59 -0
- package/dist/local-rag/parser.d.ts.map +1 -0
- package/dist/local-rag/parser.js +206 -0
- package/dist/local-rag/parser.js.map +1 -0
- package/dist/local-rag/types.d.ts +209 -0
- package/dist/local-rag/types.d.ts.map +1 -0
- package/dist/local-rag/types.js +5 -0
- package/dist/local-rag/types.js.map +1 -0
- package/dist/local-rag/utils/pool.d.ts +60 -0
- package/dist/local-rag/utils/pool.d.ts.map +1 -0
- package/dist/local-rag/utils/pool.js +140 -0
- package/dist/local-rag/utils/pool.js.map +1 -0
- package/dist/local-rag/utils/typed-emitter.d.ts +28 -0
- package/dist/local-rag/utils/typed-emitter.d.ts.map +1 -0
- package/dist/local-rag/utils/typed-emitter.js +44 -0
- package/dist/local-rag/utils/typed-emitter.js.map +1 -0
- package/dist/local-rag/vectordb/index.d.ts +91 -0
- package/dist/local-rag/vectordb/index.d.ts.map +1 -0
- package/dist/local-rag/vectordb/index.js +278 -0
- package/dist/local-rag/vectordb/index.js.map +1 -0
- package/dist/local-rag/vectordb/manager.d.ts +28 -0
- package/dist/local-rag/vectordb/manager.d.ts.map +1 -0
- package/dist/local-rag/vectordb/manager.js +91 -0
- package/dist/local-rag/vectordb/manager.js.map +1 -0
- package/dist/local-rag/vectordb/migration.d.ts +27 -0
- package/dist/local-rag/vectordb/migration.d.ts.map +1 -0
- package/dist/local-rag/vectordb/migration.js +121 -0
- package/dist/local-rag/vectordb/migration.js.map +1 -0
- package/dist/local-rag/vectordb/retriever.d.ts +51 -0
- package/dist/local-rag/vectordb/retriever.d.ts.map +1 -0
- package/dist/local-rag/vectordb/retriever.js +157 -0
- package/dist/local-rag/vectordb/retriever.js.map +1 -0
- package/dist/local-rag/vectordb/schema.d.ts +33 -0
- package/dist/local-rag/vectordb/schema.d.ts.map +1 -0
- package/dist/local-rag/vectordb/schema.js +102 -0
- package/dist/local-rag/vectordb/schema.js.map +1 -0
- package/dist/local-rag/watcher.d.ts +48 -0
- package/dist/local-rag/watcher.d.ts.map +1 -0
- package/dist/local-rag/watcher.js +102 -0
- package/dist/local-rag/watcher.js.map +1 -0
- package/dist/tools/create-pages.d.ts +2 -1
- package/dist/tools/create-pages.d.ts.map +1 -1
- package/dist/tools/create-pages.js +3 -2
- package/dist/tools/create-pages.js.map +1 -1
- package/dist/tools/fetch.d.ts +2 -1
- package/dist/tools/fetch.d.ts.map +1 -1
- package/dist/tools/fetch.js +2 -1
- package/dist/tools/fetch.js.map +1 -1
- package/dist/tools/query-datasource.d.ts +2 -1
- package/dist/tools/query-datasource.d.ts.map +1 -1
- package/dist/tools/query-datasource.js +3 -3
- package/dist/tools/query-datasource.js.map +1 -1
- package/dist/tools/search.d.ts +12 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +75 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/update-page.d.ts +4 -0
- package/dist/tools/update-page.d.ts.map +1 -0
- package/dist/tools/update-page.js +135 -0
- package/dist/tools/update-page.js.map +1 -0
- package/package.json +15 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { TypedEventEmitter } from './utils/typed-emitter.js';
|
|
2
|
+
/**
|
|
3
|
+
* Defines the events that the DirectoryWatcher can emit.
|
|
4
|
+
* The key is the event name, and the value is an array of argument types for the listener.
|
|
5
|
+
*/
|
|
6
|
+
type WatcherEvents = {
|
|
7
|
+
'file-added': [filePath: string];
|
|
8
|
+
'file-changed': [filePath: string];
|
|
9
|
+
'file-deleted': [filePath: string];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A robust file system watcher that abstracts away the complexities of chokidar.
|
|
13
|
+
* It debounces change events and only reports on supported file types, emitting clean,
|
|
14
|
+
* actionable events. It handles both initial discovery of existing files and
|
|
15
|
+
* subsequent changes.
|
|
16
|
+
*/
|
|
17
|
+
export declare class DirectoryWatcher extends TypedEventEmitter<WatcherEvents> {
|
|
18
|
+
private readonly watcher;
|
|
19
|
+
private readonly debounceTimers;
|
|
20
|
+
private readonly debounceMs;
|
|
21
|
+
private readonly supportedExtensions;
|
|
22
|
+
constructor(debounceMs: number, supportedExtensions: string[]);
|
|
23
|
+
private setupListeners;
|
|
24
|
+
private isSupported;
|
|
25
|
+
private handleFileEvent;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a given path is already being watched by chokidar.
|
|
28
|
+
* @param path The absolute path to check.
|
|
29
|
+
* @returns True if the path is being watched, false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
isWatching(path: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Starts watching a given path (file or directory).
|
|
34
|
+
* @param path - The path to watch.
|
|
35
|
+
*/
|
|
36
|
+
watch(path: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* Stops watching a given path.
|
|
39
|
+
* @param path - The path to unwatch.
|
|
40
|
+
*/
|
|
41
|
+
unwatch(path: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Gracefully shuts down the watcher, releasing all file system handles.
|
|
44
|
+
*/
|
|
45
|
+
close(): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=watcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../src/local-rag/watcher.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAE5D;;;GAGG;AACH,KAAK,aAAa,GAAG;IACnB,YAAY,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IAChC,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IAClC,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;CACnC,CAAA;AAED;;;;;GAKG;AACH,qBAAa,gBAAiB,SAAQ,iBAAiB,CAAC,aAAa,CAAC;IACpE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAW;IACnC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAoC;IACnE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IACnC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAa;gBAErC,UAAU,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE;IAc7D,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,eAAe;IA4BvB;;;;OAIG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAQxC;;;OAGG;IACI,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQhC;;;OAGG;IACI,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIlC;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAOpC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { basename, dirname, extname } from 'node:path';
|
|
2
|
+
import { logger } from '@mcp-monorepo/shared';
|
|
3
|
+
import { FSWatcher } from 'chokidar';
|
|
4
|
+
import { TypedEventEmitter } from './utils/typed-emitter.js';
|
|
5
|
+
/**
|
|
6
|
+
* A robust file system watcher that abstracts away the complexities of chokidar.
|
|
7
|
+
* It debounces change events and only reports on supported file types, emitting clean,
|
|
8
|
+
* actionable events. It handles both initial discovery of existing files and
|
|
9
|
+
* subsequent changes.
|
|
10
|
+
*/
|
|
11
|
+
export class DirectoryWatcher extends TypedEventEmitter {
|
|
12
|
+
watcher;
|
|
13
|
+
debounceTimers = new Map();
|
|
14
|
+
debounceMs;
|
|
15
|
+
supportedExtensions;
|
|
16
|
+
constructor(debounceMs, supportedExtensions) {
|
|
17
|
+
super();
|
|
18
|
+
this.debounceMs = debounceMs;
|
|
19
|
+
this.supportedExtensions = new Set(supportedExtensions);
|
|
20
|
+
this.watcher = new FSWatcher({
|
|
21
|
+
ignored: /(^|[/\\])\../, // ignore dotfiles and dot folders
|
|
22
|
+
persistent: true,
|
|
23
|
+
awaitWriteFinish: true,
|
|
24
|
+
});
|
|
25
|
+
this.setupListeners();
|
|
26
|
+
}
|
|
27
|
+
setupListeners() {
|
|
28
|
+
this.watcher
|
|
29
|
+
.on('add', (path) => this.handleFileEvent(path, 'file-added'))
|
|
30
|
+
.on('change', (path) => this.handleFileEvent(path, 'file-changed'))
|
|
31
|
+
.on('unlink', (path) => this.handleFileEvent(path, 'file-deleted'))
|
|
32
|
+
.on('error', (error) => logger.error(`Watcher error: ${error}`));
|
|
33
|
+
}
|
|
34
|
+
isSupported(filePath) {
|
|
35
|
+
const ext = extname(filePath).toLowerCase();
|
|
36
|
+
return this.supportedExtensions.has(ext);
|
|
37
|
+
}
|
|
38
|
+
handleFileEvent(filePath, event) {
|
|
39
|
+
if (!this.isSupported(filePath)) {
|
|
40
|
+
return; // Ignore unsupported file types
|
|
41
|
+
}
|
|
42
|
+
// Clear any existing timer to debounce rapid changes
|
|
43
|
+
if (this.debounceTimers.has(filePath)) {
|
|
44
|
+
clearTimeout(this.debounceTimers.get(filePath));
|
|
45
|
+
this.debounceTimers.delete(filePath);
|
|
46
|
+
}
|
|
47
|
+
// For deletions, we want to act immediately.
|
|
48
|
+
if (event === 'file-deleted') {
|
|
49
|
+
logger.info(`Watcher: Detected deletion for: ${filePath}`);
|
|
50
|
+
this.emit('file-deleted', filePath);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
// For adds and changes, debounce the event to avoid churn.
|
|
54
|
+
const timer = setTimeout(() => {
|
|
55
|
+
logger.info(`Watcher: Detected ${event === 'file-added' ? 'addition' : 'change'} for: ${filePath}`);
|
|
56
|
+
this.emit(event, filePath);
|
|
57
|
+
this.debounceTimers.delete(filePath);
|
|
58
|
+
}, this.debounceMs);
|
|
59
|
+
this.debounceTimers.set(filePath, timer);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Checks if a given path is already being watched by chokidar.
|
|
63
|
+
* @param path The absolute path to check.
|
|
64
|
+
* @returns True if the path is being watched, false otherwise.
|
|
65
|
+
*/
|
|
66
|
+
isWatching(path) {
|
|
67
|
+
const watched = this.watcher.getWatched();
|
|
68
|
+
// getWatched() returns an object like: { '/path/to/dir': ['file1.txt', 'file2.txt'], '/path/to/other/file.md': [] }
|
|
69
|
+
const dir = dirname(path);
|
|
70
|
+
const base = basename(path);
|
|
71
|
+
return !!watched[path] || watched[dir]?.includes(base);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Starts watching a given path (file or directory).
|
|
75
|
+
* @param path - The path to watch.
|
|
76
|
+
*/
|
|
77
|
+
watch(path) {
|
|
78
|
+
if (this.isWatching(path)) {
|
|
79
|
+
logger.debug(`Watcher: Already watching ${path}`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
this.watcher.add(path);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Stops watching a given path.
|
|
86
|
+
* @param path - The path to unwatch.
|
|
87
|
+
*/
|
|
88
|
+
unwatch(path) {
|
|
89
|
+
this.watcher.unwatch(path);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Gracefully shuts down the watcher, releasing all file system handles.
|
|
93
|
+
*/
|
|
94
|
+
async close() {
|
|
95
|
+
for (const timer of this.debounceTimers.values()) {
|
|
96
|
+
clearTimeout(timer);
|
|
97
|
+
}
|
|
98
|
+
this.debounceTimers.clear();
|
|
99
|
+
await this.watcher.close();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# source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@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
|
|
2
|
+
import type { NotionSyncer } from '../lib/notion-syncer.js';
|
|
3
|
+
export declare const registerCreatePagesTool: (server: McpServer, notionSyncer: NotionSyncer) => void;
|
|
3
4
|
//# sourceMappingURL=create-pages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-pages.d.ts","sourceRoot":"","sources":["../../src/tools/create-pages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yCAAyC,CAAA;
|
|
1
|
+
{"version":3,"file":"create-pages.d.ts","sourceRoot":"","sources":["../../src/tools/create-pages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yCAAyC,CAAA;AAcxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAyD3D,eAAO,MAAM,uBAAuB,GAAI,QAAQ,SAAS,EAAE,cAAc,YAAY,SAyIjF,CAAA"}
|
|
@@ -58,8 +58,8 @@ Examples of creating pages:
|
|
|
58
58
|
}
|
|
59
59
|
]
|
|
60
60
|
}`;
|
|
61
|
-
export const registerCreatePagesTool = (server) => registerTool(server, {
|
|
62
|
-
name: '
|
|
61
|
+
export const registerCreatePagesTool = (server, notionSyncer) => registerTool(server, {
|
|
62
|
+
name: 'create-pages',
|
|
63
63
|
title: 'Create pages in Markdown',
|
|
64
64
|
description,
|
|
65
65
|
inputSchema: {
|
|
@@ -166,6 +166,7 @@ export const registerCreatePagesTool = (server) => registerTool(server, {
|
|
|
166
166
|
return Promise.all(createPagePromises);
|
|
167
167
|
},
|
|
168
168
|
async formatter(createdPages) {
|
|
169
|
+
await Promise.allSettled(createdPages.map((page) => notionSyncer.triggerImmediateSync(page.id)));
|
|
169
170
|
const results = createdPages.map((page) => {
|
|
170
171
|
const titleProperty = Object.values(page.properties).find((p) => p.type === 'title');
|
|
171
172
|
const title = titleProperty && 'title' in titleProperty && titleProperty.title.length > 0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-pages.js","sourceRoot":"","sources":["../../src/tools/create-pages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAQnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"create-pages.js","sourceRoot":"","sources":["../../src/tools/create-pages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAQnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AAIpE,wEAAwE;AACxE,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoDlB,CAAA;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAAiB,EAAE,YAA0B,EAAE,EAAE,CACvF,YAAY,CAAC,MAAM,EAAE;IACnB,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,0BAA0B;IACjC,WAAW;IACX,WAAW,EAAE;QACX,KAAK,EAAE,CAAC;aACL,KAAK,CACJ,CAAC;aACE,MAAM,CAAC;YACN,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAA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CAAC,MAAM,CAAC;gBACxC,MAAM,EAAE,SAAS;gBACjB,UAAU,EAAE,gBAAgB;gBAC5B,QAAQ;aACT,CAAC,CAAA;YACF,OAAO,OAA6B,CAAA;QACtC,CAAC,CAAC,CAAA;QAEF,OAAO,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;IACxC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,YAAY;QAC1B,MAAM,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAChG,MAAM,OAAO,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YACxC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAA;YACpF,MAAM,KAAK,GACT,aAAa,IAAI,OAAO,IAAI,aAAa,IAAI,aAAa,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;gBACzE,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU;gBACnC,CAAC,CAAC,UAAU,CAAA;YAEhB,OAAO;gBACL,OAAO,EAAE,IAAI,CAAC,EAAE;gBAChB,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,KAAK;aACN,CAAA;QACH,CAAC,CAAC,CAAA;QACF,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,CAAA;IACnC,CAAC;CACF,CAAC,CAAA"}
|
package/dist/tools/fetch.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
|
|
2
|
+
import type { NotionSyncer } from '../lib/notion-syncer.js';
|
|
3
|
+
export declare const registerFetchTool: (server: McpServer, notionSyncer: NotionSyncer) => void;
|
|
3
4
|
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/tools/fetch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yCAAyC,CAAA;
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/tools/fetch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yCAAyC,CAAA;AAmBxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAM3D,eAAO,MAAM,iBAAiB,GAAI,QAAQ,SAAS,EAAE,cAAc,YAAY,SA6F3E,CAAA"}
|
package/dist/tools/fetch.js
CHANGED
|
@@ -3,7 +3,7 @@ import { z } from 'zod';
|
|
|
3
3
|
import { getNotionClient } from '../lib/client.js';
|
|
4
4
|
import { normalizeId } from '../lib/id-utils.js';
|
|
5
5
|
import { formatDatabaseToMarkdown, formatPageToMarkdown } from '../lib/response-formatter.js';
|
|
6
|
-
export const registerFetchTool = (server) => registerTool(server, {
|
|
6
|
+
export const registerFetchTool = (server, notionSyncer) => registerTool(server, {
|
|
7
7
|
name: 'fetch',
|
|
8
8
|
title: 'Fetch Notion entities',
|
|
9
9
|
description: `Retrieves details about a Notion entity by its URL or ID.
|
|
@@ -76,6 +76,7 @@ https://notion.so/page-url?"
|
|
|
76
76
|
},
|
|
77
77
|
async formatter(data) {
|
|
78
78
|
if (data.type === 'page') {
|
|
79
|
+
await notionSyncer.triggerImmediateSync(data.page.id);
|
|
79
80
|
return {
|
|
80
81
|
markdown: await formatPageToMarkdown(data.page, data.blocks.results),
|
|
81
82
|
};
|
package/dist/tools/fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../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M,EAAE,CAAC;YACzB,MAAM,YAAY,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YACrD,OAAO;gBACL,QAAQ,EAAE,MAAM,oBAAoB,CAClC,IAAI,CAAC,IAA0B,EAC/B,IAAI,CAAC,MAAM,CAAC,OAAgC,CAC7C;aACF,CAAA;QACH,CAAC;QACD,qEAAqE;QACrE,OAAO;YACL,QAAQ,EAAE,MAAM,wBAAwB,CACtC,IAAI,CAAC,QAAkC,EACvC,IAAI,CAAC,YAA0C,CAChD;SACF,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NotionSyncer } from '../lib/notion-syncer.js';
|
|
1
2
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
export declare const registerQueryDatasourceTool: (server: McpServer) => void;
|
|
3
|
+
export declare const registerQueryDatasourceTool: (server: McpServer, notionSyncer: NotionSyncer) => void;
|
|
3
4
|
//# sourceMappingURL=query-datasource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-datasource.d.ts","sourceRoot":"","sources":["../../src/tools/query-datasource.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AAExE,eAAO,MAAM,2BAA2B,GAAI,QAAQ,SAAS,
|
|
1
|
+
{"version":3,"file":"query-datasource.d.ts","sourceRoot":"","sources":["../../src/tools/query-datasource.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AAExE,eAAO,MAAM,2BAA2B,GAAI,QAAQ,SAAS,EAAE,cAAc,YAAY,SA+ErF,CAAA"}
|
|
@@ -2,7 +2,7 @@ import { registerTool } from '@mcp-monorepo/shared';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { getNotionClient } from '../lib/client.js';
|
|
4
4
|
import { simplifyNotionPages } from '../lib/parser.js';
|
|
5
|
-
export const registerQueryDatasourceTool = (server) => registerTool(server, {
|
|
5
|
+
export const registerQueryDatasourceTool = (server, notionSyncer) => registerTool(server, {
|
|
6
6
|
name: 'query-datasource',
|
|
7
7
|
title: 'Query a Notion Data Source',
|
|
8
8
|
description: `Gets a list of pages from a data source, identified by its URL (e.g., "collection://<uuid>"). Supports filtering and sorting. The response is paginated; use 'start_cursor' for subsequent requests if 'next_cursor' is returned. Filters operate on properties and can be simple or compound (using "and"/"or"). Sorts operate on properties or timestamps. For performance, you can use 'filter_properties' to retrieve only necessary page properties. Refer to Notion API documentation for the exact filter and sort object structures.`,
|
|
@@ -64,8 +64,8 @@ export const registerQueryDatasourceTool = (server) => registerTool(server, {
|
|
|
64
64
|
throw new Error('An unknown Notion API error occurred.');
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
async formatter(data) {
|
|
68
|
+
await Promise.allSettled(data.results.map((pageOrDatasource) => notionSyncer.triggerImmediateSync(pageOrDatasource.id)));
|
|
69
69
|
return {
|
|
70
70
|
results: simplifyNotionPages(data.results),
|
|
71
71
|
next_cursor: data.next_cursor,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-datasource.js","sourceRoot":"","sources":["../../src/tools/query-datasource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAEnD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"query-datasource.js","sourceRoot":"","sources":["../../src/tools/query-datasource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sB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AC,CAAA;QAC1D,CAAC;IACH,CAAC;IACD,KAAK,CAAC,SAAS,CAAC,IAAI;QAClB,MAAM,OAAO,CAAC,UAAU,CACtB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,EAAE,CAAC,YAAY,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAC/F,CAAA;QACD,OAAO;YACL,OAAO,EAAE,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC;YAC1C,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { NotionSyncer } from '../lib/notion-syncer.js';
|
|
2
|
+
import type { LocalRAG } from '../local-rag/index.js';
|
|
3
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
|
+
/**
|
|
5
|
+
* Registers the Notion search tool with the MCP server.
|
|
6
|
+
* The tool uses a LocalRAG instance for searching and a NotionSyncer for metadata.
|
|
7
|
+
* @param server - The McpServer instance.
|
|
8
|
+
* @param localRag - The initialized LocalRAG instance.
|
|
9
|
+
* @param notionSyncer - The initialized NotionSyncer instance.
|
|
10
|
+
*/
|
|
11
|
+
export declare const registerSearchTool: (server: McpServer, localRag: LocalRAG, notionSyncer: NotionSyncer) => void;
|
|
12
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/tools/search.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AAYxE;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,SAAS,EAAE,UAAU,QAAQ,EAAE,cAAc,YAAY,SA6EnG,CAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { registerTool } from '@mcp-monorepo/shared';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Registers the Notion search tool with the MCP server.
|
|
5
|
+
* The tool uses a LocalRAG instance for searching and a NotionSyncer for metadata.
|
|
6
|
+
* @param server - The McpServer instance.
|
|
7
|
+
* @param localRag - The initialized LocalRAG instance.
|
|
8
|
+
* @param notionSyncer - The initialized NotionSyncer instance.
|
|
9
|
+
*/
|
|
10
|
+
export const registerSearchTool = (server, localRag, notionSyncer) => {
|
|
11
|
+
return registerTool(server, {
|
|
12
|
+
name: 'search',
|
|
13
|
+
title: 'Search Notion workspace',
|
|
14
|
+
description: 'Perform a semantic search over your entire Notion workspace.\nYou can use search when you need to find information which is not already available via other tools, and you don\'t know where it\'s located.\nIf initial results do not contain all the information you need, you can try more specific queries.\nAfter obtaining search results, if the user asks for the full contents of a page or database, use the "fetch" tool. This tool only shows some details like a highlight and the URL and title of each search result.',
|
|
15
|
+
inputSchema: {
|
|
16
|
+
query: z
|
|
17
|
+
.string()
|
|
18
|
+
.min(1)
|
|
19
|
+
.describe("Semantic search query over your entire Notion workspace. For best results, don't provide more than one question per tool call."),
|
|
20
|
+
page_url: z
|
|
21
|
+
.string()
|
|
22
|
+
.optional()
|
|
23
|
+
.describe('Optionally, provide the URL or ID of a page to search within. This will perform a semantic search over the content within and under the specified page.'),
|
|
24
|
+
teamspace_id: z
|
|
25
|
+
.string()
|
|
26
|
+
.optional()
|
|
27
|
+
.describe('Optionally, provide the ID of a teamspace to restrict search results to. This will perform a search over content within the specified teamspace only.'),
|
|
28
|
+
data_source_url: z
|
|
29
|
+
.string()
|
|
30
|
+
.optional()
|
|
31
|
+
.describe('Optionally, provide the URL of a Data source to search. This will perform a semantic search over the pages in the Data Source.'),
|
|
32
|
+
},
|
|
33
|
+
outputSchema: {
|
|
34
|
+
results: z
|
|
35
|
+
.array(z.object({
|
|
36
|
+
title: z.string(),
|
|
37
|
+
url: z.string().url(),
|
|
38
|
+
highlight: z.string(),
|
|
39
|
+
score: z.number(),
|
|
40
|
+
}))
|
|
41
|
+
.describe('An array of search results, ordered by relevance (lower score is better).'),
|
|
42
|
+
},
|
|
43
|
+
isReadOnly: true,
|
|
44
|
+
async fetcher(args) {
|
|
45
|
+
// The core logic is just to query the LocalRAG instance.
|
|
46
|
+
// We don't need the syncer state here, we'll use it in the formatter.
|
|
47
|
+
return localRag.query({
|
|
48
|
+
query: args.query,
|
|
49
|
+
limit: 5, // Return top 5 results
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
async formatter(ragResults) {
|
|
53
|
+
const syncState = notionSyncer.getSyncState();
|
|
54
|
+
if (!syncState) {
|
|
55
|
+
return { results: [] };
|
|
56
|
+
}
|
|
57
|
+
const searchResults = [];
|
|
58
|
+
for (const result of ragResults) {
|
|
59
|
+
// Extract the page ID from the file path (e.g., '.../content/page-id.md')
|
|
60
|
+
const pageId = result.filePath.split(/[/\\]/).pop()?.replace('.md', '');
|
|
61
|
+
if (pageId && syncState.pages[pageId]) {
|
|
62
|
+
const pageInfo = syncState.pages[pageId];
|
|
63
|
+
searchResults.push({
|
|
64
|
+
title: pageInfo.title ?? '<N/A>',
|
|
65
|
+
url: pageInfo.url ?? '<N/A>',
|
|
66
|
+
highlight: result.text,
|
|
67
|
+
score: result.score,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return { results: searchResults };
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/tools/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAC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A;QACJ,CAAC;QACD,KAAK,CAAC,SAAS,CAAC,UAAyB;YACvC,MAAM,SAAS,GAAG,YAAY,CAAC,YAAY,EAAE,CAAA;YAC7C,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAA;YACxB,CAAC;YAED,MAAM,aAAa,GAAyB,EAAE,CAAA;YAC9C,KAAK,MAAM,MAAM,IAAI,UAAU,EAAE,CAAC;gBAChC,0EAA0E;gBAC1E,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;gBAEvE,IAAI,MAAM,IAAI,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;oBACtC,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;oBACxC,aAAa,CAAC,IAAI,CAAC;wBACjB,KAAK,EAAE,QAAQ,CAAC,KAAK,IAAI,OAAO;wBAChC,GAAG,EAAE,QAAQ,CAAC,GAAG,IAAI,OAAO;wBAC5B,SAAS,EAAE,MAAM,CAAC,IAAI;wBACtB,KAAK,EAAE,MAAM,CAAC,KAAK;qBACpB,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,CAAA;QACnC,CAAC;KACF,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { type NotionSyncer } from '../lib/notion-syncer.js';
|
|
3
|
+
export declare const registerUpdatePageTool: (server: McpServer, notionSyncer: NotionSyncer) => void;
|
|
4
|
+
//# sourceMappingURL=update-page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-page.d.ts","sourceRoot":"","sources":["../../src/tools/update-page.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yCAAyC,CAAA;AAaxE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAmC3D,eAAO,MAAM,sBAAsB,GAAI,QAAQ,SAAS,EAAE,cAAc,YAAY,SA4GhF,CAAA"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { registerTool } from '@mcp-monorepo/shared';
|
|
2
|
+
import { markdownToBlocks } from '@tryfabric/martian';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { getNotionClient } from '../lib/client.js';
|
|
5
|
+
import { normalizeId } from '../lib/id-utils.js';
|
|
6
|
+
import { notionToMarkdown } from '../lib/markdown-converter.js';
|
|
7
|
+
import { parsePropertiesForUpdate } from '../lib/property-parser.js';
|
|
8
|
+
const description = `Update a Notion page's properties or content.
|
|
9
|
+
Notion page properties are a JSON map of property names to SQLite values.
|
|
10
|
+
For pages in a database, use the SQLite schema definition shown in <database>.
|
|
11
|
+
For pages outside of a database, the only allowed property is "title", which is the title of the page in inline markdown format.
|
|
12
|
+
Notion page content is a string in Notion-flavored Markdown format. See the "create-pages" tool description for the full enhanced Markdown spec.
|
|
13
|
+
Before updating a page's content with this tool, use the "fetch" tool first to get the existing content to find out the Markdown snippets to use in the "replace_content_range" or "insert_content_after" commands.
|
|
14
|
+
IMPORTANT: Some property types require expanded formats:
|
|
15
|
+
- Date properties: Split into "date:{property}:start", "date:{property}:end" (optional), and "date:{property}:is_datetime" (0 or 1)
|
|
16
|
+
- Place properties: Split into "place:{property}:name", "place:{property}:address", "place:{property}:latitude", "place:{property}:longitude", and "place:{property}:google_place_id" (optional)
|
|
17
|
+
Number properties accept JavaScript numbers (not strings). Use null to remove a property's value. Boolean values like "__YES__" are supported for checkbox properties.`;
|
|
18
|
+
/** Helper function to find and modify a text range based on a start...end snippet */
|
|
19
|
+
function findAndModifyText(fullText, snippet, newText, mode) {
|
|
20
|
+
if (!snippet.includes('...')) {
|
|
21
|
+
throw new Error('Invalid selection_with_ellipsis format. Must contain exactly one "...".');
|
|
22
|
+
}
|
|
23
|
+
const [start, end] = snippet.split('...').map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
24
|
+
const regex = new RegExp(`(${start})([\\s\\S]*?)(${end})`, 's');
|
|
25
|
+
const match = fullText.match(regex);
|
|
26
|
+
if (!match)
|
|
27
|
+
throw new Error(`Could not find the specified content range: "${snippet}"`);
|
|
28
|
+
const originalMatch = match[0];
|
|
29
|
+
if (mode === 'replace')
|
|
30
|
+
return fullText.replace(originalMatch, newText);
|
|
31
|
+
return fullText.replace(originalMatch, originalMatch + newText);
|
|
32
|
+
}
|
|
33
|
+
export const registerUpdatePageTool = (server, notionSyncer) => registerTool(server, {
|
|
34
|
+
name: 'notion-update-page',
|
|
35
|
+
title: 'Update Notion page',
|
|
36
|
+
description,
|
|
37
|
+
inputSchema: {
|
|
38
|
+
data: z.discriminatedUnion('command', [
|
|
39
|
+
z
|
|
40
|
+
.object({
|
|
41
|
+
page_id: z.string().describe('The ID of the page to update, with or without dashes.'),
|
|
42
|
+
command: z.literal('update_properties'),
|
|
43
|
+
properties: z.record(z.union([z.string(), z.number(), z.boolean(), z.null()])),
|
|
44
|
+
})
|
|
45
|
+
.strict(),
|
|
46
|
+
z
|
|
47
|
+
.object({
|
|
48
|
+
page_id: z.string().describe('The ID of the page to update, with or without dashes.'),
|
|
49
|
+
command: z.literal('replace_content'),
|
|
50
|
+
new_str: z.string().describe('The new string to replace all content with.'),
|
|
51
|
+
})
|
|
52
|
+
.strict(),
|
|
53
|
+
z
|
|
54
|
+
.object({
|
|
55
|
+
page_id: z.string().describe('The ID of the page to update, with or without dashes.'),
|
|
56
|
+
command: z.literal('replace_content_range'),
|
|
57
|
+
selection_with_ellipsis: z.string().describe('Unique start and end snippet of the string to replace...'),
|
|
58
|
+
new_str: z.string().describe('The new string to replace the old string with.'),
|
|
59
|
+
})
|
|
60
|
+
.strict(),
|
|
61
|
+
z
|
|
62
|
+
.object({
|
|
63
|
+
page_id: z.string().describe('The ID of the page to update, with or without dashes.'),
|
|
64
|
+
command: z.literal('insert_content_after'),
|
|
65
|
+
selection_with_ellipsis: z.string().describe('Unique start and end snippet of the string to match...'),
|
|
66
|
+
new_str: z.string().describe('The new content to insert.'),
|
|
67
|
+
})
|
|
68
|
+
.strict(),
|
|
69
|
+
]),
|
|
70
|
+
},
|
|
71
|
+
outputSchema: {
|
|
72
|
+
page_id: z.string(),
|
|
73
|
+
url: z.string(),
|
|
74
|
+
last_edited_time: z.string(),
|
|
75
|
+
},
|
|
76
|
+
async fetcher(args) {
|
|
77
|
+
const notion = getNotionClient();
|
|
78
|
+
const { data } = args;
|
|
79
|
+
const pageId = normalizeId(data.page_id);
|
|
80
|
+
if (!pageId)
|
|
81
|
+
throw new Error(`Invalid page_id: ${data.page_id}`);
|
|
82
|
+
switch (data.command) {
|
|
83
|
+
case 'update_properties': {
|
|
84
|
+
const page = (await notion.pages.retrieve({ page_id: pageId }));
|
|
85
|
+
if (page.parent.type !== 'data_source_id') {
|
|
86
|
+
throw new Error('Cannot update properties on a page that is not in a database.');
|
|
87
|
+
}
|
|
88
|
+
const dataSource = (await notion.dataSources.retrieve({
|
|
89
|
+
data_source_id: page.parent.data_source_id,
|
|
90
|
+
}));
|
|
91
|
+
const notionProperties = parsePropertiesForUpdate(data.properties, dataSource.properties);
|
|
92
|
+
return (await notion.pages.update({ page_id: pageId, properties: notionProperties }));
|
|
93
|
+
}
|
|
94
|
+
case 'replace_content':
|
|
95
|
+
case 'replace_content_range':
|
|
96
|
+
case 'insert_content_after': {
|
|
97
|
+
const allBlocks = (await notion.blocks.children.list({ block_id: pageId })).results;
|
|
98
|
+
let newMarkdown;
|
|
99
|
+
if (data.command === 'replace_content') {
|
|
100
|
+
newMarkdown = data.new_str;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const originalMd = await notionToMarkdown(allBlocks);
|
|
104
|
+
const mode = data.command === 'replace_content_range' ? 'replace' : 'insert_after';
|
|
105
|
+
newMarkdown = findAndModifyText(originalMd, data.selection_with_ellipsis, data.new_str, mode);
|
|
106
|
+
}
|
|
107
|
+
// Delete all existing blocks before adding new ones.
|
|
108
|
+
// This is inefficient but necessary for replacement commands.
|
|
109
|
+
const deletePromises = allBlocks.map((block) => notion.blocks.delete({ block_id: block.id }));
|
|
110
|
+
await Promise.all(deletePromises);
|
|
111
|
+
const newBlocks = markdownToBlocks(newMarkdown);
|
|
112
|
+
const chunks = [];
|
|
113
|
+
for (let i = 0; i < newBlocks.length; i += 100) {
|
|
114
|
+
chunks.push(newBlocks.slice(i, i + 100));
|
|
115
|
+
}
|
|
116
|
+
for (const chunk of chunks) {
|
|
117
|
+
await notion.blocks.children.append({ block_id: pageId, children: chunk });
|
|
118
|
+
}
|
|
119
|
+
return (await notion.pages.retrieve({ page_id: pageId }));
|
|
120
|
+
}
|
|
121
|
+
default:
|
|
122
|
+
// This case should be unreachable due to Zod validation
|
|
123
|
+
throw new Error('Invalid command for update-page tool.');
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
async formatter(updatedPage) {
|
|
127
|
+
await notionSyncer.triggerImmediateSync(updatedPage.id);
|
|
128
|
+
return {
|
|
129
|
+
page_id: updatedPage.id,
|
|
130
|
+
url: updatedPage.url,
|
|
131
|
+
last_edited_time: updatedPage.last_edited_time,
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
//# sourceMappingURL=update-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-page.js","sourceRoot":"","sources":["../../src/tools/update-page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAQnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,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c,CAAC,CAAA;gBAEjC,MAAM,SAAS,GAAG,gBAAgB,CAAC,WAAW,CAAyB,CAAA;gBACvE,MAAM,MAAM,GAAG,EAAE,CAAA;gBACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC;oBAC/C,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;gBAC1C,CAAC;gBACD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;oBAC3B,MAAM,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAA;gBAC5E,CAAC;gBAED,OAAO,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAuB,CAAA;YACjF,CAAC;YACD;gBACE,wDAAwD;gBACxD,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAA;QAC5D,CAAC;IACH,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,WAAW;QACzB,MAAM,YAAY,CAAC,oBAAoB,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;QACvD,OAAO;YACL,OAAO,EAAE,WAAW,CAAC,EAAE;YACvB,GAAG,EAAE,WAAW,CAAC,GAAG;YACpB,gBAAgB,EAAE,WAAW,CAAC,gBAAgB;SAC/C,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-monorepo/notion-query",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MCP server for querying Notion data sources.",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"build": "tsc -b",
|
|
17
17
|
"dev": "tsc --watch",
|
|
18
18
|
"start": "node dist/index.js",
|
|
19
|
+
"demo": "node dist/local-rag/DEMO.js",
|
|
19
20
|
"test": "vitest run --passWithNoTests",
|
|
20
21
|
"test:watch": "vitest",
|
|
21
22
|
"test:coverage": "vitest run --coverage",
|
|
@@ -23,15 +24,28 @@
|
|
|
23
24
|
"clean": "rimraf dist tsconfig.tsbuildinfo"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
27
|
+
"@huggingface/transformers": "^3.8.1",
|
|
28
|
+
"@lancedb/lancedb": "0.22.2",
|
|
29
|
+
"@langchain/core": "^1.1.8",
|
|
30
|
+
"@langchain/textsplitters": "^1.0.1",
|
|
26
31
|
"@mcp-monorepo/shared": "workspace:*",
|
|
27
32
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
33
|
+
"@mozilla/readability": "^0.6.0",
|
|
28
34
|
"@notionhq/client": "^5.6.0",
|
|
29
35
|
"@tryfabric/martian": "^1.2.4",
|
|
36
|
+
"apache-arrow": "^21.1.0",
|
|
37
|
+
"chokidar": "^5.0.0",
|
|
38
|
+
"jsdom": "^27.3.0",
|
|
39
|
+
"mammoth": "^1.11.0",
|
|
30
40
|
"notion-to-md": "^3.1.9",
|
|
41
|
+
"papaparse": "^5.5.3",
|
|
42
|
+
"pdf-parse": "^2.4.5",
|
|
31
43
|
"zod": "^3.25.76"
|
|
32
44
|
},
|
|
33
45
|
"devDependencies": {
|
|
46
|
+
"@types/jsdom": "^27",
|
|
34
47
|
"@types/node": "^22.14.1",
|
|
48
|
+
"@types/papaparse": "^5",
|
|
35
49
|
"rimraf": "^6.0.1",
|
|
36
50
|
"typescript": "^5.8.3",
|
|
37
51
|
"vitest": "^3.2.4"
|