search_blocks
Search and retrieve blocks from a Logseq graph using specific queries, such as finding blocks on a page, journal, or containing a search term. Ideal for targeted knowledge retrieval.
Instructions
Searches for blocks matching a query in the Logseq graph.
Examples of useful queries:
- page:"Page Name" - find all blocks on a specific page
- "search term" - find blocks containing the term
- page:"Apr 4th, 2025" - find all blocks in a journal
- [[Page Name]] - find references to a specific page
Returned blocks from journal pages will include:
- "journal?": true
- "journalDay": YYYYMMDD - The date in numeric format
Args:
query (str): The search query.
Returns:
list: A list of blocks matching the search query.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Implementation Reference
- src/logseq_mcp/tools/blocks.py:181-203 (handler)The MCP tool handler for 'search_blocks', decorated with @mcp.tool(). Includes schema via type hints and docstring. Delegates to LogseqAPIClient.search_blocks(query).@mcp.tool() def search_blocks(query: str) -> List[Dict]: """ Searches for blocks matching a query in the Logseq graph. Examples of useful queries: - page:"Page Name" - find all blocks on a specific page - "search term" - find blocks containing the term - page:"Apr 4th, 2025" - find all blocks in a journal - [[Page Name]] - find references to a specific page Returned blocks from journal pages will include: - "journal?": true - "journalDay": YYYYMMDD - The date in numeric format Args: query (str): The search query. Returns: list: A list of blocks matching the search query. """ """Search for blocks matching the query.""" return logseq_client.search_blocks(query)
- Core implementation in LogseqAPIClient that performs the actual API call to Logseq's Editor.search endpoint.def search_blocks(self, query: str) -> List[Dict]: """Search for blocks matching a query""" response = self.call_api("logseq.Editor.search", [query]) if isinstance(response, list): return response return response.get("result", []) if isinstance(response, dict) else []
- src/logseq_mcp/tools/__init__.py:2-3 (registration)Re-exports search_blocks from blocks.py, making it available for import in higher modules.from .blocks import get_page_blocks, get_block, create_block, update_block, remove_block, insert_block, move_block, search_blocks
- src/logseq_mcp/__init__.py:11-11 (registration)Includes search_blocks in the public API export via __all__.search_blocks,