search_blocks
Locate specific blocks in your Logseq graph by using queries to search for terms, pages, or references, streamlining content discovery and organization.
Instructions
Searches for blocks matching a query in the Logseq graph.
Query examples:
- page:"Page Name" - blocks on a specific page
- "search term" - blocks containing the term
- [[Page Name]] - references to a specific page
Args:
query: The search query.
Returns:
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:134-150 (handler)The MCP tool handler for search_blocks, decorated with @mcp.tool(), which implements the tool logic by calling logseq_client.search_blocks(query). Includes type hints and docstring defining the input/output schema.@mcp.tool() def search_blocks(query: str) -> List[Dict]: """ Searches for blocks matching a query in the Logseq graph. Query examples: - page:"Page Name" - blocks on a specific page - "search term" - blocks containing the term - [[Page Name]] - references to a specific page Args: query: The search query. Returns: List of blocks matching the search query. """ return logseq_client.search_blocks(query)
- Supporting method in LogseqAPIClient that performs the actual API call to Logseq's 'logseq.Editor.search' endpoint with the query, handling response parsing.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-2 (registration)Import of the search_blocks tool from blocks.py into the tools package, exposing it for higher-level imports.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:17-17 (registration)Export of search_blocks in the package __all__, making it available when importing * from the main package.__all__ = ["get_all_pages", "get_page", "create_page", "get_page_blocks", "get_block", "create_block", "update_block", "search_blocks", "get_page_linked_references"]