Skip to main content
Glama

roam_datomic_query

Read-onlyIdempotent

Execute custom Datomic queries on Roam graph for advanced data retrieval beyond standard search. Enables complex filtering, boolean logic, sorting, and proximity search.

Instructions

Execute a custom Datomic query on the Roam graph for advanced data retrieval beyond the available search tools. This provides direct access to Roam's query engine. Note: Roam graph is case-sensitive.

Optimal Use Cases for roam_datomic_query:

  • Advanced Filtering (including Regex): Use for scenarios requiring complex filtering, including regex matching on results post-query, which Datalog does not natively support for all data types. It can fetch broader results for client-side post-processing.

  • Highly Complex Boolean Logic: Ideal for intricate combinations of "AND", "OR", and "NOT" conditions across multiple terms or attributes.

  • Arbitrary Sorting Criteria: The go-to for highly customized sorting needs beyond default options.

  • Proximity Search: For advanced search capabilities involving proximity, which are difficult to implement efficiently with simpler tools.

List of some of Roam's data model Namespaces and Attributes: ancestor (descendants), attrs (lookup), block (children, heading, open, order, page, parents, props, refs, string, text-align, uid), children (view-type), create (email, time), descendant (ancestors), edit (email, seen-by, time), entity (attrs), log (id), node (title), page (uid, title), refs (text). Predicates (clojure.string/includes?, clojure.string/starts-with?, clojure.string/ends-with?, <, >, <=, >=, =, not=, !=). Aggregates (distinct, count, sum, max, min, avg, limit). Tips: Use :block/parents for all ancestor levels, :block/children for direct descendants only; combine clojure.string for complex matching, use distinct to deduplicate, leverage Pull patterns for hierarchies, handle case-sensitivity carefully, and chain ancestry rules for multi-level queries.

IMPORTANT: call roam_get_guidelines for this graph once per session before using this tool, reads included — conventions change how results are read, not just written.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
graphNoTarget graph key from ROAM_GRAPHS config. Defaults to ROAM_DEFAULT_GRAPH. Only needed in multi-graph mode.
queryYesThe Datomic query to execute (in Datalog syntax). Example: `[:find ?block-string :where [?block :block/string ?block-string] (or [(clojure.string/includes? ?block-string "hypnosis")] [(clojure.string/includes? ?block-string "trance")] [(clojure.string/includes? ?block-string "suggestion")]) :limit 25]`
inputsNoOptional array of input parameters for the query
write_keyNoWrite confirmation key. Required for write operations on non-default graphs when write_key is configured.
regexFlagsNoOptional: Flags for the regex filter (e.g., "i" for case-insensitive, "g" for global).
regexFilterNoOptional: A regex pattern to filter the results client-side after the Datomic query. Applied to JSON.stringify(result) or specific fields if regexTargetField is provided.
regexTargetFieldNoOptional: An array of field paths (e.g., ["block_string", "page_title"]) within each Datomic result object to apply the regex filter to. If not provided, the regex is applied to the stringified full result.
Behavior5/5

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

The description adds substantial behavioral context beyond annotations: it notes case-sensitivity, explains that regex filtering is applied client-side after the query, and warns that graph conventions affect results. Annotations already declare readOnly, idempotent, and non-destructive, and the description does not contradict them; it enriches the agent's understanding of side effects and result interpretation.

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 lengthy but well-structured with sections (Optimal Use Cases, data model, predicates, tips) and all content is relevant to using the tool effectively. It front-loads the purpose and uses bold headers for scannability, though a slight trim could make it more concise.

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

Completeness4/5

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

For a complex Datomic query tool, the description covers most essential context: syntax, use cases, data model, predicates, and a required guideline call. However, it does not describe the return format beyond mentioning client-side filtering, and could benefit from noting potential errors or performance implications, so it isn't fully complete.

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

Parameters4/5

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

Schema coverage is 100%, so the baseline is 3, but the description adds significant value by providing an example Datalog query, listing predicates and aggregates, and explaining the data model namespaces. This goes beyond the schema's parameter descriptions and helps the agent construct correct queries, especially for the 'query' parameter.

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

Purpose5/5

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

The description clearly states the tool executes custom Datomic queries on the Roam graph for advanced data retrieval, explicitly distinguishing it from search tools. It further lists specific advanced use cases (regex filtering, complex boolean logic, arbitrary sorting, proximity search), making the purpose unambiguous.

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

Usage Guidelines4/5

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

The description has an 'Optimal Use Cases' section that clearly specifies when to use this tool (advanced filtering, complex boolean logic, etc.), and the opening sentence implies it should be used beyond the available search tools. It also mandates calling roam_get_guidelines before use, but doesn't explicitly name alternative tools for contrast or state when not to use it, so it falls short of a 5.

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/2b3pro/roam-research-mcp'

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