Skip to main content
Glama
camiloluvino

Roam Research MCP Server

by camiloluvino

roam_search_block_refs

Find block references within pages or across your entire Roam Research graph to track connections and identify relationships between notes.

Instructions

Search for block references within a page or across the entire graph. Can search for references to a specific block or find all block references.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
block_uidNoOptional: UID of the block to find references to
page_title_uidNoOptional: Title or UID of the page to search in (UID is preferred for accuracy). If not provided, searches across all pages.

Implementation Reference

  • Core handler logic: Executes Datomic queries to find blocks referencing a specific block UID or containing any block references ((uid)) within a page or graph-wide. Resolves embedded references and formats results.
    async execute(): Promise<SearchResult> {
      const { block_uid, page_title_uid } = this.params;
    
      // Get target page UID if provided
      let targetPageUid: string | undefined;
      if (page_title_uid) {
        targetPageUid = await SearchUtils.findPageByTitleOrUid(this.graph, page_title_uid);
      }
    
      // Build query based on whether we're searching for references to a specific block
      // or all block references within a page/graph
      let queryStr: string;
      let queryParams: any[];
    
      if (block_uid) {
        // Search for references to a specific block
        if (targetPageUid) {
          queryStr = `[:find ?block-uid ?block-str
                      :in $ ?ref-uid ?page-uid
                      :where [?p :block/uid ?page-uid]
                             [?b :block/page ?p]
                             [?b :block/string ?block-str]
                             [?b :block/uid ?block-uid]
                             [(clojure.string/includes? ?block-str ?ref-uid)]]`;
          queryParams = [`((${block_uid}))`, targetPageUid];
        } else {
          queryStr = `[:find ?block-uid ?block-str ?page-title
                      :in $ ?ref-uid
                      :where [?b :block/string ?block-str]
                             [?b :block/uid ?block-uid]
                             [?b :block/page ?p]
                             [?p :node/title ?page-title]
                             [(clojure.string/includes? ?block-str ?ref-uid)]]`;
          queryParams = [`((${block_uid}))`];
        }
      } else {
        // Search for any block references
        if (targetPageUid) {
          queryStr = `[:find ?block-uid ?block-str
                      :in $ ?page-uid
                      :where [?p :block/uid ?page-uid]
                             [?b :block/page ?p]
                             [?b :block/string ?block-str]
                             [?b :block/uid ?block-uid]
                             [(re-find #"\\(\\([^)]+\\)\\)" ?block-str)]]`;
          queryParams = [targetPageUid];
        } else {
          queryStr = `[:find ?block-uid ?block-str ?page-title
                      :where [?b :block/string ?block-str]
                             [?b :block/uid ?block-uid]
                             [?b :block/page ?p]
                             [?p :node/title ?page-title]
                             [(re-find #"\\(\\([^)]+\\)\\)" ?block-str)]]`;
          queryParams = [];
        }
      }
    
      const rawResults = await q(this.graph, queryStr, queryParams) as [string, string, string?][];
      
      // Resolve block references in content
      const resolvedResults = await Promise.all(
        rawResults.map(async ([uid, content, pageTitle]) => {
          const resolvedContent = await resolveRefs(this.graph, content);
          return [uid, resolvedContent, pageTitle] as [string, string, string?];
        })
      );
      
      const searchDescription = block_uid 
        ? `referencing block ((${block_uid}))`
        : 'containing block references';
        
      return SearchUtils.formatSearchResults(resolvedResults, searchDescription, !targetPageUid);
    }
  • Defines the tool schema including name, description, and input schema for 'roam_search_block_refs'.
    [toolName(BASE_TOOL_NAMES.SEARCH_BLOCK_REFS)]: {
      name: toolName(BASE_TOOL_NAMES.SEARCH_BLOCK_REFS),
      description: 'Search for block references within a page or across the entire graph. Can search for references to a specific block or find all block references.',
      inputSchema: {
        type: 'object',
        properties: {
          block_uid: {
            type: 'string',
            description: 'Optional: UID of the block to find references to'
          },
          page_title_uid: {
            type: 'string',
            description: 'Optional: Title or UID of the page to search in (UID is preferred for accuracy). If not provided, searches across all pages.'
          }
        }
      }
    },
  • Registers the tool handler in the MCP server request handler switch statement, delegating to ToolHandlers.searchBlockRefs.
    case BASE_TOOL_NAMES.SEARCH_BLOCK_REFS: {
      const params = request.params.arguments as {
        block_uid?: string;
        page_title_uid?: string;
      };
      const result = await this.toolHandlers.searchBlockRefs(params);
      return {
        content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
      };
    }
  • Wrapper method in ToolHandlers class that delegates to SearchOperations.searchBlockRefs.
    async searchBlockRefs(params: { block_uid?: string; page_title_uid?: string }) {
      return this.searchOps.searchBlockRefs(params);
    }
  • Method in SearchOperations class that instantiates and executes BlockRefSearchHandlerImpl.
    async searchBlockRefs(params: BlockRefSearchParams): Promise<SearchHandlerResult> {
      const handler = new BlockRefSearchHandlerImpl(this.graph, params);
      return handler.execute();
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'can search for references to a specific block or find all block references,' which hints at functionality but lacks critical details: it doesn't specify output format, pagination, rate limits, authentication requirements, or error handling. For a search tool with zero annotation coverage, this leaves significant gaps in understanding how the tool behaves.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded, with two sentences that directly state the tool's purpose and key capabilities. There is no wasted language or redundancy. However, it could be slightly more structured by explicitly separating scope and parameter usage, which prevents a perfect score.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (search functionality with optional parameters), lack of annotations, and absence of an output schema, the description is incomplete. It fails to explain what the search returns (e.g., list of blocks, metadata), how results are formatted, or any limitations (e.g., search depth, performance considerations). This leaves the agent with insufficient context to use the tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, clearly documenting both optional parameters (block_uid and page_title_uid). The description adds minimal value beyond the schema: it implies the parameters are optional ('can search for references to a specific block') and mentions scope ('within a page or across the entire graph'), but doesn't provide additional syntax, format details, or interaction effects. With high schema coverage, a baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Search for block references within a page or across the entire graph.' It specifies the verb ('search') and resource ('block references'), and distinguishes scope options (page-specific vs. graph-wide). However, it doesn't explicitly differentiate from sibling search tools like roam_search_by_text or roam_search_for_tag, which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides minimal guidance: it mentions searching 'within a page or across the entire graph' and references optional parameters, but offers no explicit advice on when to use this tool versus alternatives (e.g., roam_search_by_text for general text searches or roam_search_for_tag for tag-based searches). No prerequisites, exclusions, or comparative context are provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/camiloluvino/roamMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server