用于 Roam Research 图形集成的 MCP 服务器和 CLI 工具
I created this project to solve a personal problem: I wanted to manage my Roam Research graph directly from Claude Code (and other LLMs). As I built the Model Context Protocol (MCP) server to give AI agents access to my notes, I realized the underlying tools were powerful enough to stand on their own.
What started as an backend for AI agents evolved into a full-featured Standalone CLI. Now, you can use the same powerful API capabilities directly from your terminal—piping content into Roam, searching your graph, and managing tasks—without needing an LLM at all.
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.
In one line: a block containing a soft line break (Shift+Enter) now survives a page rewrite. Read a page, write it back, and nothing moves.
Until now, a multi-line block rendered as two physical lines, the second at column 0. That reset the parser's indentation baseline, so every block after it collapsed toward the root and roam_update_page_markdown dutifully generated the moves to make your real page match. Reading a page and writing back a revision, the documented purpose of the tool, was enough to trigger it. Callout bodies and fenced code blocks are exactly the blocks that carry soft breaks.
⏎. A page containing one gains a leading `` marker line; keep it if you write the markdown back. Pages with no multi-line block render byte-identical to 3.x, with no marker and no encoding.\n, which is also a common prefix in authored text: \nabla, \neq, C:\newdir. The sentinel needs no such rule, so all of those are written exactly as typed, everywhere.roam get piped into roam save --update leaves the page as it was.roam_fetch_page_full_view escapes soft breaks in referring blocks and breadcrumbs, not just the page's own content.MCP-Protocol-Version and Last-Event-ID, both of which a client must send after initialization. Non-browser clients were never affected.Why a major. Four read surfaces return different bytes for any page containing a multi-line block: roam_fetch_page_by_title (format: "markdown"), roam_fetch_page_full_view, roam_get_subpages, and roam get. If you use the server through an AI assistant, nothing is required of you. A script that parses markdown output of multi-line pages sees the new encoding. If you pinned roam-research-mcp@3, you keep 3.2.0's fixes and its documented multi-line limitation until you re-pin.
Full detail, including the corner cases and how each fix was verified against the prior state, is in the changelog.
Roam Research ships its own MCP server and CLI (@roam-research/roam-mcp). 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.
| This project | Official @roam-research/roam-mcp |
|
|---|---|---|
| Talks to | Roam's backend REST API (graph token + graph name) | Roam Desktop's local HTTP API |
| Needs Roam running | No — works headless | Yes, the desktop app must be open (it deep-links to launch it) |
| Where it can run | Anywhere: laptop, server, container, CI | The machine running Roam Desktop |
| Shared daemon | Yes — roam server runs one HTTP daemon for every client |
Per-client stdio |
| Multi-graph | ROAM_GRAPHS env var, with write_key protection for chosen graphs |
~/.roam-tools.json, one token per graph |
| Web-only graphs | Works | Desktop only |
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.
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.
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.
The two servers share conventions on purpose, so running both costs you nothing:
[[roam/agent guidelines]] — both read the same page for your conventions. Write them once; both honour them. See Agent guidelines.#.rm-hide / #.rm-private — both withhold tagged blocks from AI-facing content. Tag once, hidden from both. See Hiding content from the AI.roamThe 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.
…Available Commands: get, search, save, refs, update, batch, rename, status, server.
Run roam --help for details on any command.
npm install -g roam-research-mcp
# The 'roam' command is now available globallyThe MCP server exposes these tools to AI assistants (like Claude), enabling them to read, write, and organize your Roam graph intelligently.
Multi-Graph Support: All tools accept optional
graphandwrite_keyparameters. Usegraphto target a specific graph from yourROAM_GRAPHSconfig, andwrite_keyfor write operations on protected graphs.
| Tool Name | Description |
|---|---|
roam_fetch_page_by_title |
Fetch page content by title. |
roam_fetch_page_full_view |
Fetch a page's content plus all linked references with breadcrumb context and children. |
roam_fetch_block |
Fetch a block by UID with optional children (depth) and/or ancestors (up to page root). |
roam_create_page |
Create new pages, optionally with mixed text and table content. |
roam_update_page_markdown |
Update a page using smart diff (preserves block UIDs). |
roam_get_subpages |
List sub-pages under a namespace prefix (e.g. "Project/") with optional tag filter. |
roam_search_by_text |
Full-text search across the graph or within specific pages. Supports namespace prefix search for page titles. |
roam_search_block_refs |
Find blocks that reference a page, tag, or block UID. |
roam_search_by_status |
Find TODO or DONE items. |
roam_search_for_tag |
Find blocks containing specific tags (supports exclusion). |
roam_search_by_date |
Find blocks/pages by creation or modification date. |
roam_find_pages_modified_today |
List pages modified since midnight. |
roam_add_todo |
Add TODO items to today's daily page. |
roam_create_table |
Create properly formatted Roam tables. |
roam_create_outline |
Create hierarchical outlines. |
roam_process_batch_actions |
Execute multiple low-level actions (create, move, update, delete) in one batch. |
roam_move_block |
Move a block to a new parent or position. |
roam_remember / roam_recall |
specialized tools for AI memory management within Roam. |
roam_datomic_query |
Execute raw Datalog queries for advanced filtering. |
roam_markdown_cheatsheet |
Retrieve the Roam-flavored markdown reference. |
roam_get_guidelines |
Retrieve this graph's user-defined agent conventions. |
The ten write tools declare an outputSchema and return structuredContent — a validated object — alongside the usual text. A client can read page_uid, uid_map or success directly instead of hunting for JSON inside a string, which makes chaining calls more reliable:
// roam_process_batch_actions
{ "success": true, "uid_map": { "parent1": "Xk7mN2pQ9" },
"validation_passed": true, "actions_attempted": 4 }Three things worth knowing:
structuredContent behaves exactly as before.Upgrading to 4.0.0: markdown reads of a page containing a soft line break (Shift+Enter) now render that break as
⏎and carry a leading `` marker, so the page survives a write-back intact. Pages without multi-line blocks are byte-identical to 3.x. AI-assistant users need do nothing; scripts parsing markdown output of multi-line pages see the new encoding. See the changelog.
Upgrading from 2.x: three write-result fields were renamed —
uid→page_uid(roam_create_page),created_uids→created_blocks(roam_create_outline,roam_import_markdown) andpreservedUids→preserved_uids(roam_update_page_markdown). This only affects code that reads those names; if you use the server through an AI assistant, nothing changes. See the changelog for why.
roam_get_guidelines reads a page inside the graph — [[roam/agent guidelines]] by default — holding your own conventions: how you tag, how you namespace pages, what an agent should never do. Roam's official MCP server reads the same page title, so one page serves both.
This is distinct from CUSTOM_INSTRUCTIONS_PATH, and the two compose:
CUSTOM_INSTRUCTIONS_PATH |
[[roam/agent guidelines]] |
|
|---|---|---|
| Lives in | a file on disk | a page in the graph |
| Scope | server-wide, all graphs | per-graph |
| To change it | edit the file, restart the server | edit the page |
| Answers | how to write Roam markdown | how *thi |
暂无开放 Issues,或尚未同步最近议题。