gustavo-meilus/logseq-api-mcp
If you are the rightful owner of logseq-api-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Logseq API MCP Server facilitates seamless integration between Model Context Protocol clients and Logseq knowledge bases, enabling AI assistants to interact with Logseq notes.
Logseq API MCP Server
Model Context Protocol server for Logseq API integration with dynamic tool discovery
Table of Contents
- Overview
- Features
- Installation
- Configuration
- Available Tools
- Tool Details & Examples
- Usage Examples
- Development
- Adding New Tools
- Testing
- Contributing
- License
Overview
The Logseq API MCP Server provides seamless integration between Model Context Protocol clients and Logseq knowledge bases. This server enables AI assistants and other MCP clients to interact with your Logseq notes, extract educational content, analyze knowledge relationships, and work with structured information through a comprehensive set of specialized tools.
π Key Innovation: Features a dynamic tool discovery system that automatically detects, imports, and registers any new tools added to the src/tools/
directory - zero configuration required!
Perfect for:
- π Educational Content Management - Extract and organize flashcards and study materials
- π Learning Systems - Build AI-powered study assistants and spaced repetition tools
- π Knowledge Base Analysis - Discover relationships and patterns in your notes
- π Content Discovery - Navigate complex knowledge graphs with AI assistance
- π§ Academic Research - Analyze course materials and learning resources
Features
π οΈ Core Tools (6 Available)
get_all_pages
- Complete page listing with metadataget_page_blocks
- Hierarchical block structure analysisget_page_links
- Page relationship and reference discoveryget_block_content
- Detailed block content with childrenget_all_page_content
- Comprehensive page content extractionget_linked_flashcards
- Advanced flashcard collection and analysis
π Dynamic Tool Discovery
- Auto-Discovery - Automatically finds and imports tools from
src/tools/
- Zero Configuration - No manual imports or registrations needed
- Instant Integration - New tools are immediately available
- CI Validation - Automated testing ensures all tools work correctly
π― Optimized for AI/LLM Consumption
- Clean Structured Output - Emoji-enhanced, hierarchical formatting
- Educational Content Focus - Specialized flashcard and learning material extraction
- Comprehensive Metadata - Block IDs, UUIDs, timestamps, properties, and relationships
- Smart Content Organization - Automatic categorization and summary generation
- Language Agnostic - Works with any Logseq knowledge base language
Installation
Prerequisites
- Python 3.11+ - Modern Python with async/await support
- uv - Fast Python package manager and project management
- Running Logseq instance with API enabled
- Logseq API token for authentication
Quick Setup
-
Clone the repository
git clone https://github.com/gustavo-meilus/logseq-api-mcp.git cd logseq-api-mcp
-
Install with uv
uv sync
-
Configure environment
cp .env.template .env # Edit .env with your Logseq API details
-
Start the server
uv run mcp run src/server.py
Configuration
Create a .env
file in the project root:
# Logseq API Configuration
LOGSEQ_API_ENDPOINT=http://127.0.0.1:12315/api
LOGSEQ_API_TOKEN=your_api_token_here
Getting Your Logseq API Token
- Open Logseq application
- Go to Settings β Features β Developer mode
- Enable "HTTP APIs server"
- Copy the displayed API token
- Note the API endpoint (default:
http://127.0.0.1:12315/api
) - Activate the API
Available Tools
Tool | Description | Output | Best For |
---|---|---|---|
get_all_pages | Lists all pages with essential metadata | 568 pages (135 journal, 433 regular) | Navigation, page discovery |
get_page_blocks | Hierarchical block tree structure | Multi-level tree with IDs, UUIDs | Structure analysis, navigation |
get_page_links | Pages linking to target page | Reference analysis with metadata | Relationship discovery |
get_block_content | Detailed block info with children | Block content + immediate children | Deep content analysis |
get_all_page_content | Complete page content + references | Full content with linked sources | Comprehensive content review |
get_linked_flashcards | Flashcards from page + linked pages | 20 flashcards across 2 pages | Study material extraction |
Tool Details & Examples
ποΈ get_all_pages
Purpose: Get a clean listing of all pages in your knowledge base
Output Format:
π LOGSEQ PAGES LISTING
π Total pages: 568
π
Journal pages: 135
π Regular pages: 433
π REGULAR PAGES:
π Domain Driven Design (DDD) I | ID: 3460 | UUID: 682cfd19-7df6-46e0-a6f3-c09eca3b2530
π MBA Engenharia de Software | ID: 170 | UUID: 682fa28c-a3cc-47f2-ae65-7b7db57e1d67
Use Cases:
- Knowledge base exploration
- Page inventory and organization
- Finding specific pages by name or metadata
π³ get_page_blocks
Purpose: Get hierarchical block structure of any page
Example Input: "Domain Driven Design (DDD) I"
Output Features:
- Tree structure with indentation levels
- Block IDs, UUIDs, and parent-child relationships
- Property extraction and metadata
- Multi-level hierarchy support (up to 8+ levels)
Sample Output:
π³ PAGE BLOCKS TREE STRUCTURE
π Page: Domain Driven Design (DDD) I (ID: 3460)
π Total blocks: 1
π tipo:: #aula curso:: [[MBA Engenharia de Software]]
π ID:3544 | UUID:682cfd19-2826-46b7-8222-0821b11abc60 | Level:1
π Children: 7
H1 # Flashcards [heading: 1]
π ID:3552 | UUID:682cfd19-4c9c-40dd-8cb1-c2625315b8ae | Level:2
π Children: 10
π get_page_links
Purpose: Find all pages that link to a target page
Example Result for "Domain Driven Design (DDD) I":
π PAGE LINKS ANALYSIS
π Target Page: Domain Driven Design (DDD) I
π Found 1 pages linking to this page
π 1. Domain Driven Design (DDD) II
π ID: 3588 | UUID: 682cfd19-3a24-4636-a5d5-c62ea57d352e
π References: 1 | Journal: No
βοΈ Properties: relacionado: Domain Driven Design (DDD) I
Applications:
- Discover related content and cross-references
- Build knowledge maps and relationship graphs
- Find course sequences and learning paths
π get_block_content
Purpose: Get detailed information about a specific block and its immediate children
Example Input: UUID 682cfd19-3c3f-427c-a0be-c5a3a197ea20
Output:
π MAIN BLOCK
π Block ID: 3465
π UUID: 682cfd19-3c3f-427c-a0be-c5a3a197ea20
π CONTENT:
π‘ Flashcard
Por que o DDD prioriza a colaboraΓ§Γ£o entre desenvolvedores e especialistas do domΓnio? #card
+ [ ] Porque os especialistas do domΓnio sΓ£o responsΓ‘veis apenas por aprovar a infraestrutura tecnolΓ³gica.
+ [ ] Para garantir que o software seja construΓdo com base no conhecimento profundo do domΓnio, reduzindo ambiguidades e erros.
πΆ IMMEDIATE CHILDREN:
πΈ CHILD 1:
Resposta Correta: Para garantir que o software seja construΓdo com base no conhecimento profundo do domΓnio, reduzindo ambiguidades e erros.
π get_all_page_content
Purpose: Extract comprehensive content from a page including properties, blocks, and linked references
Key Features:
- Complete hierarchical content structure
- Property extraction and formatting
- Flashcard identification and extraction
- Linked references analysis
- Educational content optimization
Example Summary:
π Domain Driven Design (DDD) I
π 1 blocks | 1 linked sources
π COMPREHENSIVE CONTENT:
π Page Properties [3544]
π curso: MBA Engenharia de Software | tipo: aula | professor: Guilherme Bezerra de Lima
π― # Flashcards [3552]
π‘ Flashcard [3465]
β Q: Por que o DDD prioriza a colaboraΓ§Γ£o entre desenvolvedores e especialistas do domΓnio?
π§ get_linked_flashcards
Purpose: Comprehensive flashcard extraction from target page and all linked pages
Real Example Results for "Domain Driven Design (DDD) I":
π― LINKED FLASHCARDS ANALYSIS
π Target Page: Domain Driven Design (DDD) I
π Searched 2 pages (target + 1 linked)
π‘ Found 20 flashcards total
π Domain Driven Design (DDD) I (10 flashcards)
π Domain Driven Design (DDD) II (10 flashcards)
π SUMMARY:
β’ Total flashcards: 20
β’ Total answer blocks: 0
β’ Pages with flashcards: 2
β’ Average answers per flashcard: 0.0
Advanced Features:
- Multi-choice question support
- Answer block extraction and linking
- Cross-page flashcard discovery
- Educational metadata preservation
- Learning system integration ready
Usage Examples
Add to your Claude Desktop MCP settings (~/.claude/claude_desktop_config.json
):
{
"mcpServers": {
"logseq-api": {
"command": "uv",
"args": [
"run",
"--directory",
"/path/to/logseq-api-mcp",
"python",
"src/server.py"
],
"env": {
"LOGSEQ_API_ENDPOINT": "http://127.0.0.1:12315/api",
"LOGSEQ_API_TOKEN": "your_token_here"
}
}
}
}
Note: Replace /path/to/logseq-api-mcp
with the actual path to your cloned repository.
Development
Project Structure
logseq-api-mcp/
βββ src/
β βββ server.py # MCP server implementation
β βββ registry.py # Dynamic tool discovery & registration
β βββ tools/ # Tool implementations (auto-discovered)
β βββ __init__.py # Dynamic tool importer
β βββ get_all_pages.py # Page listing tool
β βββ get_page_blocks.py # Block structure tool
β βββ get_page_links.py # Page links tool
β βββ get_block_content.py # Block detail tool
β βββ get_all_page_content.py # Complete content tool
β βββ get_linked_flashcards.py # Flashcard extraction tool
βββ tests/
β βββ test_mcp_server.py # Automated server & tool validation
β βββ README.md # Testing documentation
βββ pyproject.toml # UV project configuration
βββ .env.template # Environment template
βββ README.md # This file
Development Setup
# Install with development dependencies
uv sync --dev
# Format code (auto-fixes issues)
uv run ruff check --fix && uv run ruff format
# Test server with MCP inspector
uv run mcp dev src/server.py
# Run server directly
uv run mcp run src/server.py
Adding New Tools
Thanks to the dynamic discovery system, adding new tools is incredibly simple:
1. Create Your Tool File
Create src/tools/your_new_tool.py
:
def your_new_tool(param: str) -> dict:
"""
Your tool description here.
Args:
param: Description of parameter
Returns:
Dict with tool results
"""
return {
"result": f"Processed: {param}",
"status": "success"
}
2. That's It! π
The system automatically:
- β Discovers your tool file
- β Imports the function
- β Registers it with the MCP server
- β Validates it in CI tests
Tool Requirements
- File location: Must be in
src/tools/
directory - Function visibility: Don't start function names with
_
- File naming: Don't start filenames with
_
- Documentation: Include docstring with description
- Type hints: Use for better IDE support
Dynamic Discovery Process
New Tool File β Auto-Scan β Import β Registration β Validation
- Auto-Scan:
src/tools/__init__.py
scans directory for.py
files - Import: Dynamically imports all public functions
- Registration:
src/registry.py
auto-registers with MCP server - Validation: Tests automatically verify tool presence
Testing
Automated Testing
The project includes comprehensive automated testing:
# Run the full test suite
uv run python tests/test_mcp_server.py
Test Coverage:
- β Server Health - Ensures MCP server starts correctly
- β Tool Discovery - Validates automatic tool detection
- β Dynamic Registration - Confirms all tools are registered
- β CI Integration - Runs automatically on all commits
Manual Testing
# Test with MCP Inspector (interactive)
uv run mcp dev src/server.py
# Direct server testing
uv run mcp run src/server.py
Test Output Example
π Testing MCP Server Health and Tools...
π§ Discovered tools (auto-discovery): ['get_all_page_content', 'get_all_pages', 'get_block_content', 'get_linked_flashcards', 'get_page_blocks', 'get_page_links']
π₯ Testing server health...
β
Server started and responded successfully
β
Dynamic tool discovery working correctly
π MCP Server test completed successfully!
π Tools auto-discovered: 6
π₯ Server health: OK
π Dynamic discovery: OK
Contributing
We follow GitHub Flow for all contributions. See for complete details.
Quick Start
- Fork the repository
- Create a feature branch
git checkout -b feature/add-search-tool
- Create your tool (just add the file - automatic integration!)
# Create src/tools/search_tool.py with your function
- Format and test
uv run ruff check --fix && uv run ruff format uv run python tests/test_mcp_server.py
- Commit and push
git commit -m "feat: add search tool for content discovery" git push origin feature/add-search-tool
- Open a Pull Request
Development Benefits
- Zero Configuration - No manual imports or registrations
- Instant Feedback - Tools work immediately after creation
- Automated Validation - CI tests verify everything works
- Clean Architecture - Dynamic system keeps code organized
Code Quality Standards
- Python 3.11+ with modern async/await patterns
- PEP 8 compliance via Ruff formatting
- Type hints for better IDE support
- Error handling with comprehensive exception management
- Environment variables for configuration
- Modular design with dynamic tool loading
Documentation & Resources
License
This project is licensed under the MIT License - see the file for details.
Acknowledgments
- Model Context Protocol for the excellent protocol specification
- Logseq for the powerful knowledge management platform
- MCP Python SDK for the robust development framework
- UV for modern Python package management
Made for the Logseq and MCP communities