# Logseq MCP

> Logseq (Knowledge Management) MCP Server lets your AI agent treat your local knowledge graph like a database. It connects to Logseq, letting you programmatically create pages (`create_page`), append specific blocks (`insert_block`), search content across the entire graph (`search_content`), or manage structure by listing all pages (`list_pages`). Full control over your private notes without touching the UI.

## Overview
- **Category:** loved-by-devs
- **Price:** Free
- **Tags:** bi-directional-linking, markdown, knowledge-graph, privacy-first, outliner

## Description

**Logseq Knowledge Graph Operations MCP Server**

You're tired of your AI agent just poking around the Logseq UI like a tourist? This server lets your agent treat your local knowledge graph like it's a proper database. You get full, programmatic control over every note and link without ever touching the visual interface. It exposes tools that let your AI client read, write, and restructure your entire private knowledge base.

**Managing Pages: Creating and Deleting Containers**
You can tell your agent to build new pages instantly; use `create_page` to generate a fresh, organized page right into your graph with native markdown content. If a project or idea is dead, you've got `delete_page`—it nukes the whole Logseq page irreversibly, taking out all associated metadata loops. To check what you're working with, run `list_pages`; it spits out a list of every single page currently living in your graph. Need to know everything about one specific location? Use `get_page` to pull all metadata for any page by its name or UUID.

**Manipulating Blocks: The Fine Detail Work**
The real power is down at the block level, where you can make surgical changes. You'll use `insert_block` to append a new outliner block onto a specific page and update every necessary node immediately. If something needs tweaking, don't worry; `update_block` modifies raw properties within one specific block while keeping its unique UUID bounds and linking indices intact. Wanna remove a section? Use `delete_block`; it safely pulls an active block from the target graph, dropping any child dependencies or nodes that relied on it.

**Auditing and Structure Control**
Want to map out your whole damn system before you mess with it? The server lets you run `get_page_blocks`, which extracts the complete, hierarchical block tree array for a page you specify. For environmental sanity checks, running `get_current_graph` identifies and parses the current graph's native array limits. You can also get a full snapshot of a single page using `get_page_blocks` to extract that deeply nested structure for analysis.

**Search and Retrieval: Finding the Needle in the Haystack**
Forget the built-in search bar; it's too limited. The `search_content` tool executes local queries across your entire knowledge base, pulling out bound text targets from every index, no matter where they live. It’s way better.

This setup gives your AI client total command over your notes. You can programmatically read metadata, append content blocks, delete entire pages, and search across the whole graph—all controlled by simple function calls.

## Tools

### create_page
Creates a new, organized page in your Logseq graph with native markdown content.

### delete_block
Removes an active block from the target graph, safely dropping child dependencies and nodes.

### delete_page
Deletes an entire Logseq page irreversibly, including all associated metadata loops.

### get_current_graph
Validates the environment by identifying and parsing the current graph's native array limits.

### get_page
Retrieves all metadata for a specific Logseq page using its name or UUID.

### get_page_blocks
Extracts the complete, hierarchical block tree array from a specified page map.

### insert_block
Appends a new outliner block to a specific page and updates all necessary nodes immediately.

### list_pages
Returns a list of every single page currently existing in the Logseq graph.

### search_content
Executes local queries, extracting bound text targets across the entire knowledge base and multiple indices.

### update_block
Modifies raw properties within a specific Logseq block while preserving its unique UUID bounds and linking indices.

## Prompt Examples

**Prompt:** 
```
Search my Logseq graph for 'smart building research'
```

**Response:** 
```
I've scanned your graph and found 3 relevant matches: 1) Page 'Smart-Buildings-Project', 2) Block in 'Journal 2026-03-27' mentioning sensor setups, 3) Tag '#research' in multiple blocks. Would you like to see the blocks from the project page?
```

**Prompt:** 
```
Create a new page called 'Meeting Notes' with content '# Meetings 2026'
```

**Response:** 
```
Page 'Meeting Notes' created successfully in your graph. I've added the initial markdown header. You can now use the `insert_block` tool to add specific meeting items or agenda points.
```

**Prompt:** 
```
Add a block to the 'Project Alpha' page: 'Verify API endpoints for production'
```

**Response:** 
```
Block added successfully to 'Project Alpha'. It is now part of the outliner tree for that page. Would you like me to add any specific child blocks or sub-tasks under this point?
```

## Capabilities

### Manage Pages
The agent can create new pages, delete entire pages, and pull metadata for any page by name or UUID.

### Manipulate Blocks
You can append new outliner blocks to a page, modify existing block properties, or safely remove specific nodes within the graph.

### Audit Graph Structure
The server allows you to list all pages in the graph or extract deeply nested, hierarchical trees for structural analysis.

### Search and Retrieve Content
Execute local queries across your entire knowledge base, finding specific text targets regardless of where they live.

## Use Cases

### Finding all mentions of 'Kubernetes'
A developer needs every instance where they mentioned 'Kubernetes' across their project notes. Instead of manually searching page by page, the agent runs `search_content`. It returns a list of relevant blocks and pages instantly, telling them exactly where to look.

### Building a new meeting record
A team member finishes a call. They ask their agent to create a page called 'Client Sync' using `create_page`. The agent returns the empty shell; the user then uses `insert_block` multiple times to add specific action items and owners.

### Reviewing an old project structure
The PKM enthusiast wants to know how deeply nested their 'AI Research' notes are. They use `get_page_blocks` on the main page, which returns a full hierarchical tree array, visualizing all sub-ideas and relationships in one view.

### Cleaning up orphaned data
The user finds an outdated project note they need to remove entirely. Instead of just deleting content, the agent runs `delete_page`, ensuring that all metadata loops are destroyed securely and irreversibly from the graph.

## Benefits

- Centralized search: Instead of opening tabs, use `search_content` to query your whole corpus for specific text targets across all pages and namespaces. It finds what you need instantly.
- Structured updates: Need to refine a project requirement? Use `update_block` to modify raw properties inside an existing block without risking broken links or UUID bounds.
- Graph mapping: Understand the structure of your notes with `get_page_blocks`. This tool extracts the full, nested outliner hierarchy so you can audit how ideas connect.
- Content generation: Start a new project by calling `create_page` and giving it an initial markdown header. It's ready to accept blocks right away.
- Data integrity: Don't accidentally lose notes. Use `get_page` to check the metadata for a page before you decide to delete it with `delete_page`.

## How It Works

The bottom line is: you tell your AI client what to do with the knowledge base; the server executes the command directly against Logseq's private API.

1. Subscribe to the server and enable the HTTP API in Logseq settings.
2. Give your AI client the Logseq API Token and Host URL for authentication.
3. Your agent calls a tool—say, `search_content`—and gets back structured data detailing what's in your local graph.

## Frequently Asked Questions

**How do I find a specific piece of text in my notes using search_content?**
You just tell your agent the query. `search_content` executes local queries across all indices, finding explicitly bound text targets anywhere in your graph, titles, or namespaces.

**Can I use insert_block to add items to a page?**
Yes. Running `insert_block` appends new outliner chunks to the specified map. This is how you programmatically build meeting notes or task lists without manual input.

**Does get_page really give me all the metadata for a page?**
It does. `get_page` retrieves all associated metadata, letting your agent understand the context and structure of that specific page before making any changes.

**If I delete a page using delete_page, is it safe?**
Yes, it's irreversible. `delete_page` handles removing content arrays and destroying metadata loops securely from the graph.

**How do I use get_current_graph to verify that my AI client is targeting the correct knowledge base?**
It validates your environment by parsing and listing active graph arrays. The tool returns explicit local database paths, confirming that your agent connects to the right storage before running any commands.

**When I use delete_block, how does it safely handle child dependencies within a node?**
The process automatically handles dependent nodes. It removes only the target block while managing and preserving the structural integrity of all linked parent/child elements around it.

**What deep structural information do I get when running get_page_blocks on a page?**
It extracts the full hierarchical tree structure. This gives you a complete map of nested blocks, showing complex relationships between ideas and sub-tasks on that specific page.

**Does create_page just make an empty container, or does it handle initial content?**
It does more than just make an empty placeholder. `create_page` deploys the new page and inserts native markdown contents simultaneously, allowing you to build structure immediately.

**Can I search across all my Logseq pages using my agent?**
Yes. Use the `search_content` tool to execute deep property searches across your graph indices. Your agent will filter titles, namespaces, and block scopes to find the exact information you need.

**How do I add a new note to a specific page?**
Use the `insert_block` tool and provide the target Page name or ID. Your agent will drive the Logseq editor to add a new outliner chunk with your markdown content immediately.

**Can my agent retrieve the hierarchical structure of a long page?**
Absolutely. The `get_page_blocks` tool extracts the full hierarchical tree from a page map. Your agent will return the nested arrays of outliner blocks, ensuring you have the complete structural context of your data.