roam-research-mcp 2.23.0 → 2.25.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 CHANGED
@@ -18,6 +18,34 @@ What started as an backend for AI agents evolved into a full-featured **Standalo
18
18
 
19
19
  Whether you want to give Claude superpowers over your knowledge base or just want a robust CLI for your own scripts, this project has you covered.
20
20
 
21
+ ![Before and after: copy-pasting notes into Roam by hand, versus Claude and your terminal reading and writing the graph directly — install with npm i -g roam-research-mcp, then `roam save "idea"` or pipe with `echo "Buy milk" | roam save --todo`](./roam-research-mcp-sketchnote.png)
22
+
23
+ ## How this differs from Roam's official MCP server
24
+
25
+ Roam Research ships its own MCP server and CLI ([`@roam-research/roam-mcp`](https://github.com/Roam-Research/roam-tools)). It is a good tool, and this project is not trying to replace it. **They talk to two different Roam APIs, which is the difference everything else follows from.**
26
+
27
+ | | **This project** | **Official `@roam-research/roam-mcp`** |
28
+ | ------------------ | ---------------------------------------------------------------------- | --------------------------------------------------------------- |
29
+ | Talks to | Roam's **backend REST API** (graph token + graph name) | Roam **Desktop's local HTTP API** |
30
+ | Needs Roam running | No — works headless | Yes, the desktop app must be open (it deep-links to launch it) |
31
+ | Where it can run | Anywhere: laptop, server, container, CI | The machine running Roam Desktop |
32
+ | Shared daemon | Yes — `roam server` runs one HTTP daemon for every client | Per-client stdio |
33
+ | Multi-graph | `ROAM_GRAPHS` env var, with `write_key` protection for chosen graphs | `~/.roam-tools.json`, one token per graph |
34
+ | Web-only graphs | Works | Desktop only |
35
+
36
+ **Reach for the official server when** you want Roam's own supported path, or you need things only the running app can do: controlling the Desktop UI (open a page, read the current selection, drive the sidebar), semantic/embeddings search, link suggestions, file upload, comments, or invoking tools that Roam extensions register.
37
+
38
+ **Reach for this one when** Roam isn't running or isn't installed — a server, a container, a cron job, a CI step. Or when you want the extras this project has grown: a full standalone CLI with stdin piping, a shared HTTP daemon with optional bearer auth, smart page diffing that preserves block UIDs (and therefore your block references), batch operations with UID placeholders for building nested structures in one call, and agent memory tools.
39
+
40
+ One deliberate omission: **there is no page-delete tool here.** Roam has no undo that can reverse a bulk API deletion. The official server does offer `delete_page`; this project takes the more conservative line.
41
+
42
+ ### They interoperate
43
+
44
+ The two servers share conventions on purpose, so running both costs you nothing:
45
+
46
+ - **`[[roam/agent guidelines]]`** — both read the same page for your conventions. Write them once; both honour them. See [Agent guidelines](#agent-guidelines-per-graph).
47
+ - **`#.rm-hide` / `#.rm-private`** — both withhold tagged blocks from AI-facing content. Tag once, hidden from both. See [Hiding content from the AI](#hiding-content-from-the-ai).
48
+
21
49
  ## Standalone CLI: `roam`
22
50
 
23
51
  The `roam` CLI lets you interact with your graph directly from the terminal. It supports **standard input (stdin) piping** for all content creation and retrieval commands, making it perfect for automation workflows.
@@ -133,14 +161,24 @@ This is distinct from `CUSTOM_INSTRUCTIONS_PATH`, and the two compose:
133
161
  | To change it | edit the file, restart the server | edit the page |
134
162
  | Answers | how to write Roam markdown | how *this user* wants *this graph* handled |
135
163
 
136
- Configure per graph, or disable with `false`:
164
+ **Just create the page.** With no configuration at all, `roam_get_guidelines` reads `[[roam/agent guidelines]]` — the same title Roam's own server reads, so writing it once makes both honour it. Creating a page with that exact namespaced title is the opt-in; nothing is read from the graph unless an agent explicitly calls the tool.
165
+
166
+ If the page doesn't exist, the tool returns `exists: false` rather than failing, so it is always safe to call.
167
+
168
+ Each graph can point at a different page, or turn it off:
137
169
 
138
170
  ```bash
139
- ROAM_GRAPHS='{"personal": {"token": "...", "graph": "...", "guidelinesPage": "roam/agent guidelines"}, "work": {"token": "...", "graph": "...", "guidelinesPage": false}}'
140
- ROAM_GUIDELINES_PAGE='roam/agent guidelines' # fallback when a graph sets none
171
+ ROAM_GRAPHS='{
172
+ "personal": {"token": "...", "graph": "..."},
173
+ "work": {"token": "...", "graph": "...", "guidelinesPage": "work/agent rules"},
174
+ "private": {"token": "...", "graph": "...", "guidelinesPage": false}
175
+ }'
176
+ ROAM_GUIDELINES_PAGE='team/agent guidelines' # change the default for every graph
141
177
  ```
142
178
 
143
- If no such page exists the tool returns `exists: false` rather than failing, so it is safe to call unconditionally. Results are cached for 30 seconds — an edit to the page takes effect without a restart. A starter template lives at [`.roam/agent-guidelines.template.md`](.roam/agent-guidelines.template.md).
179
+ Resolution order is **per-graph `guidelinesPage` → `ROAM_GUIDELINES_PAGE` → `roam/agent guidelines`**. Above: `personal` uses the env override, `work` uses its own page, and `private` has guidelines off entirely. **Only an explicit `false` disables it** — an unset value never does.
180
+
181
+ Results are cached for 30 seconds — an edit to the page takes effect without a restart. A starter template lives at [`.roam/agent-guidelines.template.md`](.roam/agent-guidelines.template.md).
144
182
 
145
183
  Note that guidelines are read through the normal page path, so blocks tagged `#.rm-hide` / `#.rm-private` are withheld from them too — see below.
146
184
 
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import { initializeGraph } from '@roam-research/roam-api-sdk';
11
11
  import { RoamError } from '../shared/errors.js';
12
+ import { DEFAULT_GUIDELINES_PAGE } from '../tools/operations/guidelines.js';
12
13
  /** List of tool names that perform write operations */
13
14
  export const WRITE_OPERATIONS = [
14
15
  'roam_create_page',
@@ -70,8 +71,21 @@ export class GraphRegistry {
70
71
  return config?.memoriesTag ?? process.env.ROAM_MEMORIES_TAG ?? 'Memories';
71
72
  }
72
73
  /**
73
- * Page holding a graph's agent conventions, or null when disabled.
74
- * Same precedence as memoriesTag: per-graph config > env var > default.
74
+ * Page holding a graph's agent conventions, or null when explicitly disabled.
75
+ *
76
+ * Precedence: per-graph config > ROAM_GUIDELINES_PAGE env var >
77
+ * "roam/agent guidelines" (the shared convention).
78
+ *
79
+ * Reading the conventional title by default is deliberate. It is the same
80
+ * page Roam's own MCP server reads unconditionally, so writing it once makes
81
+ * both servers honour it — which is the entire point of a convention, and it
82
+ * stops working the moment it needs private configuration. Creating a page
83
+ * with that exact namespaced title IS the opt-in; nobody makes one by
84
+ * accident. And nothing here reads the graph unprompted: the lookup only
85
+ * happens when an agent explicitly calls roam_get_guidelines, so the tool
86
+ * call is already the consent.
87
+ *
88
+ * Set `guidelinesPage: false` to turn it off for a graph.
75
89
  */
76
90
  getGuidelinesPage(key) {
77
91
  const resolvedKey = key ?? this.defaultKey;
@@ -79,7 +93,7 @@ export class GraphRegistry {
79
93
  if (config?.guidelinesPage === false) {
80
94
  return null;
81
95
  }
82
- return config?.guidelinesPage ?? process.env.ROAM_GUIDELINES_PAGE ?? 'roam/agent guidelines';
96
+ return config?.guidelinesPage ?? process.env.ROAM_GUIDELINES_PAGE ?? DEFAULT_GUIDELINES_PAGE;
83
97
  }
84
98
  /**
85
99
  * Get an initialized Graph instance, creating it lazily if needed
@@ -67,11 +67,25 @@ describe('GraphRegistry', () => {
67
67
  });
68
68
  describe('getGuidelinesPage', () => {
69
69
  const make = (configs, def = 'personal') => new GraphRegistry(configs, def);
70
- it('defaults to the shared roam/agent guidelines convention', () => {
70
+ it('reads the shared convention when a graph configures nothing', () => {
71
+ // Creating a page with that exact namespaced title IS the opt-in, and it is
72
+ // the same title Roam's own server reads — so one page serves both.
71
73
  delete process.env.ROAM_GUIDELINES_PAGE;
72
74
  const r = make({ personal: { token: 't', graph: 'g' } });
73
75
  expect(r.getGuidelinesPage('personal')).toBe('roam/agent guidelines');
74
76
  });
77
+ it('requires an explicit false to turn off — nothing else disables it', () => {
78
+ delete process.env.ROAM_GUIDELINES_PAGE;
79
+ const off = make({ personal: { token: 't', graph: 'g', guidelinesPage: false } });
80
+ expect(off.getGuidelinesPage('personal')).toBeNull();
81
+ });
82
+ it('false on one graph beats the env fallback', () => {
83
+ process.env.ROAM_GUIDELINES_PAGE = 'env/page';
84
+ const r = make({ personal: { token: 't', graph: 'p' }, work: { token: 't', graph: 'g', guidelinesPage: false } });
85
+ expect(r.getGuidelinesPage('work')).toBeNull();
86
+ expect(r.getGuidelinesPage('personal')).toBe('env/page');
87
+ delete process.env.ROAM_GUIDELINES_PAGE;
88
+ });
75
89
  it('prefers per-graph config over the env var', () => {
76
90
  process.env.ROAM_GUIDELINES_PAGE = 'env/page';
77
91
  const r = make({ work: { token: 't', graph: 'g', guidelinesPage: 'work/rules' } }, 'work');
@@ -2,6 +2,7 @@ import { q } from '@roam-research/roam-api-sdk';
2
2
  import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
3
3
  import { resolveBlockRefs } from '../helpers/refs.js';
4
4
  import { fetchChildrenByDepth } from '../helpers/fetch-children.js';
5
+ import { pruneHiddenBlocks, isHiddenBlockString } from '../helpers/hidden.js';
5
6
  export class BlockRetrievalOperations {
6
7
  constructor(graph) {
7
8
  this.graph = graph;
@@ -24,12 +25,17 @@ export class BlockRetrievalOperations {
24
25
  }
25
26
  const [rootString, rootOrder, rootHeading] = rootBlockResults[0];
26
27
  const childrenMap = await fetchChildrenByDepth(this.graph, [block_uid], depth);
28
+ // A block the user tagged #.rm-hide / #.rm-private is withheld outright,
29
+ // as is anything nested under it — same rule as the page read paths.
30
+ if (isHiddenBlockString(rootString)) {
31
+ return null;
32
+ }
27
33
  const rootBlock = {
28
34
  uid: block_uid,
29
35
  string: rootString,
30
36
  order: rootOrder,
31
37
  heading: rootHeading || undefined,
32
- children: childrenMap[block_uid] || [],
38
+ children: pruneHiddenBlocks(childrenMap[block_uid] || []),
33
39
  };
34
40
  // Fetch ancestors if requested
35
41
  if (include_ancestors) {
@@ -3,6 +3,7 @@ import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
3
3
  import { getPageUid as getPageUidHelper } from '../helpers/page-resolution.js';
4
4
  import { resolveRefs } from '../helpers/refs.js';
5
5
  import { fetchChildrenByDepth } from '../helpers/fetch-children.js';
6
+ import { collectHiddenUids, pruneHiddenBlocks, isHiddenBlockString } from '../helpers/hidden.js';
6
7
  export class FullPageViewOperations {
7
8
  constructor(graph, pageOps) {
8
9
  this.graph = graph;
@@ -21,12 +22,20 @@ export class FullPageViewOperations {
21
22
  const refResults = await this.fetchReferringBlocks(title);
22
23
  // Deduplicate by block_uid, then cap at max_references
23
24
  const seenUids = new Set();
24
- const allUniqueRefs = refResults.filter(r => {
25
+ const dedupedRefs = refResults.filter(r => {
25
26
  if (seenUids.has(r.block_uid))
26
27
  return false;
27
28
  seenUids.add(r.block_uid);
28
29
  return true;
29
30
  });
31
+ // Backlinks come from other pages, so the page's own prune (pageBlocks
32
+ // above, already filtered by fetchPageByUid) does not cover them. A
33
+ // referring block may itself be tagged, or sit under a tagged parent
34
+ // elsewhere — hence the UID closure rather than a text check alone.
35
+ // Filtered BEFORE the max_references cap so truncation counts what the
36
+ // caller can actually see.
37
+ const hiddenUids = await collectHiddenUids(this.graph);
38
+ const allUniqueRefs = dedupedRefs.filter(r => !hiddenUids.has(r.block_uid) && !isHiddenBlockString(r.block_str));
30
39
  const truncated = allUniqueRefs.length > max_references;
31
40
  const uniqueRefs = truncated ? allUniqueRefs.slice(0, max_references) : allUniqueRefs;
32
41
  const refBlockUids = uniqueRefs.map(r => r.block_uid);
@@ -89,7 +98,8 @@ export class FullPageViewOperations {
89
98
  uid: ref.block_uid,
90
99
  string: resolvedRefStrings.get(ref.block_uid) || ref.block_str,
91
100
  order: 0,
92
- children: childrenMap[ref.block_uid] || []
101
+ // Children of a visible backlink can still contain tagged subtrees.
102
+ children: pruneHiddenBlocks(childrenMap[ref.block_uid] || [])
93
103
  };
94
104
  groupMap.get(key).references.push({
95
105
  breadcrumbs: breadcrumbsMap[ref.block_uid] || [],
@@ -1,18 +1,20 @@
1
1
  /**
2
2
  * Per-graph agent guidelines.
3
3
  *
4
- * A page in the graph — `[[roam/agent guidelines]]` by default — holding the
5
- * user's own conventions: how they tag, how they name pages, what to never do.
4
+ * A page in the graph — conventionally `[[roam/agent guidelines]]` — holding
5
+ * the user's own conventions: how they tag, how they name pages, what to never do.
6
6
  * This is the same page Roam's official MCP server reads, so a user writes their
7
7
  * conventions once and both servers honour them.
8
8
  *
9
9
  * Distinct from the markdown cheatsheet, which is Roam *syntax* plus this
10
10
  * server's mechanics and lives in a file. Guidelines are per-graph, live-edited
11
11
  * from inside Roam, and answer "how does this user want their graph handled".
12
+ *
13
+ * Read by default; set `guidelinesPage: false` on a graph to disable it there.
12
14
  */
13
15
  import { PageOperations } from './pages.js';
14
16
  import { formatRoamDate } from '../../utils/helpers.js';
15
- /** Default page title, matching Roam's own convention. */
17
+ /** The shared convention, read by default and by Roam's own MCP server. */
16
18
  export const DEFAULT_GUIDELINES_PAGE = 'roam/agent guidelines';
17
19
  /**
18
20
  * Short TTL: the point of a page over a config file is that an edit takes
@@ -14,7 +14,7 @@ describe('GuidelinesOperations', () => {
14
14
  it('returns the page content when the page exists', async () => {
15
15
  getPageUid.mockResolvedValue('abc123456');
16
16
  fetchPageByTitle.mockResolvedValue('- H2: Tagging Philosophy');
17
- const res = await new GuidelinesOperations(newGraph()).getGuidelines();
17
+ const res = await new GuidelinesOperations(newGraph(), DEFAULT_GUIDELINES_PAGE).getGuidelines();
18
18
  expect(res.exists).toBe(true);
19
19
  expect(res.page).toBe(DEFAULT_GUIDELINES_PAGE);
20
20
  expect(res.guidelines).toBe('- H2: Tagging Philosophy');
@@ -22,7 +22,7 @@ describe('GuidelinesOperations', () => {
22
22
  });
23
23
  it('reports absence rather than failing when no page has been created', async () => {
24
24
  getPageUid.mockResolvedValue(null);
25
- const res = await new GuidelinesOperations(newGraph()).getGuidelines();
25
+ const res = await new GuidelinesOperations(newGraph(), DEFAULT_GUIDELINES_PAGE).getGuidelines();
26
26
  expect(res.exists).toBe(false);
27
27
  expect(res.guidelines).toBeNull();
28
28
  expect(res.nextSteps).toMatch(/no user conventions/i);
@@ -35,6 +35,13 @@ describe('GuidelinesOperations', () => {
35
35
  expect(res.page).toBe('work/agent rules');
36
36
  expect(getPageUid).toHaveBeenCalledWith('work/agent rules');
37
37
  });
38
+ it('defaults to the shared convention with no page configured', async () => {
39
+ getPageUid.mockResolvedValue('abc123456');
40
+ fetchPageByTitle.mockResolvedValue('rules');
41
+ const res = await new GuidelinesOperations(newGraph()).getGuidelines();
42
+ expect(res.page).toBe(DEFAULT_GUIDELINES_PAGE);
43
+ expect(getPageUid).toHaveBeenCalledWith(DEFAULT_GUIDELINES_PAGE);
44
+ });
38
45
  it('reports guidelines as disabled without touching the graph', async () => {
39
46
  const res = await new GuidelinesOperations(newGraph(), null).getGuidelines();
40
47
  expect(res.page).toBeNull();
@@ -44,27 +51,27 @@ describe('GuidelinesOperations', () => {
44
51
  });
45
52
  it('fails open — a lookup error never breaks the tool the agent wanted', async () => {
46
53
  getPageUid.mockRejectedValue(new Error('network down'));
47
- const res = await new GuidelinesOperations(newGraph()).getGuidelines();
54
+ const res = await new GuidelinesOperations(newGraph(), DEFAULT_GUIDELINES_PAGE).getGuidelines();
48
55
  expect(res.exists).toBe(false);
49
56
  expect(res.guidelines).toBeNull();
50
57
  expect(res.nextSteps).toMatch(/network down/);
51
58
  });
52
59
  it('always reports today in Roam ordinal date format', async () => {
53
60
  getPageUid.mockResolvedValue(null);
54
- const res = await new GuidelinesOperations(newGraph()).getGuidelines();
61
+ const res = await new GuidelinesOperations(newGraph(), DEFAULT_GUIDELINES_PAGE).getGuidelines();
55
62
  expect(res.todaysDailyNote).toMatch(/^[A-Z][a-z]+ \d{1,2}(st|nd|rd|th), \d{4}$/);
56
63
  });
57
64
  it('tells the agent not to re-orient, so it does not refetch every call', async () => {
58
65
  getPageUid.mockResolvedValue('abc123456');
59
66
  fetchPageByTitle.mockResolvedValue('rules');
60
- const res = await new GuidelinesOperations(newGraph()).getGuidelines();
67
+ const res = await new GuidelinesOperations(newGraph(), DEFAULT_GUIDELINES_PAGE).getGuidelines();
61
68
  expect(res.nextSteps).toMatch(/do not call this tool again/i);
62
69
  expect(res.nextSteps).toMatch(/reads as well as writes/i);
63
70
  });
64
71
  it('caches within the TTL so a burst of calls costs one fetch', async () => {
65
72
  getPageUid.mockResolvedValue('abc123456');
66
73
  fetchPageByTitle.mockResolvedValue('rules');
67
- const ops = new GuidelinesOperations(newGraph());
74
+ const ops = new GuidelinesOperations(newGraph(), DEFAULT_GUIDELINES_PAGE);
68
75
  await ops.getGuidelines();
69
76
  await ops.getGuidelines();
70
77
  await ops.getGuidelines();
@@ -73,7 +80,7 @@ describe('GuidelinesOperations', () => {
73
80
  it('refetches after the cache is cleared', async () => {
74
81
  getPageUid.mockResolvedValue('abc123456');
75
82
  fetchPageByTitle.mockResolvedValue('rules');
76
- const ops = new GuidelinesOperations(newGraph());
83
+ const ops = new GuidelinesOperations(newGraph(), DEFAULT_GUIDELINES_PAGE);
77
84
  await ops.getGuidelines();
78
85
  ops.clearCache();
79
86
  await ops.getGuidelines();
@@ -82,8 +89,8 @@ describe('GuidelinesOperations', () => {
82
89
  it('keeps separate graphs separate', async () => {
83
90
  getPageUid.mockResolvedValue('abc123456');
84
91
  fetchPageByTitle.mockResolvedValue('rules');
85
- await new GuidelinesOperations(newGraph()).getGuidelines();
86
- await new GuidelinesOperations(newGraph()).getGuidelines();
92
+ await new GuidelinesOperations(newGraph(), DEFAULT_GUIDELINES_PAGE).getGuidelines();
93
+ await new GuidelinesOperations(newGraph(), DEFAULT_GUIDELINES_PAGE).getGuidelines();
87
94
  expect(getPageUid).toHaveBeenCalledTimes(2);
88
95
  });
89
96
  });
@@ -1,6 +1,7 @@
1
1
  import { q } from '@roam-research/roam-api-sdk';
2
2
  import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
3
3
  import { generateBlockUid } from '../../markdown-utils.js';
4
+ import { collectHiddenUids, isHiddenBlockString } from '../helpers/hidden.js';
4
5
  import { ANCESTOR_RULE } from '../../search/ancestor-rule.js';
5
6
  import { sanitizeTagName } from '../../utils/helpers.js';
6
7
  import { resolveRefs } from '../helpers/refs.js';
@@ -92,17 +93,26 @@ export class MemoryOperations {
92
93
  .replace(/^\[\[/, '').replace(/\]\]$/, ''); // Remove [[ and ]]
93
94
  try {
94
95
  // Query to find all blocks on the page
95
- const pageQuery = `[:find ?string ?time
96
+ // ?uid is selected so hidden blocks can be filtered by the UID closure
97
+ // below — a text check alone would miss blocks nested under a tagged
98
+ // parent, which carry no tag of their own.
99
+ const pageQuery = `[:find ?string ?time ?uid
96
100
  :in $ % ?title
97
101
  :where
98
102
  [?page :node/title ?title]
99
103
  [?block :block/string ?string]
104
+ [?block :block/uid ?uid]
100
105
  [?block :create/time ?time]
101
106
  (ancestor ?block ?page)]`;
102
107
  // Execute query
103
108
  const pageResults = await q(this.graph, pageQuery, [ANCESTOR_RULE, tagText]);
109
+ // Withhold anything the user tagged #.rm-hide / #.rm-private. The tagged
110
+ // half of recall (searchForTag below) is already filtered by
111
+ // SearchOperations; this is the page half.
112
+ const hiddenUids = await collectHiddenUids(this.graph);
104
113
  // Process page blocks with sorting
105
114
  let pageMemories = pageResults
115
+ .filter(([content, , uid]) => !hiddenUids.has(uid) && !isHiddenBlockString(content))
106
116
  .sort(([_, aTime], [__, bTime]) => sort_by === 'newest' ? bTime - aTime : aTime - bTime)
107
117
  .map(([content]) => content);
108
118
  // Get tagged blocks from across the graph
@@ -501,10 +501,27 @@ export class PageOperations {
501
501
  });
502
502
  };
503
503
  sortBlocks(rootBlocks);
504
+ // Withhold #.rm-hide / #.rm-private subtrees before ANY format renders
505
+ // them. This function builds its own tree rather than reusing
506
+ // fetchPageByUid, so it needs its own prune — that duplication is exactly
507
+ // how this path shipped unfiltered the first time.
508
+ const visibleRoots = pruneHiddenBlocks(rootBlocks);
509
+ // Collect from the PRUNED tree, not by filtering allBlocks: pruning copies
510
+ // any node that has children, so the originals are no longer the objects
511
+ // rendered below, and the markdown branch mutates these in place.
512
+ const visibleBlocks = [];
513
+ const collectVisible = (bs) => {
514
+ for (const b of bs) {
515
+ visibleBlocks.push(b);
516
+ if (b.children.length > 0)
517
+ collectVisible(b.children);
518
+ }
519
+ };
520
+ collectVisible(visibleRoots);
504
521
  if (format === 'raw') {
505
522
  // Resolve structured references for raw JSON output
506
- await resolveBlockRefs(this.graph, allBlocks, 2);
507
- return JSON.stringify(rootBlocks);
523
+ await resolveBlockRefs(this.graph, visibleBlocks, 2);
524
+ return JSON.stringify(visibleRoots);
508
525
  }
509
526
  if (format === 'structure') {
510
527
  const flattenBlocks = (blocks, depth, parentUid) => {
@@ -532,7 +549,7 @@ export class PageOperations {
532
549
  }
533
550
  return result;
534
551
  };
535
- const structureBlocks = flattenBlocks(rootBlocks, 0, uid);
552
+ const structureBlocks = flattenBlocks(visibleRoots, 0, uid);
536
553
  return JSON.stringify({
537
554
  page_uid: uid,
538
555
  title: title,
@@ -541,7 +558,7 @@ export class PageOperations {
541
558
  });
542
559
  }
543
560
  // For markdown, resolve references inline
544
- await Promise.all(allBlocks.map(async (b) => {
561
+ await Promise.all(visibleBlocks.map(async (b) => {
545
562
  b.string = await resolveRefs(this.graph, b.string);
546
563
  }));
547
564
  // Convert to markdown with proper nesting
@@ -567,7 +584,7 @@ export class PageOperations {
567
584
  })
568
585
  .join('\n');
569
586
  };
570
- return `# ${title}\n\n${toMarkdown(rootBlocks)}`;
587
+ return `# ${title}\n\n${toMarkdown(visibleRoots)}`;
571
588
  }
572
589
  /**
573
590
  * Update an existing page with new markdown content using smart diff.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roam-research-mcp",
3
- "version": "2.23.0",
3
+ "version": "2.25.0",
4
4
  "description": "MCP server and CLI for Roam Research",
5
5
  "private": false,
6
6
  "repository": {