A comprehensive Python MCP server for managing Obsidian vaults via obsidian-local-rest-api
Project description
ObsidianReaderMCP
A comprehensive Python MCP (Model Context Protocol) server for managing Obsidian vaults through the obsidian-local-rest-api plugin.
Features
Core CRUD Operations
- Create: Create new notes with content, metadata, and tags
- Read: Retrieve note content and metadata by path
- Update: Modify existing notes (content, metadata, tags)
- Delete: Remove notes from the vault
Extended Functionality
- Batch Operations: Create, update, or delete multiple notes at once
- Template System: Create and use note templates with variables
- Link Analysis: Analyze relationships between notes
- Search & Filter: Advanced search by content, tags, date range, word count
- Vault Statistics: Generate comprehensive vault analytics
- Backup Management: Create and manage vault backups
MCP Server Integration
- Full MCP protocol support for AI assistant integration
- Async/await support for high performance
- Comprehensive error handling and logging
- Rate limiting and connection management
Installation
Prerequisites
- Obsidian with the obsidian-local-rest-api plugin installed and configured
- Python 3.10+
Method 1: Using uvx (Recommended)
The easiest way to use ObsidianReaderMCP is with uvx, which allows you to run it without installation:
# Run directly without installation
uvx obsidianreadermcp
# Or install as a tool
uv tool install obsidianreadermcp
obsidianreadermcp
Method 2: Using pip
# Install from PyPI
pip install obsidianreadermcp
# Run the server
obsidianreadermcp
Method 3: Install from Source
# Clone the repository
git clone https://github.com/QianJue-CN/ObsidianReaderMCP.git
cd ObsidianReaderMCP
# Install dependencies
uv sync
# Or with pip
pip install -e .
Configuration
Environment Variables
Create a .env file in the project root (copy from .env.example):
# Obsidian API Configuration
OBSIDIAN_HOST=localhost
OBSIDIAN_PORT=27123
OBSIDIAN_API_KEY=your_api_key_here
OBSIDIAN_USE_HTTPS=false
OBSIDIAN_TIMEOUT=30
OBSIDIAN_MAX_RETRIES=3
OBSIDIAN_RATE_LIMIT=10
# MCP Server Configuration
LOG_LEVEL=INFO
ENABLE_DEBUG=false
Obsidian Setup
- Install the obsidian-local-rest-api plugin from the Community Plugins
- Enable the plugin in Obsidian settings
- Configure the plugin:
- Set API port (default: 27123)
- Generate an API key
- Enable CORS if needed
- Start the local REST API server
Usage
As a Python Library
import asyncio
from obsidianreadermcp import ObsidianClient
from obsidianreadermcp.config import ObsidianConfig
from obsidianreadermcp.models import NoteMetadata
async def main():
# Create configuration
config = ObsidianConfig() # Uses environment variables
# Create and connect client
async with ObsidianClient(config) as client:
# Create a note
metadata = NoteMetadata(
tags=["example", "demo"],
frontmatter={"title": "My Note", "author": "Me"}
)
note = await client.create_note(
path="my_note.md",
content="# My Note\n\nThis is my note content.",
metadata=metadata
)
# Read the note
retrieved_note = await client.get_note("my_note.md")
print(f"Note content: {retrieved_note.content}")
# Update the note
await client.update_note(
path="my_note.md",
content="# Updated Note\n\nThis content has been updated."
)
# Search notes
results = await client.search_notes("updated")
print(f"Found {len(results)} matching notes")
# Delete the note
await client.delete_note("my_note.md")
asyncio.run(main())
As an MCP Server
# Method 1: Using uvx (recommended)
uvx obsidianreadermcp
# Method 2: Using installed package
obsidianreadermcp
# Method 3: Using Python module
python -m obsidianreadermcp.server
# Method 4: Programmatically
python -c "
import asyncio
from obsidianreadermcp.server import main
asyncio.run(main())
"
Claude Desktop Integration
Add to your Claude Desktop configuration file:
{
"mcpServers": {
"obsidian": {
"command": "uvx",
"args": ["obsidianreadermcp"],
"env": {
"OBSIDIAN_HOST": "localhost",
"OBSIDIAN_PORT": "27123",
"OBSIDIAN_API_KEY": "your-api-key-here"
}
}
}
}
Or if you have it installed globally:
{
"mcpServers": {
"obsidian": {
"command": "obsidianreadermcp",
"env": {
"OBSIDIAN_HOST": "localhost",
"OBSIDIAN_PORT": "27123",
"OBSIDIAN_API_KEY": "your-api-key-here"
}
}
}
}
Extended Features
from obsidianreadermcp.extensions import ObsidianExtensions
async with ObsidianClient(config) as client:
extensions = ObsidianExtensions(client)
# Create a template
template = extensions.create_template(
name="daily_note",
content="# {{date}}\n\n## Tasks\n- {{task}}\n\n## Notes\n{{notes}}",
description="Daily note template"
)
# Create note from template
note = await extensions.create_note_from_template(
template_name="daily_note",
path="daily/2024-01-15.md",
variables={
"date": "2024-01-15",
"task": "Review project status",
"notes": "All systems operational"
}
)
# Batch operations
batch_notes = [
{"path": "note1.md", "content": "Content 1", "tags": ["batch"]},
{"path": "note2.md", "content": "Content 2", "tags": ["batch"]},
]
result = await extensions.batch_create_notes(batch_notes)
# Analyze vault
stats = await extensions.generate_vault_stats()
print(f"Vault has {stats.total_notes} notes with {stats.total_words} words")
# Find orphaned notes
orphaned = await extensions.find_orphaned_notes()
print(f"Found {len(orphaned)} orphaned notes")
MCP Tools
When running as an MCP server, the following tools are available:
Core Operations
create_note: Create a new note with content and metadataget_note: Retrieve a note by pathupdate_note: Update an existing notedelete_note: Delete a notelist_notes: List all notes in vault or foldersearch_notes: Search notes by content
Vault Management
get_vault_info: Get vault information and statisticsget_tags: List all tags used in the vaultget_notes_by_tag: Find notes with specific tags
API Reference
ObsidianClient
The main client class for interacting with Obsidian.
Methods
async create_note(path: str, content: str = "", metadata: Optional[NoteMetadata] = None) -> Noteasync get_note(path: str) -> Noteasync update_note(path: str, content: Optional[str] = None, metadata: Optional[NoteMetadata] = None) -> Noteasync delete_note(path: str) -> boolasync list_notes(folder: str = "") -> List[str]async search_notes(query: str, limit: int = 50, context_length: int = 100) -> List[SearchResult]async get_vault_info() -> VaultInfoasync get_tags() -> List[str]async get_notes_by_tag(tag: str) -> List[Note]
ObsidianExtensions
Extended functionality for advanced vault management.
Methods
async batch_create_notes(notes_data: List[Dict], continue_on_error: bool = True) -> Dictasync batch_update_notes(updates: List[Dict], continue_on_error: bool = True) -> Dictasync batch_delete_notes(paths: List[str], continue_on_error: bool = True) -> Dictcreate_template(name: str, content: str, variables: Optional[List[str]] = None, description: Optional[str] = None) -> Templateasync create_note_from_template(template_name: str, path: str, variables: Optional[Dict[str, str]] = None, metadata: Optional[NoteMetadata] = None) -> Noteasync create_backup(backup_path: str, include_attachments: bool = True) -> BackupInfoasync analyze_links() -> List[LinkInfo]async find_orphaned_notes() -> List[str]async find_broken_links() -> List[LinkInfo]async generate_vault_stats() -> VaultStatsasync search_by_date_range(start_date: Optional[datetime] = None, end_date: Optional[datetime] = None, date_field: str = "created") -> List[Note]async search_by_word_count(min_words: Optional[int] = None, max_words: Optional[int] = None) -> List[Note]
Testing
Run the test suite:
# With uv
uv run pytest
# With pip
pytest
# With coverage
pytest --cov=obsidianreadermcp --cov-report=html
Examples
See the examples/ directory for more detailed usage examples:
basic_usage.py: Demonstrates core CRUD operationsadvanced_features.py: Shows extended functionalitymcp_integration.py: MCP server integration examples
Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Run the test suite (
uv run pytest) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Issues and Support
- 🐛 Bug Reports: GitHub Issues
- 💡 Feature Requests: GitHub Issues
- 📖 Documentation: API Documentation
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- obsidian-local-rest-api - The Obsidian plugin that makes this possible
- MCP (Model Context Protocol) - The protocol for AI assistant integration
- Obsidian - The knowledge management application
Star History
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file obsidianreadermcp-0.1.6.tar.gz.
File metadata
- Download URL: obsidianreadermcp-0.1.6.tar.gz
- Upload date:
- Size: 108.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1aca91520466c3579aa837d727f14d753d93113cda91f28ca385637b76eeda1a
|
|
| MD5 |
f2770b1aaa04a384e426f709dfbd1d0e
|
|
| BLAKE2b-256 |
3c1d0870785cf79c868fb271c79899ff684223953ca6d01dc2652c45202bcf09
|
File details
Details for the file obsidianreadermcp-0.1.6-py3-none-any.whl.
File metadata
- Download URL: obsidianreadermcp-0.1.6-py3-none-any.whl
- Upload date:
- Size: 24.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c33a5ff090978ff9618e2930f73db2adb9f5729851e4c16a2feb891bb3ec11c
|
|
| MD5 |
aa3690fe4dd81046d78204c93856bd7b
|
|
| BLAKE2b-256 |
838d116fb141dc6ecb6202e89f87ad025bc872d1e01726ee1c21ffaf9f3d9761
|