Obsidian MCP Server
A Model Context Protocol server that enables AI assistants like Claude to interact with your Obsidian vault through the Local REST API plugin, allowing reading, creating, searching, and managing notes.
README
Obsidian MCP Server
A Model Context Protocol (MCP) server that enables AI assistants like Claude to interact with your Obsidian vault. This server provides tools for reading, creating, searching, and managing notes in Obsidian through the Local REST API plugin.
Features
- 📖 Read & write notes - Full access to your Obsidian vault with automatic overwrite protection
- 🔍 Smart search - Find notes by content, tags, or modification date
- 📁 Browse vault - List and navigate your notes by directory
- 🏷️ Tag management - Add, remove, and organize tags in frontmatter
- 📊 Note insights - Get statistics like word count and link analysis
- 🎯 AI-optimized - Clear error messages and smart defaults for better AI interactions
- 🔒 Secure - API key authentication with local-only connections
Prerequisites
- Obsidian with the Local REST API plugin installed and enabled
- Python 3.10+ installed on your system
- Node.js (optional, for running MCP Inspector)
Installation
Quick Install
-
Install and configure Obsidian:
- Install the Local REST API plugin in Obsidian
- Enable the plugin in Settings > Community plugins
- Go to Settings > Local REST API
- Copy your API key (you'll need this for step 2)
-
Configure your AI tool:
<details> <summary><b>Claude Desktop</b></summary>
Edit your Claude Desktop config file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
{ "mcpServers": { "obsidian": { "command": "uvx", "args": ["obsidian-mcp"], "env": { "OBSIDIAN_REST_API_KEY": "your-api-key-here" } } } }</details>
<details> <summary><b>Cursor IDE</b></summary>
Add to your Cursor settings:
- Project-specific:
.cursor/mcp.jsonin your project directory - Global:
~/.cursor/mcp.jsonin your home directory
{ "mcpServers": { "obsidian": { "command": "uvx", "args": ["obsidian-mcp"], "env": { "OBSIDIAN_REST_API_KEY": "your-api-key-here" } } } }Then: Open Settings → Cursor Settings → Enable MCP </details>
<details> <summary><b>Windsurf IDE</b></summary>
Edit your Windsurf config file:
- Location:
~/.codeium/windsurf/mcp_config.json
{ "mcpServers": { "obsidian": { "command": "uvx", "args": ["obsidian-mcp"], "env": { "OBSIDIAN_REST_API_KEY": "your-api-key-here" } } } }Then: Open Windsurf Settings → Advanced Settings → Cascade → Add Server → Refresh </details>
Replace
your-api-key-herewith the API key you copied from Obsidian. - macOS:
-
Restart your AI tool to load the new configuration.
That's it! The server will now be available in your AI tool with access to your Obsidian vault.
Note: This uses
uvxwhich automatically downloads and runs the server in an isolated environment. Most users won't need to install anything else. If you don't haveuvinstalled, you can also usepipx install obsidian-mcpand change the command to"obsidian-mcp"in the config.
Try It Out
Here are some example prompts to get started:
- "Show me all notes I modified this week"
- "Create a new daily note for today with my meeting agenda"
- "Search for all notes about project planning"
- "Read my Ideas/startup.md note"
Development Installation
-
Clone the repository:
git clone https://github.com/natestrong/obsidian-mcp cd obsidian-mcp -
Set up Python environment:
# Using pyenv (recommended) pyenv virtualenv 3.12.9 obsidian-mcp pyenv activate obsidian-mcp # Or using venv python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate -
Install dependencies:
pip install -r requirements.txt -
Set up Obsidian Local REST API:
- Install the Local REST API plugin in Obsidian
- Enable the plugin in Obsidian settings
- Copy the API key from the plugin settings
- Note the port number (default: 27124)
-
Configure environment variables:
export OBSIDIAN_REST_API_KEY="your-api-key-here" export OBSIDIAN_API_URL="https://localhost:27124" # if not using default -
Add to Claude Desktop (for development):
Edit your Claude Desktop config file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
{ "mcpServers": { "obsidian": { "command": "/path/to/python", "args": ["-m", "src.server"], "cwd": "/path/to/obsidian-mcp", "env": { "PYTHONPATH": "/path/to/obsidian-mcp", "OBSIDIAN_REST_API_KEY": "your-api-key-here", "OBSIDIAN_API_URL": "https://localhost:27124" } } } } - macOS:
Project Structure
obsidian-mcp/
├── src/
│ ├── server.py # Main entry point with rich parameter schemas
│ ├── tools/ # Tool implementations
│ │ ├── note_management.py # CRUD operations
│ │ ├── search_discovery.py # Search and navigation
│ │ └── organization.py # Tags, moves, metadata
│ ├── models/ # Pydantic models for validation
│ │ └── obsidian.py # Note, SearchResult, VaultItem models
│ ├── utils/ # Shared utilities
│ │ ├── obsidian_api.py # REST API client wrapper
│ │ ├── validators.py # Path validation, sanitization
│ │ └── validation.py # Comprehensive parameter validation
│ └── constants.py # API endpoints, defaults, enhanced error messages
├── tests/
│ ├── run_tests.py # Smart test runner
│ ├── test_unit.py # Unit tests with mocks
│ ├── test_integration.py # Integration tests
│ ├── test_live.py # Live API tests
│ ├── test_comprehensive.py # Full workflow validation
│ └── test_data_validation.py # Return value testing
├── docs/ # Additional documentation
├── requirements.txt # Python dependencies
├── CLAUDE.md # Instructions for Claude Code
└── README.md
Available Tools
Note Management
read_note
Read the content and metadata of a specific note.
Parameters:
path: Path to the note (e.g., "Daily/2024-01-15.md")
Returns:
{
"path": "Daily/2024-01-15.md",
"content": "# Daily Note\n\nContent here...",
"metadata": {
"tags": ["daily", "journal"],
"aliases": [],
"frontmatter": {}
}
}
create_note
Create a new note or update an existing one.
Parameters:
path: Path where the note should be createdcontent: Markdown content of the noteoverwrite(default:false): Whether to overwrite existing notes
update_note
Update the content of an existing note.
⚠️ IMPORTANT: By default, this tool REPLACES the entire note content. Always read the note first if you need to preserve existing content.
Parameters:
path: Path to the note to updatecontent: New markdown content (REPLACES existing content unless using append)create_if_not_exists(default:false): Create if doesn't existmerge_strategy(default:"replace"): How to handle content"replace": Overwrites entire note content (default)"append": Adds new content to the end of existing content
Safe Update Pattern:
# ALWAYS read first to preserve content
existing_note = await read_note("Daily/2024-01-15.md")
updated_content = existing_note["content"] + "\n\n## New Section\nAdded content"
await update_note("Daily/2024-01-15.md", updated_content)
# Or use append mode to add to the end
await update_note("Daily/2024-01-15.md", "## New Section\nAdded content", merge_strategy="append")
delete_note
Delete a note from the vault.
Parameters:
path: Path to the note to delete
Search and Discovery
search_notes
Search for notes containing specific text.
Parameters:
query: Search query (supports Obsidian search syntax)context_length(default:100): Number of characters to show around matches
Note: Search functionality may have connectivity issues with some REST API configurations.
search_by_date
Search for notes by creation or modification date.
Parameters:
date_type(default:"modified"): Either "created" or "modified"days_ago(default:7): Number of days to look backoperator(default:"within"): Either "within" (last N days) or "exactly" (exactly N days ago)
Returns:
{
"query": "Notes modified within last 7 days",
"count": 15,
"results": [
{
"path": "Daily/2024-01-15.md",
"date": "2024-01-15T10:30:00",
"days_ago": 1
}
]
}
Example usage:
- "Show me all notes modified this week" →
search_by_date("modified", 7, "within") - "Find notes created in the last 30 days" →
search_by_date("created", 30, "within") - "What notes were modified exactly 2 days ago?" →
search_by_date("modified", 2, "exactly")
list_notes
List notes in your vault with optional recursive traversal.
Parameters:
directory(optional): Specific directory to list (e.g., "Daily", "Projects")recursive(default:true): List all notes recursively
Returns:
{
"directory": "Daily",
"recursive": true,
"count": 365,
"notes": [
{"path": "Daily/2024-01-01.md", "name": "2024-01-01.md"},
{"path": "Daily/2024-01-02.md", "name": "2024-01-02.md"}
]
}
Organization
move_note
Move a note to a new location.
Parameters:
source_path: Current path of the notedestination_path: New path for the noteupdate_links(default:true): Update links in other notes (future enhancement)
add_tags
Add tags to a note's frontmatter.
Parameters:
path: Path to the notetags: List of tags to add (without # prefix)
remove_tags
Remove tags from a note's frontmatter.
Parameters:
path: Path to the notetags: List of tags to remove
get_note_info
Get metadata and statistics about a note without retrieving its full content.
Parameters:
path: Path to the note
Returns:
{
"path": "Projects/AI Research.md",
"exists": true,
"metadata": {
"tags": ["ai", "research"],
"aliases": [],
"frontmatter": {}
},
"stats": {
"size_bytes": 4523,
"word_count": 823,
"link_count": 12
}
}
Testing
Running Tests
# Run all tests
python tests/run_tests.py
# Run specific test types
python tests/run_tests.py unit # Unit tests (requires pytest)
python tests/run_tests.py integration # Integration tests (requires pytest)
python tests/run_tests.py live # Live tests with real Obsidian
# Run individual test files
python tests/test_comprehensive.py # Full workflow test
python tests/test_data_validation.py # Data structure validation
Testing with MCP Inspector
-
Ensure Obsidian is running with the Local REST API plugin enabled
-
Run the MCP Inspector:
npx @modelcontextprotocol/inspector python -m src.server -
Open the Inspector UI at
http://localhost:5173 -
Test the tools interactively with your actual vault
Integration with Claude Desktop
For development installations, see the Development Installation section above.
Enhanced Error Handling
The server provides detailed, actionable error messages to help AI systems recover from errors:
Example Error Messages
Invalid Path:
Invalid note path: '../../../etc/passwd'.
Valid paths must: 1) End with .md or .markdown, 2) Use forward slashes (e.g., 'folder/note.md'),
3) Not contain '..' or start with '/', 4) Not exceed 255 characters.
Example: 'Daily/2024-01-15.md' or 'Projects/My Project.md'
Empty Search Query:
Search query cannot be empty.
Valid queries: 1) Keywords: 'machine learning',
2) Tags: 'tag:#project', 3) Paths: 'path:Daily/',
4) Combined: 'tag:#urgent TODO'
Invalid Date Parameters:
Invalid date_type: 'invalid'.
Must be either 'created' or 'modified'.
Use 'created' to find notes by creation date, 'modified' for last edit date
Troubleshooting
"Connection refused" error
- Ensure Obsidian is running
- Verify the Local REST API plugin is enabled
- Check that the port matches (default: 27124)
- Confirm the API key is correct
- The enhanced error will show the exact URL and port being used
"Certificate verify failed" error
- This is expected with the Local REST API's self-signed certificate
- The server handles this automatically
"Module not found" error
- Ensure your virtual environment is activated
- Run from the project root:
python -m src.server - Verify PYTHONPATH includes the project directory
Empty results when listing notes
- Specify a directory when using
list_notes(e.g., "Daily", "Projects") - Root directory listing requires recursive implementation
- Check if notes are in subdirectories
Tags not updating
- Ensure notes have YAML frontmatter section
- Frontmatter must include a
tags:field (even if empty)
Best Practices for AI Assistants
Preventing Data Loss
- Always read before updating: The
update_notetool REPLACES content by default - Use append mode for additions: When adding to existing notes, use
merge_strategy="append" - Check note existence: Use
read_noteto verify a note exists before modifying - Be explicit about overwrites: Only use
overwrite=truewhen intentionally replacing content
Recommended Workflows
Safe note editing:
- Read the existing note first
- Modify the content as needed
- Update with the complete new content
Adding to daily notes:
- Use
merge_strategy="append"to add entries without losing existing content
Creating new notes:
- Use
create_notewithoverwrite=false(default) to prevent accidental overwrites
Security Considerations
- Keep your API key secret - never commit it to version control
- The server validates all paths to prevent directory traversal attacks
- All communication with Obsidian uses HTTPS (self-signed certificate)
- The server only accepts local connections through the REST API
Development
Code Style
- Uses FastMCP framework for MCP implementation
- Pydantic models for type safety and validation
- Modular architecture with separated concerns
- Comprehensive error handling and user-friendly messages
Adding New Tools
- Create tool function in appropriate module under
src/tools/ - Add Pydantic models if needed in
src/models/ - Register the tool in
src/server.pywith the@mcp.tool()decorator - Include comprehensive docstrings
- Add tests in
tests/ - Test with MCP Inspector before deploying
Publishing (for maintainers)
To publish a new version to PyPI:
# 1. Update version in pyproject.toml
# 2. Clean old builds
rm -rf dist/ build/ *.egg-info/
# 3. Build the package
python -m build
# 4. Check the package
twine check dist/*
# 5. Upload to PyPI
twine upload dist/* -u __token__ -p $PYPI_API_KEY
# 6. Create and push git tag
git tag -a v1.1.0 -m "Release version 1.1.0"
git push origin v1.1.0
Users can then install and run with:
# Using uvx (recommended - no installation needed)
uvx obsidian-mcp
# Or install globally with pipx
pipx install obsidian-mcp
obsidian-mcp
# Or with pip
pip install obsidian-mcp
obsidian-mcp
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-tool) - Write tests for new functionality
- Ensure all tests pass
- Commit your changes (
git commit -m 'Add amazing tool') - Push to the branch (
git push origin feature/amazing-tool) - Open a Pull Request
License
MIT License - see LICENSE file for details
Acknowledgments
- Anthropic for creating the Model Context Protocol
- Obsidian team for the amazing note-taking app
- coddingtonbear for the Local REST API plugin
- dsp-ant for the FastMCP framework
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。