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)
You can install the package globally:
npm install -g roam-research-mcp
Or clone the repository and build from source:
git clone https://github.com/2b3pro/roam-research-mcp.git
cd roam-research-mcp
npm install
npm run build
The server provides powerful tools for interacting with Roam Research:
roam_fetch_page_by_title
: Fetch and read a page's content by title, recursively resolving block references up to 4 levels deeproam_create_page
: Create new pages with optional contentroam_create_block
: Create new blocks in a page (defaults to today's daily page)roam_import_markdown
: Import nested markdown content under specific blocksroam_add_todo
: Add multiple todo items to today's daily page with checkbox syntaxroam_create_outline
: Create hierarchical outlines with proper nesting and structureroam_search_block_refs
: Search for block references within pages or across the graphroam_search_hierarchy
: Navigate and search through block parent-child relationshipsroam_find_pages_modified_today
: Find all pages that have been modified since midnight todayroam_search_by_text
: Search for blocks containing specific text across all pages or within a specific pageroam_update_block
: Update block content with direct text or pattern-based transformationsroam_search_by_date
: Search for blocks and pages based on creation or modification datesroam_search_for_tag
: Search for blocks containing specific tags with optional filtering by nearby tagsroam_remember
: Store and categorize memories or information with automatic taggingroam_recall
: Recall memories of blocks marked with tag MEMORIES_TAG (see below) or blocks on page title of the same nameroam_datomic_query
: Execute custom Datalog queries on the Roam graph for advanced data retrieval and analysisCreate a Roam Research API token:
Configure the environment variables: You have two options for configuring the required environment variables:
Option 1: Using a .env file (Recommended for development)
Create a .env
file in the roam-research directory:
ROAM_API_TOKEN=your-api-token
ROAM_GRAPH_NAME=your-graph-name
MEMORIES_TAG='#[[LLM/Memories]]'
Option 2: Using MCP settings (Alternative method) Add the configuration to your MCP settings file:
~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
):~/Library/Application Support/Claude/claude_desktop_config.json
):{
"mcpServers": {
"roam-research": {
"command": "node",
"args": ["/path/to/roam-research-mcp/build/index.js"],
"env": {
"ROAM_API_TOKEN": "your-api-token",
"ROAM_GRAPH_NAME": "your-graph-name",
"MEMORIES_TAG": "#[[LLM/Memories]]"
}
}
}
}
Note: The server will first try to load from .env file, then fall back to environment variables from MCP settings.
Build the server (make sure you're in the root directory of the MCP):
cd roam-research-mcp
npm install
npm run build
Fetch and read a page's content with resolved block references:
use_mcp_tool roam-research roam_fetch_page_by_title {
"title": "Example Page"
}
Returns the page content as markdown with:
Create a new page with optional content:
use_mcp_tool roam-research roam_create_page {
"title": "New Page",
"content": "Initial content for the page"
}
Returns the created page's UID on success.
Add a new block to a page (defaults to today's daily page if neither page_uid nor title provided):
use_mcp_tool roam-research roam_create_block {
"content": "Block content",
"page_uid": "optional-target-page-uid",
"title": "optional-target-page-title"
}
You can specify either:
page_uid
: Direct reference to target pagetitle
: Name of target page (will be created if it doesn't exist)Returns:
{
"success": true,
"block_uid": "created-block-uid",
"parent_uid": "parent-page-uid"
}
Create a hierarchical outline with proper nesting and structure:
use_mcp_tool roam-research roam_create_outline {
"outline": [
{
"text": "I. Top Level",
"level": 1
},
{
"text": "A. Second Level",
"level": 2
},
{
"text": "1. Third Level",
"level": 3
}
],
"page_title_uid": "optional-target-page",
"block_text_uid": "optional-header-text"
}
Features:
Parameters:
outline
: Array of outline items, each with:
text
: Content of the outline item (required)level
: Nesting level (1-10, required)page_title_uid
: Target page title or UID (optional, defaults to today's page)block_text_uid
: Header text for the outline (optional)Returns:
{
"success": true,
"page_uid": "target-page-uid",
"parent_uid": "header-block-uid",
"created_uids": ["uid1", "uid2", ...]
}
Add one or more todo items to today's daily page:
use_mcp_tool roam-research roam_add_todo {
"todos": [
"First todo item",
"Second todo item",
"Third todo item"
]
}
Features:
{{TODO}} todo text
)Import nested markdown content under a specific block:
use_mcp_tool roam-research roam_import_markdown {
"content": "- Item 1\n - Subitem A\n - Subitem B\n- Item 2",
"page_uid": "optional-page-uid",
"page_title": "optional-page-title",
"parent_uid": "optional-parent-block-uid",
"parent_string": "optional-exact-block-content",
"order": "first"
}
Features:
{
"success": true,
"page_uid": "target-page-uid",
"parent_uid": "parent-block-uid",
"created_uids": ["uid1", "uid2", ...]
}
Parameters:
content
: Nested markdown content to importpage_uid
: UID of the page containing the parent blockpage_title
: Title of the page containing the parent block (ignored if page_uid provided)parent_uid
: UID of the parent block to add content underparent_string
: Exact string content of the parent block (must provide either page_uid or page_title)order
: Where to add the content ("first" or "last", defaults to "first")Search for block references within pages or across the entire graph:
use_mcp_tool roam-research roam_search_block_refs {
"block_uid": "optional-block-uid",
"page_title_uid": "optional-page-title-or-uid"
}
Features:
Parameters:
block_uid
: UID of the block to find references to (optional)page_title_uid
: Title or UID of the page to search in (optional)Returns:
{
"success": true,
"matches": [
{
"block_uid": "referenced-block-uid",
"content": "Block content with ((reference))",
"page_title": "Page containing reference"
}
],
"message": "Found N block(s) referencing..."
}
Search for blocks containing specific text across all pages or within a specific page:
use_mcp_tool roam-research roam_search_by_text {
"text": "search text",
"page_title_uid": "optional-page-title-or-uid",
"case_sensitive": true
}
Features:
Parameters:
text
: The text to search for (required)page_title_uid
: Title or UID of the page to search in (optional)case_sensitive
: Whether to perform a case-sensitive search (optional, default: true to match Roam's native behavior)Returns:
{
"success": true,
"matches": [
{
"block_uid": "matching-block-uid",
"content": "Block content containing search text",
"page_title": "Page containing block"
}
],
"message": "Found N block(s) containing \"search text\""
}
Update a block's content using either direct text replacement or pattern-based transformations:
use_mcp_tool roam-research roam_update_block {
"block_uid": "target-block-uid",
"content": "New block content"
}
Or use pattern-based transformation:
use_mcp_tool roam-research roam_update_block {
"block_uid": "target-block-uid",
"transform_pattern": {
"find": "\\bPython\\b",
"replace": "[[Python]]",
"global": true
}
}
Features:
Parameters:
block_uid
: UID of the block to update (required)content
: New content for the block (if using direct replacement)transform_pattern
: Pattern for transforming existing content:
find
: Text or regex pattern to findreplace
: Text to replace withglobal
: Whether to replace all occurrences (default: true)Returns:
{
"success": true,
"content": "Updated block content"
}
Search for blocks containing specific tags with optional filtering by nearby tags:
use_mcp_tool roam-research roam_search_for_tag {
"primary_tag": "Project/Tasks",
"page_title_uid": "optional-page-title-or-uid",
"near_tag": "optional-secondary-tag",
"case_sensitive": true
}
Features:
Parameters:
primary_tag
: The main tag to search for (required)page_title_uid
: Title or UID of the page to search in (optional)near_tag
: Another tag to filter results by (optional)case_sensitive
: Whether to perform case-sensitive search (optional, default: true to match Roam's native behavior)Returns:
{
"success": true,
"matches": [
{
"block_uid": "matching-block-uid",
"content": "Block content containing #[[primary_tag]]",
"page_title": "Page containing block"
}
],
"message": "Found N block(s) referencing \"primary_tag\""
}
Store memories or important information with automatic tagging and categorization:
use_mcp_tool roam-research roam_remember {
"memory": "Important information to remember",
"categories": ["Work", "Project/Alpha"]
}
Features:
Parameters:
memory
: The information to remember (required)categories
: Optional array of categories to tag the memory withReturns:
{
"success": true,
"block_uid": "created-block-uid",
"content": "Memory content with tags"
}
Search for blocks and pages based on creation or modification dates:
use_mcp_tool roam-research roam_search_by_date {
"start_date": "2025-01-01",
"end_date": "2025-01-31",
"type": "modified",
"scope": "blocks",
"include_content": true
}
Features:
Parameters:
start_date
: Start date in ISO format (YYYY-MM-DD) (required)end_date
: End date in ISO format (YYYY-MM-DD) (optional)type
: Whether to search by 'created', 'modified', or 'both' (required)scope
: Whether to search 'blocks', 'pages', or 'both' (required)include_content
: Whether to include the content of matching blocks/pages (optional, default: true)Returns:
{
"success": true,
"matches": [
{
"uid": "block-or-page-uid",
"type": "block",
"time": 1704067200000,
"content": "Block or page content",
"page_title": "Page title (for blocks)"
}
],
"message": "Found N matches for the given date range and criteria"
}
Find all pages that have been modified since midnight today:
use_mcp_tool roam-research roam_find_pages_modified_today {}
Features:
Returns:
{
"success": true,
"pages": ["Page 1", "Page 2"],
"message": "Found 2 page(s) modified today"
}
Execute custom Datalog queries on your Roam graph for advanced data retrieval and analysis:
use_mcp_tool roam-research roam_datomic_query {
"query": "[:find (count ?p)\n :where [?p :node/title]]",
"inputs": []
}
Features:
Parameters:
query
: The Datalog query to execute (required)inputs
: Optional array of input parameters for the queryReturns:
{
"success": true,
"matches": [
{
"content": "[result data]",
"block_uid": "",
"page_title": ""
}
],
"message": "Query executed successfully. Found N results."
}
Example Queries:
[:find (count ?p)
:where [?p :node/title]]
[:find ?string ?title
:where
[?b :block/string ?string]
[(clojure.string/lower-case ?string) ?lower]
[(clojure.string/includes? ?lower "search term")]
[?b :block/page ?p]
[?p :node/title ?title]]
[:find ?block_ref ?string
:in $ ?start_of_day
:where
[?b :edit/time ?time]
[(> ?time ?start_of_day)]
[?b :block/uid ?block_ref]
[?b :block/string ?string]]
See Roam_Research_Datalog_Cheatsheet.md for more query examples and syntax documentation.
Navigate and search through block parent-child relationships:
use_mcp_tool roam-research roam_search_hierarchy {
"parent_uid": "optional-parent-block-uid",
"child_uid": "optional-child-block-uid",
"page_title_uid": "optional-page-title-or-uid",
"max_depth": 3
}
Features:
Parameters:
parent_uid
: UID of the block to find children of (required if searching down)child_uid
: UID of the block to find parents of (required if searching up)page_title_uid
: Title or UID of the page to search in (optional)max_depth
: How many levels deep to search (optional, default: 1, max: 10)Returns:
{
"success": true,
"matches": [
{
"block_uid": "related-block-uid",
"content": "Block content",
"depth": 2,
"page_title": "Page containing block"
}
],
"message": "Found N block(s) as children/parents..."
}
The server provides comprehensive error handling for common scenarios:
Each error response includes:
To build the server:
npm install
npm run build
This will:
You can also use npm run watch
during development to automatically recompile when files change.
The MCP Inspector is a tool that helps test and debug MCP servers. To test the server:
# Inspect with npx:
npx @modelcontextprotocol/inspector node build/index.js
This will:
MIT License
Seamless access to top MCP servers powering the future of AI integration.