roam-research-mcp 0.25.7 → 0.27.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/README.md +44 -606
- package/build/config/environment.js +3 -1
- package/build/server/roam-server.js +113 -30
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -5,16 +5,25 @@
|
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
[](https://github.com/2b3pro/roam-research-mcp/blob/main/LICENSE)
|
|
7
7
|
|
|
8
|
-
A Model Context Protocol (MCP) server that provides comprehensive access to Roam Research's API functionality. This server enables AI assistants like Claude to interact with your Roam Research graph through a standardized interface. (A WORK-IN-PROGRESS, personal project not officially endorsed by Roam Research)
|
|
8
|
+
A Model Context Protocol (MCP) server that provides comprehensive access to Roam Research's API functionality. This server enables AI assistants like Claude to interact with your Roam Research graph through a standardized interface. It supports standard input/output (stdio), HTTP Stream, and Server-Sent Events (SSE) communication. (A WORK-IN-PROGRESS, personal project not officially endorsed by Roam Research)
|
|
9
9
|
|
|
10
10
|
<a href="https://glama.ai/mcp/servers/fzfznyaflu"><img width="380" height="200" src="https://glama.ai/mcp/servers/fzfznyaflu/badge" alt="Roam Research MCP server" /></a>
|
|
11
11
|
|
|
12
|
-
## Installation
|
|
12
|
+
## Installation and Usage
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
This MCP server supports three primary communication methods:
|
|
15
|
+
|
|
16
|
+
1. **Stdio (Standard Input/Output):** Ideal for local inter-process communication, command-line tools, and direct integration with applications running on the same machine. This is the default communication method when running the server directly.
|
|
17
|
+
2. **HTTP Stream:** Provides network-based communication, suitable for web-based clients, remote applications, or scenarios requiring real-time updates over HTTP. The HTTP Stream endpoint runs on port `8088` by default.
|
|
18
|
+
3. **SSE (Server-Sent Events):** A transport for legacy clients that require SSE. The SSE endpoint runs on port `8087` by default. (NOTE: ⚠️ DEPRECATED: The SSE Transport has been deprecated as of MCP specification version 2025-03-26. HTTP Stream Transport preferred.)
|
|
19
|
+
|
|
20
|
+
### Running with Stdio
|
|
21
|
+
|
|
22
|
+
You can install the package globally and run it:
|
|
15
23
|
|
|
16
24
|
```bash
|
|
17
25
|
npm install -g roam-research-mcp
|
|
26
|
+
roam-research-mcp
|
|
18
27
|
```
|
|
19
28
|
|
|
20
29
|
Or clone the repository and build from source:
|
|
@@ -24,8 +33,22 @@ git clone https://github.com/2b3pro/roam-research-mcp.git
|
|
|
24
33
|
cd roam-research-mcp
|
|
25
34
|
npm install
|
|
26
35
|
npm run build
|
|
36
|
+
npm start
|
|
27
37
|
```
|
|
28
38
|
|
|
39
|
+
### Running with HTTP Stream
|
|
40
|
+
|
|
41
|
+
To run the server with HTTP Stream or SSE support, you can either:
|
|
42
|
+
|
|
43
|
+
1. **Use the default ports:** Run `npm start` after building (as shown above). The server will automatically listen on port `8088` for HTTP Stream and `8087` for SSE.
|
|
44
|
+
2. **Specify custom ports:** Set the `HTTP_STREAM_PORT` and/or `SSE_PORT` environment variables before starting the server.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
HTTP_STREAM_PORT=9000 SSE_PORT=9001 npm start
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Or, if using a `.env` file, add `HTTP_STREAM_PORT=9000` and/or `SSE_PORT=9001` to it.
|
|
51
|
+
|
|
29
52
|
## Docker
|
|
30
53
|
|
|
31
54
|
This project can be easily containerized using Docker. A `Dockerfile` is provided at the root of the repository.
|
|
@@ -40,20 +63,22 @@ docker build -t roam-research-mcp .
|
|
|
40
63
|
|
|
41
64
|
### Run the Docker Container
|
|
42
65
|
|
|
43
|
-
To run the Docker container and map
|
|
66
|
+
To run the Docker container and map the necessary ports, you must also provide the required environment variables. Use the `-e` flag to pass `ROAM_API_TOKEN`, `ROAM_GRAPH_NAME`, and optionally `MEMORIES_TAG`, `HTTP_STREAM_PORT`, and `SSE_PORT`:
|
|
44
67
|
|
|
45
68
|
```bash
|
|
46
|
-
docker run -p 3000:3000 \
|
|
69
|
+
docker run -p 3000:3000 -p 8088:8088 -p 8087:8087 \
|
|
47
70
|
-e ROAM_API_TOKEN="your-api-token" \
|
|
48
71
|
-e ROAM_GRAPH_NAME="your-graph-name" \
|
|
49
72
|
-e MEMORIES_TAG="#[[LLM/Memories]]" \
|
|
73
|
+
-e HTTP_STREAM_PORT="8088" \
|
|
74
|
+
-e SSE_PORT="8087" \
|
|
50
75
|
roam-research-mcp
|
|
51
76
|
```
|
|
52
77
|
|
|
53
78
|
Alternatively, if you have a `.env` file in the project root (which is copied into the Docker image during build), you can use the `--env-file` flag:
|
|
54
79
|
|
|
55
80
|
```bash
|
|
56
|
-
docker run -p 3000:3000 --env-file .env roam-research-mcp
|
|
81
|
+
docker run -p 3000:3000 -p 8088:8088 --env-file .env roam-research-mcp
|
|
57
82
|
```
|
|
58
83
|
|
|
59
84
|
## To Test
|
|
@@ -89,11 +114,13 @@ The server provides powerful tools for interacting with Roam Research:
|
|
|
89
114
|
9. `roam_find_pages_modified_today`: Find pages that have been modified today (since midnight).
|
|
90
115
|
10. `roam_search_by_text`: Search for blocks containing specific text.
|
|
91
116
|
11. `roam_update_block`: Update a single block identified by its UID.
|
|
92
|
-
12. `
|
|
93
|
-
13. `
|
|
94
|
-
14. `
|
|
95
|
-
15. `
|
|
96
|
-
16. `
|
|
117
|
+
12. `roam_update_multiple_blocks`: Efficiently update multiple blocks in a single batch operation.
|
|
118
|
+
13. `roam_search_by_status`: Search for blocks with a specific status (TODO/DONE) across all pages or within a specific page.
|
|
119
|
+
14. `roam_search_by_date`: Search for blocks or pages based on creation or modification dates.
|
|
120
|
+
15. `roam_search_for_tag`: Search for blocks containing a specific tag and optionally filter by blocks that also contain another tag nearby.
|
|
121
|
+
16. `roam_remember`: Add a memory or piece of information to remember.
|
|
122
|
+
17. `roam_recall`: Retrieve all stored memories.
|
|
123
|
+
18. `roam_datomic_query`: Execute a custom Datomic query on the Roam graph beyond the available search tools.
|
|
97
124
|
|
|
98
125
|
## Setup
|
|
99
126
|
|
|
@@ -113,10 +140,12 @@ The server provides powerful tools for interacting with Roam Research:
|
|
|
113
140
|
ROAM_API_TOKEN=your-api-token
|
|
114
141
|
ROAM_GRAPH_NAME=your-graph-name
|
|
115
142
|
MEMORIES_TAG='#[[LLM/Memories]]'
|
|
143
|
+
HTTP_STREAM_PORT=8088 # Or your desired port for HTTP Stream communication
|
|
144
|
+
SSE_PORT=8087 # Or your desired port for SSE communication
|
|
116
145
|
```
|
|
117
146
|
|
|
118
147
|
Option 2: Using MCP settings (Alternative method)
|
|
119
|
-
Add the configuration to your MCP settings file
|
|
148
|
+
Add the configuration to your MCP settings file. Note that you may need to update the `args` to `["/path/to/roam-research-mcp/build/index.js"]` if you are running the server directly.
|
|
120
149
|
|
|
121
150
|
- For Cline (`~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json`):
|
|
122
151
|
- For Claude desktop app (`~/Library/Application Support/Claude/claude_desktop_config.json`):
|
|
@@ -130,7 +159,9 @@ The server provides powerful tools for interacting with Roam Research:
|
|
|
130
159
|
"env": {
|
|
131
160
|
"ROAM_API_TOKEN": "your-api-token",
|
|
132
161
|
"ROAM_GRAPH_NAME": "your-graph-name",
|
|
133
|
-
"MEMORIES_TAG": "#[[LLM/Memories]]"
|
|
162
|
+
"MEMORIES_TAG": "#[[LLM/Memories]]",
|
|
163
|
+
"HTTP_STREAM_PORT": "8088",
|
|
164
|
+
"SSE_PORT": "8087"
|
|
134
165
|
}
|
|
135
166
|
}
|
|
136
167
|
}
|
|
@@ -146,599 +177,6 @@ The server provides powerful tools for interacting with Roam Research:
|
|
|
146
177
|
npm run build
|
|
147
178
|
```
|
|
148
179
|
|
|
149
|
-
## Usage
|
|
150
|
-
|
|
151
|
-
### Fetch Page By Title
|
|
152
|
-
|
|
153
|
-
Fetch and read a page's content with resolved block references:
|
|
154
|
-
|
|
155
|
-
```typescript
|
|
156
|
-
use_mcp_tool roam-research roam_fetch_page_by_title {
|
|
157
|
-
"title": "Example Page"
|
|
158
|
-
}
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
Returns the page content as markdown with:
|
|
162
|
-
|
|
163
|
-
- Complete hierarchical structure
|
|
164
|
-
- Block references recursively resolved (up to 4 levels deep)
|
|
165
|
-
- Proper indentation for nesting levels
|
|
166
|
-
- Full markdown formatting
|
|
167
|
-
|
|
168
|
-
### Create Page
|
|
169
|
-
|
|
170
|
-
Create a new page with optional content:
|
|
171
|
-
|
|
172
|
-
```typescript
|
|
173
|
-
use_mcp_tool roam-research roam_create_page {
|
|
174
|
-
"title": "New Page",
|
|
175
|
-
"content": "Initial content for the page"
|
|
176
|
-
}
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
Returns the created page's UID on success.
|
|
180
|
-
|
|
181
|
-
### Create Block
|
|
182
|
-
|
|
183
|
-
Add a new block to a page (defaults to today's daily page if neither page_uid nor title provided):
|
|
184
|
-
|
|
185
|
-
```typescript
|
|
186
|
-
use_mcp_tool roam-research roam_create_block {
|
|
187
|
-
"content": "Block content",
|
|
188
|
-
"page_uid": "optional-target-page-uid",
|
|
189
|
-
"title": "optional-target-page-title"
|
|
190
|
-
}
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
You can specify either:
|
|
194
|
-
|
|
195
|
-
- `page_uid`: Direct reference to target page
|
|
196
|
-
- `title`: Name of target page (will be created if it doesn't exist)
|
|
197
|
-
- Neither: Block will be added to today's daily page
|
|
198
|
-
|
|
199
|
-
Returns:
|
|
200
|
-
|
|
201
|
-
```json
|
|
202
|
-
{
|
|
203
|
-
"success": true,
|
|
204
|
-
"block_uid": "created-block-uid",
|
|
205
|
-
"parent_uid": "parent-page-uid"
|
|
206
|
-
}
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
### Create Outline
|
|
210
|
-
|
|
211
|
-
Create a hierarchical outline with proper nesting and structure:
|
|
212
|
-
|
|
213
|
-
```typescript
|
|
214
|
-
use_mcp_tool roam-research roam_create_outline {
|
|
215
|
-
"outline": [
|
|
216
|
-
{
|
|
217
|
-
"text": "I. Top Level",
|
|
218
|
-
"level": 1
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
"text": "A. Second Level",
|
|
222
|
-
"level": 2
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
"text": "1. Third Level",
|
|
226
|
-
"level": 3
|
|
227
|
-
}
|
|
228
|
-
],
|
|
229
|
-
"page_title_uid": "optional-target-page",
|
|
230
|
-
"block_text_uid": "optional-header-text"
|
|
231
|
-
}
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
Features:
|
|
235
|
-
|
|
236
|
-
- Create complex outlines with up to 10 levels of nesting
|
|
237
|
-
- Validate outline structure and content
|
|
238
|
-
- Maintain proper parent-child relationships
|
|
239
|
-
- Optional header block for the outline
|
|
240
|
-
- Defaults to today's daily page if no page specified
|
|
241
|
-
- Efficient batch operations for creating blocks
|
|
242
|
-
|
|
243
|
-
Parameters:
|
|
244
|
-
|
|
245
|
-
- `outline`: Array of outline items, each with:
|
|
246
|
-
- `text`: Content of the outline item (required)
|
|
247
|
-
- `level`: Nesting level (1-10, required)
|
|
248
|
-
- `page_title_uid`: Target page title or UID (optional, defaults to today's page)
|
|
249
|
-
- `block_text_uid`: Header text for the outline (optional)
|
|
250
|
-
|
|
251
|
-
Returns:
|
|
252
|
-
|
|
253
|
-
```json
|
|
254
|
-
{
|
|
255
|
-
"success": true,
|
|
256
|
-
"page_uid": "target-page-uid",
|
|
257
|
-
"parent_uid": "header-block-uid",
|
|
258
|
-
"created_uids": ["uid1", "uid2", ...]
|
|
259
|
-
}
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
### Add Todo Items
|
|
263
|
-
|
|
264
|
-
Add one or more todo items to today's daily page:
|
|
265
|
-
|
|
266
|
-
```typescript
|
|
267
|
-
use_mcp_tool roam-research roam_add_todo {
|
|
268
|
-
"todos": [
|
|
269
|
-
"First todo item",
|
|
270
|
-
"Second todo item",
|
|
271
|
-
"Third todo item"
|
|
272
|
-
]
|
|
273
|
-
}
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
Features:
|
|
277
|
-
|
|
278
|
-
- Adds todos with Roam checkbox syntax (`{{TODO}} todo text`)
|
|
279
|
-
- Supports adding multiple todos in a single operation
|
|
280
|
-
- Uses batch actions for efficiency when adding >10 todos
|
|
281
|
-
- Automatically creates today's page if it doesn't exist
|
|
282
|
-
- Adds todos as top-level blocks in sequential order
|
|
283
|
-
|
|
284
|
-
### Import Nested Markdown
|
|
285
|
-
|
|
286
|
-
Import nested markdown content under a specific block:
|
|
287
|
-
|
|
288
|
-
```typescript
|
|
289
|
-
use_mcp_tool roam-research roam_import_markdown {
|
|
290
|
-
"content": "- Item 1\n - Subitem A\n - Subitem B\n- Item 2",
|
|
291
|
-
"page_uid": "optional-page-uid",
|
|
292
|
-
"page_title": "optional-page-title",
|
|
293
|
-
"parent_uid": "optional-parent-block-uid",
|
|
294
|
-
"parent_string": "optional-exact-block-content",
|
|
295
|
-
"order": "first"
|
|
296
|
-
}
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
Features:
|
|
300
|
-
|
|
301
|
-
- Import content under specific blocks:
|
|
302
|
-
- Find parent block by UID or exact string match
|
|
303
|
-
- Locate blocks within specific pages by title or UID
|
|
304
|
-
- Defaults to today's page if no page specified
|
|
305
|
-
- Control content placement:
|
|
306
|
-
- Add as first or last child of parent block
|
|
307
|
-
- Preserve hierarchical structure
|
|
308
|
-
- Efficient batch operations for nested content
|
|
309
|
-
- Comprehensive return value:
|
|
310
|
-
```json
|
|
311
|
-
{
|
|
312
|
-
"success": true,
|
|
313
|
-
"page_uid": "target-page-uid",
|
|
314
|
-
"parent_uid": "parent-block-uid",
|
|
315
|
-
"created_uids": ["uid1", "uid2", ...]
|
|
316
|
-
}
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
Parameters:
|
|
320
|
-
|
|
321
|
-
- `content`: Nested markdown content to import
|
|
322
|
-
- `page_uid`: UID of the page containing the parent block
|
|
323
|
-
- `page_title`: Title of the page containing the parent block (ignored if page_uid provided)
|
|
324
|
-
- `parent_uid`: UID of the parent block to add content under
|
|
325
|
-
- `parent_string`: Exact string content of the parent block (must provide either page_uid or page_title)
|
|
326
|
-
- `order`: Where to add the content ("first" or "last", defaults to "first")
|
|
327
|
-
|
|
328
|
-
### Search Block References
|
|
329
|
-
|
|
330
|
-
Search for block references within pages or across the entire graph:
|
|
331
|
-
|
|
332
|
-
```typescript
|
|
333
|
-
use_mcp_tool roam-research roam_search_block_refs {
|
|
334
|
-
"block_uid": "optional-block-uid",
|
|
335
|
-
"page_title_uid": "optional-page-title-or-uid"
|
|
336
|
-
}
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
Features:
|
|
340
|
-
|
|
341
|
-
- Find all references to a specific block
|
|
342
|
-
- Search for any block references within a page
|
|
343
|
-
- Search across the entire graph
|
|
344
|
-
- Supports both direct and indirect references
|
|
345
|
-
- Includes block content and location context
|
|
346
|
-
|
|
347
|
-
Parameters:
|
|
348
|
-
|
|
349
|
-
- `block_uid`: UID of the block to find references to (optional)
|
|
350
|
-
- `page_title_uid`: Title or UID of the page to search in (optional)
|
|
351
|
-
|
|
352
|
-
Returns:
|
|
353
|
-
|
|
354
|
-
```json
|
|
355
|
-
{
|
|
356
|
-
"success": true,
|
|
357
|
-
"matches": [
|
|
358
|
-
{
|
|
359
|
-
"block_uid": "referenced-block-uid",
|
|
360
|
-
"content": "Block content with ((reference))",
|
|
361
|
-
"page_title": "Page containing reference"
|
|
362
|
-
}
|
|
363
|
-
],
|
|
364
|
-
"message": "Found N block(s) referencing..."
|
|
365
|
-
}
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
### Search By Text
|
|
369
|
-
|
|
370
|
-
Search for blocks containing specific text across all pages or within a specific page:
|
|
371
|
-
|
|
372
|
-
```typescript
|
|
373
|
-
use_mcp_tool roam-research roam_search_by_text {
|
|
374
|
-
"text": "search text",
|
|
375
|
-
"page_title_uid": "optional-page-title-or-uid",
|
|
376
|
-
"case_sensitive": true
|
|
377
|
-
}
|
|
378
|
-
```
|
|
379
|
-
|
|
380
|
-
Features:
|
|
381
|
-
|
|
382
|
-
- Search for any text across all blocks in the graph
|
|
383
|
-
- Optional page-scoped search
|
|
384
|
-
- Case-sensitive or case-insensitive search
|
|
385
|
-
- Returns block content with page context
|
|
386
|
-
- Efficient text matching using Datalog queries
|
|
387
|
-
|
|
388
|
-
Parameters:
|
|
389
|
-
|
|
390
|
-
- `text`: The text to search for (required)
|
|
391
|
-
- `page_title_uid`: Title or UID of the page to search in (optional)
|
|
392
|
-
- `case_sensitive`: Whether to perform a case-sensitive search (optional, default: true to match Roam's native behavior)
|
|
393
|
-
|
|
394
|
-
Returns:
|
|
395
|
-
|
|
396
|
-
```json
|
|
397
|
-
{
|
|
398
|
-
"success": true,
|
|
399
|
-
"matches": [
|
|
400
|
-
{
|
|
401
|
-
"block_uid": "matching-block-uid",
|
|
402
|
-
"content": "Block content containing search text",
|
|
403
|
-
"page_title": "Page containing block"
|
|
404
|
-
}
|
|
405
|
-
],
|
|
406
|
-
"message": "Found N block(s) containing \"search text\""
|
|
407
|
-
}
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
### Update Block Content
|
|
411
|
-
|
|
412
|
-
Update a block's content using either direct text replacement or pattern-based transformations:
|
|
413
|
-
|
|
414
|
-
```typescript
|
|
415
|
-
use_mcp_tool roam-research roam_update_block {
|
|
416
|
-
"block_uid": "target-block-uid",
|
|
417
|
-
"content": "New block content"
|
|
418
|
-
}
|
|
419
|
-
```
|
|
420
|
-
|
|
421
|
-
Or use pattern-based transformation:
|
|
422
|
-
|
|
423
|
-
```typescript
|
|
424
|
-
use_mcp_tool roam-research roam_update_block {
|
|
425
|
-
"block_uid": "target-block-uid",
|
|
426
|
-
"transform_pattern": {
|
|
427
|
-
"find": "\\bPython\\b",
|
|
428
|
-
"replace": "[[Python]]",
|
|
429
|
-
"global": true
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
Features:
|
|
435
|
-
|
|
436
|
-
- Two update modes:
|
|
437
|
-
- Direct content replacement
|
|
438
|
-
- Pattern-based transformation using regex
|
|
439
|
-
- Verify block existence before updating
|
|
440
|
-
- Return updated content in response
|
|
441
|
-
- Support for global or single-match replacements
|
|
442
|
-
- Preserve block relationships and metadata
|
|
443
|
-
|
|
444
|
-
Parameters:
|
|
445
|
-
|
|
446
|
-
- `block_uid`: UID of the block to update (required)
|
|
447
|
-
- `content`: New content for the block (if using direct replacement)
|
|
448
|
-
- `transform_pattern`: Pattern for transforming existing content:
|
|
449
|
-
- `find`: Text or regex pattern to find
|
|
450
|
-
- `replace`: Text to replace with
|
|
451
|
-
- `global`: Whether to replace all occurrences (default: true)
|
|
452
|
-
|
|
453
|
-
Returns:
|
|
454
|
-
|
|
455
|
-
```json
|
|
456
|
-
{
|
|
457
|
-
"success": true,
|
|
458
|
-
"content": "Updated block content"
|
|
459
|
-
}
|
|
460
|
-
```
|
|
461
|
-
|
|
462
|
-
### Search For Tags
|
|
463
|
-
|
|
464
|
-
Search for blocks containing specific tags with optional filtering by nearby tags:
|
|
465
|
-
|
|
466
|
-
```typescript
|
|
467
|
-
use_mcp_tool roam-research roam_search_for_tag {
|
|
468
|
-
"primary_tag": "Project/Tasks",
|
|
469
|
-
"page_title_uid": "optional-page-title-or-uid",
|
|
470
|
-
"near_tag": "optional-secondary-tag",
|
|
471
|
-
"case_sensitive": true
|
|
472
|
-
}
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
Features:
|
|
476
|
-
|
|
477
|
-
- Search for blocks containing specific tags
|
|
478
|
-
- Optional filtering by presence of another tag
|
|
479
|
-
- Page-scoped or graph-wide search
|
|
480
|
-
- Case-sensitive or case-insensitive search
|
|
481
|
-
- Returns block content with page context
|
|
482
|
-
- Efficient tag matching using Datalog queries
|
|
483
|
-
|
|
484
|
-
Parameters:
|
|
485
|
-
|
|
486
|
-
- `primary_tag`: The main tag to search for (required)
|
|
487
|
-
- `page_title_uid`: Title or UID of the page to search in (optional)
|
|
488
|
-
- `near_tag`: Another tag to filter results by (optional)
|
|
489
|
-
- `case_sensitive`: Whether to perform case-sensitive search (optional, default: true to match Roam's native behavior)
|
|
490
|
-
|
|
491
|
-
Returns:
|
|
492
|
-
|
|
493
|
-
```json
|
|
494
|
-
{
|
|
495
|
-
"success": true,
|
|
496
|
-
"matches": [
|
|
497
|
-
{
|
|
498
|
-
"block_uid": "matching-block-uid",
|
|
499
|
-
"content": "Block content containing #[[primary_tag]]",
|
|
500
|
-
"page_title": "Page containing block"
|
|
501
|
-
}
|
|
502
|
-
],
|
|
503
|
-
"message": "Found N block(s) referencing \"primary_tag\""
|
|
504
|
-
}
|
|
505
|
-
```
|
|
506
|
-
|
|
507
|
-
### Remember Information
|
|
508
|
-
|
|
509
|
-
Store memories or important information with automatic tagging and categorization:
|
|
510
|
-
|
|
511
|
-
```typescript
|
|
512
|
-
use_mcp_tool roam-research roam_remember {
|
|
513
|
-
"memory": "Important information to remember",
|
|
514
|
-
"categories": ["Work", "Project/Alpha"]
|
|
515
|
-
}
|
|
516
|
-
```
|
|
517
|
-
|
|
518
|
-
Features:
|
|
519
|
-
|
|
520
|
-
- Store information with #[[LLM/Memories]] tag
|
|
521
|
-
- Add optional category tags for organization
|
|
522
|
-
- Automatically adds to today's daily page
|
|
523
|
-
- Supports multiple categories per memory
|
|
524
|
-
- Easy retrieval using roam_search_for_tag
|
|
525
|
-
- Maintains chronological order of memories
|
|
526
|
-
|
|
527
|
-
Parameters:
|
|
528
|
-
|
|
529
|
-
- `memory`: The information to remember (required)
|
|
530
|
-
- `categories`: Optional array of categories to tag the memory with
|
|
531
|
-
|
|
532
|
-
Returns:
|
|
533
|
-
|
|
534
|
-
```json
|
|
535
|
-
{
|
|
536
|
-
"success": true,
|
|
537
|
-
"block_uid": "created-block-uid",
|
|
538
|
-
"content": "Memory content with tags"
|
|
539
|
-
}
|
|
540
|
-
```
|
|
541
|
-
|
|
542
|
-
### Search By Date
|
|
543
|
-
|
|
544
|
-
Search for blocks and pages based on creation or modification dates:
|
|
545
|
-
|
|
546
|
-
```typescript
|
|
547
|
-
use_mcp_tool roam-research roam_search_by_date {
|
|
548
|
-
"start_date": "2025-01-01",
|
|
549
|
-
"end_date": "2025-01-31",
|
|
550
|
-
"type": "modified",
|
|
551
|
-
"scope": "blocks",
|
|
552
|
-
"include_content": true
|
|
553
|
-
}
|
|
554
|
-
```
|
|
555
|
-
|
|
556
|
-
Features:
|
|
557
|
-
|
|
558
|
-
- Search by creation date, modification date, or both
|
|
559
|
-
- Filter blocks, pages, or both
|
|
560
|
-
- Optional date range with start and end dates
|
|
561
|
-
- Include or exclude block/page content in results
|
|
562
|
-
- Sort results by timestamp
|
|
563
|
-
- Efficient date-based filtering using Datalog queries
|
|
564
|
-
|
|
565
|
-
Parameters:
|
|
566
|
-
|
|
567
|
-
- `start_date`: Start date in ISO format (YYYY-MM-DD) (required)
|
|
568
|
-
- `end_date`: End date in ISO format (YYYY-MM-DD) (optional)
|
|
569
|
-
- `type`: Whether to search by 'created', 'modified', or 'both' (required)
|
|
570
|
-
- `scope`: Whether to search 'blocks', 'pages', or 'both' (required)
|
|
571
|
-
- `include_content`: Whether to include the content of matching blocks/pages (optional, default: true)
|
|
572
|
-
|
|
573
|
-
Returns:
|
|
574
|
-
|
|
575
|
-
```json
|
|
576
|
-
{
|
|
577
|
-
"success": true,
|
|
578
|
-
"matches": [
|
|
579
|
-
{
|
|
580
|
-
"uid": "block-or-page-uid",
|
|
581
|
-
"type": "block",
|
|
582
|
-
"time": 1704067200000,
|
|
583
|
-
"content": "Block or page content",
|
|
584
|
-
"page_title": "Page title (for blocks)"
|
|
585
|
-
}
|
|
586
|
-
],
|
|
587
|
-
"message": "Found N matches for the given date range and criteria"
|
|
588
|
-
}
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
### Find Pages Modified Today
|
|
592
|
-
|
|
593
|
-
Find all pages that have been modified since midnight today:
|
|
594
|
-
|
|
595
|
-
```typescript
|
|
596
|
-
use_mcp_tool roam-research roam_find_pages_modified_today {}
|
|
597
|
-
```
|
|
598
|
-
|
|
599
|
-
Features:
|
|
600
|
-
|
|
601
|
-
- Tracks all modifications made to pages since midnight
|
|
602
|
-
- Detects changes at any level in the block hierarchy
|
|
603
|
-
- Returns unique list of modified page titles
|
|
604
|
-
- Includes count of modified pages
|
|
605
|
-
- No parameters required
|
|
606
|
-
|
|
607
|
-
Returns:
|
|
608
|
-
|
|
609
|
-
```json
|
|
610
|
-
{
|
|
611
|
-
"success": true,
|
|
612
|
-
"pages": ["Page 1", "Page 2"],
|
|
613
|
-
"message": "Found 2 page(s) modified today"
|
|
614
|
-
}
|
|
615
|
-
```
|
|
616
|
-
|
|
617
|
-
### Execute Datomic Queries
|
|
618
|
-
|
|
619
|
-
Execute custom Datalog queries on your Roam graph for advanced data retrieval and analysis:
|
|
620
|
-
|
|
621
|
-
```typescript
|
|
622
|
-
use_mcp_tool roam-research roam_datomic_query {
|
|
623
|
-
"query": "[:find (count ?p)\n :where [?p :node/title]]",
|
|
624
|
-
"inputs": []
|
|
625
|
-
}
|
|
626
|
-
```
|
|
627
|
-
|
|
628
|
-
Features:
|
|
629
|
-
|
|
630
|
-
- Direct access to Roam's query engine
|
|
631
|
-
- Support for all Datalog query features:
|
|
632
|
-
- Complex pattern matching
|
|
633
|
-
- Aggregation functions (count, sum, max, min, avg, distinct)
|
|
634
|
-
- String operations (includes?, starts-with?, ends-with?)
|
|
635
|
-
- Logical operations (<, >, <=, >=, =, not=)
|
|
636
|
-
- Rules for recursive queries
|
|
637
|
-
- Case-sensitive and case-insensitive search capabilities
|
|
638
|
-
- Efficient querying across the entire graph
|
|
639
|
-
|
|
640
|
-
Parameters:
|
|
641
|
-
|
|
642
|
-
- `query`: The Datalog query to execute (required)
|
|
643
|
-
- `inputs`: Optional array of input parameters for the query
|
|
644
|
-
|
|
645
|
-
Returns:
|
|
646
|
-
|
|
647
|
-
```json
|
|
648
|
-
{
|
|
649
|
-
"success": true,
|
|
650
|
-
"matches": [
|
|
651
|
-
{
|
|
652
|
-
"content": "[result data]",
|
|
653
|
-
"block_uid": "",
|
|
654
|
-
"page_title": ""
|
|
655
|
-
}
|
|
656
|
-
],
|
|
657
|
-
"message": "Query executed successfully. Found N results."
|
|
658
|
-
}
|
|
659
|
-
```
|
|
660
|
-
|
|
661
|
-
Example Queries:
|
|
662
|
-
|
|
663
|
-
1. Count all pages:
|
|
664
|
-
|
|
665
|
-
```clojure
|
|
666
|
-
[:find (count ?p)
|
|
667
|
-
:where [?p :node/title]]
|
|
668
|
-
```
|
|
669
|
-
|
|
670
|
-
2. Case-insensitive text search:
|
|
671
|
-
|
|
672
|
-
```clojure
|
|
673
|
-
[:find ?string ?title
|
|
674
|
-
:where
|
|
675
|
-
[?b :block/string ?string]
|
|
676
|
-
[(clojure.string/lower-case ?string) ?lower]
|
|
677
|
-
[(clojure.string/includes? ?lower "search term")]
|
|
678
|
-
[?b :block/page ?p]
|
|
679
|
-
[?p :node/title ?title]]
|
|
680
|
-
```
|
|
681
|
-
|
|
682
|
-
3. Find blocks modified after a date:
|
|
683
|
-
|
|
684
|
-
```clojure
|
|
685
|
-
[:find ?block_ref ?string
|
|
686
|
-
:in $ ?start_of_day
|
|
687
|
-
:where
|
|
688
|
-
[?b :edit/time ?time]
|
|
689
|
-
[(> ?time ?start_of_day)]
|
|
690
|
-
[?b :block/uid ?block_ref]
|
|
691
|
-
[?b :block/string ?string]]
|
|
692
|
-
```
|
|
693
|
-
|
|
694
|
-
See Roam_Research_Datalog_Cheatsheet.md for more query examples and syntax documentation.
|
|
695
|
-
|
|
696
|
-
### Search Block Hierarchy
|
|
697
|
-
|
|
698
|
-
Navigate and search through block parent-child relationships:
|
|
699
|
-
|
|
700
|
-
```typescript
|
|
701
|
-
use_mcp_tool roam-research roam_search_hierarchy {
|
|
702
|
-
"parent_uid": "optional-parent-block-uid",
|
|
703
|
-
"child_uid": "optional-child-block-uid",
|
|
704
|
-
"page_title_uid": "optional-page-title-or-uid",
|
|
705
|
-
"max_depth": 3
|
|
706
|
-
}
|
|
707
|
-
```
|
|
708
|
-
|
|
709
|
-
Features:
|
|
710
|
-
|
|
711
|
-
- Search up or down the block hierarchy
|
|
712
|
-
- Find children of a specific block
|
|
713
|
-
- Find parents of a specific block
|
|
714
|
-
- Configure search depth (1-10 levels)
|
|
715
|
-
- Optional page scope filtering
|
|
716
|
-
- Includes depth information for each result
|
|
717
|
-
|
|
718
|
-
Parameters:
|
|
719
|
-
|
|
720
|
-
- `parent_uid`: UID of the block to find children of (required if searching down)
|
|
721
|
-
- `child_uid`: UID of the block to find parents of (required if searching up)
|
|
722
|
-
- `page_title_uid`: Title or UID of the page to search in (optional)
|
|
723
|
-
- `max_depth`: How many levels deep to search (optional, default: 1, max: 10)
|
|
724
|
-
|
|
725
|
-
Returns:
|
|
726
|
-
|
|
727
|
-
```json
|
|
728
|
-
{
|
|
729
|
-
"success": true,
|
|
730
|
-
"matches": [
|
|
731
|
-
{
|
|
732
|
-
"block_uid": "related-block-uid",
|
|
733
|
-
"content": "Block content",
|
|
734
|
-
"depth": 2,
|
|
735
|
-
"page_title": "Page containing block"
|
|
736
|
-
}
|
|
737
|
-
],
|
|
738
|
-
"message": "Found N block(s) as children/parents..."
|
|
739
|
-
}
|
|
740
|
-
```
|
|
741
|
-
|
|
742
180
|
## Error Handling
|
|
743
181
|
|
|
744
182
|
The server provides comprehensive error handling for common scenarios:
|
|
@@ -41,4 +41,6 @@ if (!API_TOKEN || !GRAPH_NAME) {
|
|
|
41
41
|
' ROAM_API_TOKEN=your-api-token\n' +
|
|
42
42
|
' ROAM_GRAPH_NAME=your-graph-name');
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
const HTTP_STREAM_PORT = process.env.HTTP_STREAM_PORT || '8088'; // Default to 8080
|
|
45
|
+
const SSE_PORT = process.env.SSE_PORT || '8087'; // Default to 8087
|
|
46
|
+
export { API_TOKEN, GRAPH_NAME, HTTP_STREAM_PORT, SSE_PORT };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
2
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
4
|
+
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
3
5
|
import { CallToolRequestSchema, ErrorCode, ListToolsRequestSchema, McpError, } from '@modelcontextprotocol/sdk/types.js';
|
|
4
6
|
import { initializeGraph } from '@roam-research/roam-api-sdk';
|
|
5
|
-
import { API_TOKEN, GRAPH_NAME } from '../config/environment.js';
|
|
7
|
+
import { API_TOKEN, GRAPH_NAME, HTTP_STREAM_PORT, SSE_PORT } from '../config/environment.js';
|
|
6
8
|
import { toolSchemas } from '../tools/schemas.js';
|
|
7
9
|
import { ToolHandlers } from '../tools/tool-handlers.js';
|
|
8
10
|
import { readFileSync } from 'node:fs';
|
|
9
11
|
import { join, dirname } from 'node:path';
|
|
12
|
+
import { createServer } from 'node:http';
|
|
10
13
|
import { fileURLToPath } from 'node:url';
|
|
11
14
|
const __filename = fileURLToPath(import.meta.url);
|
|
12
15
|
const __dirname = dirname(__filename);
|
|
@@ -37,38 +40,15 @@ export class RoamServer {
|
|
|
37
40
|
if (Object.keys(toolSchemas).length === 0) {
|
|
38
41
|
throw new McpError(ErrorCode.InternalError, 'No tool schemas defined in src/tools/schemas.ts');
|
|
39
42
|
}
|
|
40
|
-
this.server = new Server({
|
|
41
|
-
name: 'roam-research',
|
|
42
|
-
version: serverVersion, // Use the version from package.json
|
|
43
|
-
}, {
|
|
44
|
-
capabilities: {
|
|
45
|
-
tools: {
|
|
46
|
-
...Object.fromEntries(Object.keys(toolSchemas).map((toolName) => [toolName, {}])),
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
this.setupRequestHandlers();
|
|
51
|
-
// Error handling
|
|
52
|
-
this.server.onerror = (error) => {
|
|
53
|
-
// Re-throw as McpError to be caught by the MCP client
|
|
54
|
-
if (error instanceof McpError) {
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
58
|
-
throw new McpError(ErrorCode.InternalError, `MCP server internal error: ${errorMessage}`);
|
|
59
|
-
};
|
|
60
|
-
process.on('SIGINT', async () => {
|
|
61
|
-
await this.server.close();
|
|
62
|
-
process.exit(0);
|
|
63
|
-
});
|
|
64
43
|
}
|
|
65
|
-
|
|
44
|
+
// Refactored to accept a Server instance
|
|
45
|
+
setupRequestHandlers(mcpServer) {
|
|
66
46
|
// List available tools
|
|
67
|
-
|
|
47
|
+
mcpServer.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
68
48
|
tools: Object.values(toolSchemas),
|
|
69
49
|
}));
|
|
70
50
|
// Handle tool calls
|
|
71
|
-
|
|
51
|
+
mcpServer.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
72
52
|
try {
|
|
73
53
|
switch (request.params.name) {
|
|
74
54
|
case 'roam_remember': {
|
|
@@ -236,8 +216,111 @@ export class RoamServer {
|
|
|
236
216
|
}
|
|
237
217
|
async run() {
|
|
238
218
|
try {
|
|
239
|
-
const
|
|
240
|
-
|
|
219
|
+
const stdioMcpServer = new Server({
|
|
220
|
+
name: 'roam-research',
|
|
221
|
+
version: serverVersion,
|
|
222
|
+
}, {
|
|
223
|
+
capabilities: {
|
|
224
|
+
tools: {
|
|
225
|
+
...Object.fromEntries(Object.keys(toolSchemas).map((toolName) => [toolName, {}])),
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
this.setupRequestHandlers(stdioMcpServer);
|
|
230
|
+
const stdioTransport = new StdioServerTransport();
|
|
231
|
+
await stdioMcpServer.connect(stdioTransport);
|
|
232
|
+
const httpMcpServer = new Server({
|
|
233
|
+
name: 'roam-research-http', // A distinct name for the HTTP server
|
|
234
|
+
version: serverVersion,
|
|
235
|
+
}, {
|
|
236
|
+
capabilities: {
|
|
237
|
+
tools: {
|
|
238
|
+
...Object.fromEntries(Object.keys(toolSchemas).map((toolName) => [toolName, {}])),
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
this.setupRequestHandlers(httpMcpServer);
|
|
243
|
+
const httpStreamTransport = new StreamableHTTPServerTransport({
|
|
244
|
+
sessionIdGenerator: () => Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15),
|
|
245
|
+
});
|
|
246
|
+
await httpMcpServer.connect(httpStreamTransport);
|
|
247
|
+
const httpServer = createServer(async (req, res) => {
|
|
248
|
+
try {
|
|
249
|
+
await httpStreamTransport.handleRequest(req, res);
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
// console.error('HTTP Stream Server error:', error);
|
|
253
|
+
if (!res.headersSent) {
|
|
254
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
255
|
+
res.end(JSON.stringify({ error: 'Internal Server Error' }));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
httpServer.listen(parseInt(HTTP_STREAM_PORT), () => {
|
|
260
|
+
// console.log(`MCP Roam Research server running HTTP Stream on port ${HTTP_STREAM_PORT}`);
|
|
261
|
+
});
|
|
262
|
+
// SSE Server setup
|
|
263
|
+
const sseMcpServer = new Server({
|
|
264
|
+
name: 'roam-research-sse', // Distinct name for SSE server
|
|
265
|
+
version: serverVersion,
|
|
266
|
+
}, {
|
|
267
|
+
capabilities: {
|
|
268
|
+
tools: {
|
|
269
|
+
...Object.fromEntries(Object.keys(toolSchemas).map((toolName) => [toolName, {}])),
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
this.setupRequestHandlers(sseMcpServer);
|
|
274
|
+
const sseHttpServer = createServer(async (req, res) => {
|
|
275
|
+
const parseBody = (request) => {
|
|
276
|
+
return new Promise((resolve, reject) => {
|
|
277
|
+
let body = '';
|
|
278
|
+
request.on('data', (chunk) => {
|
|
279
|
+
body += chunk.toString();
|
|
280
|
+
});
|
|
281
|
+
request.on('end', () => {
|
|
282
|
+
try {
|
|
283
|
+
resolve(body ? JSON.parse(body) : {});
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
reject(error);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
request.on('error', reject);
|
|
290
|
+
});
|
|
291
|
+
};
|
|
292
|
+
try {
|
|
293
|
+
if (req.url === '/sse') {
|
|
294
|
+
const sseTransport = new SSEServerTransport('/sse', res);
|
|
295
|
+
await sseMcpServer.connect(sseTransport);
|
|
296
|
+
if (req.method === 'GET') {
|
|
297
|
+
await sseTransport.start();
|
|
298
|
+
}
|
|
299
|
+
else if (req.method === 'POST') {
|
|
300
|
+
const parsedBody = await parseBody(req);
|
|
301
|
+
await sseTransport.handlePostMessage(req, res, parsedBody);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
res.writeHead(405, { 'Content-Type': 'text/plain' });
|
|
305
|
+
res.end('Method Not Allowed');
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
310
|
+
res.end('Not Found');
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
// console.error('SSE HTTP Server error:', error);
|
|
315
|
+
if (!res.headersSent) {
|
|
316
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
317
|
+
res.end(JSON.stringify({ error: 'Internal Server Error' }));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
sseHttpServer.listen(parseInt(SSE_PORT), () => {
|
|
322
|
+
// console.log(`MCP Roam Research server running SSE on port ${SSE_PORT}`);
|
|
323
|
+
});
|
|
241
324
|
}
|
|
242
325
|
catch (error) {
|
|
243
326
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "roam-research-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "A Model Context Protocol (MCP) server for Roam Research API integration",
|
|
5
5
|
"private": false,
|
|
6
6
|
"repository": {
|
|
@@ -29,13 +29,12 @@
|
|
|
29
29
|
],
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "tsc && chmod 755 build/index.js",
|
|
32
|
-
"prepare": "npm run build",
|
|
33
32
|
"watch": "tsc --watch",
|
|
34
33
|
"inspector": "npx @modelcontextprotocol/inspector build/index.js",
|
|
35
34
|
"start": "node build/index.js"
|
|
36
35
|
},
|
|
37
36
|
"dependencies": {
|
|
38
|
-
"@modelcontextprotocol/sdk": "0.
|
|
37
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
39
38
|
"@roam-research/roam-api-sdk": "^0.10.0",
|
|
40
39
|
"dotenv": "^16.4.7"
|
|
41
40
|
},
|