Tutorials & Guides
How to Build a Custom Claude MCP Server in Python to Read and Query Local Obsidian Notes
Ditch the over-engineered vector databases. Here is how to build a lightweight, custom Python MCP server that lets Claude Desktop read, search, and synthesise your local Obsidian markdown notes directly.
Updated 11/16/2026
Stop Over-Engineering Your Local Notes
If you have tried to build a personal knowledge assistant over the past two years, you have likely fallen into the RAG (Retrieval-Augmented Generation) trap. You probably spent three weekends wrestling with vector databases, sentence transformers, chunking strategies, and metadata filtering, only to realise that the resulting system is brittle, slow, and completely blind to the structure of your thoughts.
Let’s be honest: for a personal markdown vault of a few hundred (or even thousands) of notes, spinning up a vector database is like buying a helicopter to cross the street.
With Anthropic’s Model Context Protocol (MCP), there is a far cleaner way. Instead of trying to force your notes into a database they don't belong in, you can expose your local files directly to Claude as a set of dynamic tools.
In this guide, we will build a custom Claude MCP server in Python from scratch. This server will allow Claude Desktop to search, read, and query your local Obsidian notes safely, keeping your personal workflow ticking along nicely without sending your entire vault to a third-party vector host.
To understand the broader ecosystem before we start, you can explore our overview of /platforms/claude.
---
Which AI should I use for this?
Tickd is independent and not affiliated with any AI company.
The Architecture: Why MCP Wins
MCP is an open standard that enables developers to build secure, two-way connections between AI models and local or remote data sources. Instead of the LLM guessing what is in your directory, it explicitly calls tools that you define.
Our custom Python MCP server will expose three specific tools to Claude:
1. list_notes: Returns a list of all markdown files in your Obsidian vault.
2. read_note: Reads the contents of a specific markdown file.
3. search_notes: Performs a simple, fast keyword search across your entire vault.
By keeping this local, we avoid latency, eliminate API costs for embedding generation, and retain absolute control over our data privacy.
---
Step 1: Set Up the Project Environment
We will use Python 3.10 or higher. Anthropic provides an official Python SDK for MCP, which makes building servers incredibly straightforward.
First, create a new directory for your project and set up a virtual environment:
`bash
mkdir claude-obsidian-mcp
cd claude-obsidian-mcp
python3 -m venv .venv
source .venv/bin/activate
`
Next, install the required dependencies. We will need the official mcp SDK and pydantic for data validation:
`bash
pip install mcp pydantic
`
---
Step 2: Write the MCP Server in Python
Create a file named server.py. We will write a lightweight server using the FastMCP class, which handles the complex JSON-RPC communication protocol under the hood.
`python
import os
import re
from typing import List, Dict, Any
from mcp.server.fastmcp import FastMCP
from pydantic import BaseModel, Field
Initialize the FastMCP server # The name here will show up in Claude Desktop's connection logs app = FastMCP("Obsidian Vault Sync")
Define the path to your Obsidian Vault # Pro-tip: Use an environment variable, falling back to a default VAULT_PATH = os.path.expanduser(os.getenv("OBSIDIAN_VAULT_PATH", "~/Obsidian/Personal"))
def secure_path_resolve(relative_path: str) -> str: """Prevents directory traversal attacks by ensuring queries stay inside the vault.""" safe_path = os.path.abspath(os.path.join(VAULT_PATH, relative_path)) if not safe_path.startswith(os.path.abspath(VAULT_PATH)): raise ValueError("Access denied: Attempted directory traversal.") return safe_path
@app.tool() def list_notes() -> List[str]: """ Lists all markdown files in the Obsidian vault. Use this tool to understand what notes are available. """ notes = [] if not os.path.exists(VAULT_PATH): return [f"Error: Obsidian vault path '{VAULT_PATH}' does not exist."] for root, _, files in os.walk(VAULT_PATH): for file in files: if file.endswith(".md"): # Get relative path from vault root rel_path = os.path.relpath(os.path.join(root, file), VAULT_PATH) notes.append(rel_path) return sorted(notes)
@app.tool() def read_note(note_path: str) -> str: """ Reads the full content of a specific markdown note by its relative path. Arguments: note_path: The relative path of the file (e.g., 'Projects/AI-App.md') """ try: resolved_path = secure_path_resolve(note_path) if not os.path.exists(resolved_path): return f"Error: File '{note_path}' not found." with open(resolved_path, "r", encoding="utf-8") as f: return f.read() except Exception as e: return f"Error reading file: {str(e)}"
@app.tool() def search_notes(query: str) -> List[Dict[str, Any]]: """ Performs a plain-text search across all notes in the vault. Returns matched files and the specific snippet containing the query. """ results = [] if not query: return [] query_regex = re.compile(re.escape(query), re.IGNORECASE) for root, _, files in os.walk(VAULT_PATH): for file in files: if file.endswith(".md"): full_path = os.path.join(root, file) rel_path = os.path.relpath(full_path, VAULT_PATH) try: with open(full_path, "r", encoding="utf-8") as f: for i, line in enumerate(f, 1): if query_regex.search(line): results.append({ "file": rel_path, "line": i, "snippet": line.strip() }) except Exception: # Silently skip unreadable files continue return results[:50] # Cap results at 50 for performance
if __name__ == "__main__":
# FastMCP uses standard input/output (stdio) to communicate with Claude
app.run(transport="stdio")
`
---
Step 3: Registering the Server in Claude Desktop
Claude Desktop uses a configuration file to know what local MCP servers to spin up when it launches.
You need to edit your claude_desktop_config.json file. Its location varies by operating system:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Open or create this file and add your Python server configuration. Make sure to replace the paths to match your local virtual environment, python binary, and Obsidian vault path:
`json
{
"mcpServers": {
"obsidian-vault": {
"command": "/Users/yourusername/claude-obsidian-mcp/.venv/bin/python",
"args": [
"/Users/yourusername/claude-obsidian-mcp/server.py"
],
"env": {
"OBSIDIAN_VAULT_PATH": "/Users/yourusername/Library/Mobile Documents/iCloud~md~obsidian/Documents/YourVaultName"
}
}
}
}
`
Note: If you run into issues on Windows, verify that your paths use double backslashes (`\\`) or forward slashes (`/`) so the JSON parser does not fail.
---
Step 4: Testing Your New Capabilities
Restart Claude Desktop. If configured correctly, you should see a small hammer icon in the bottom right corner of the chat input box. Clicking this icon will display your active tools: list_notes, read_note, and search_notes.
Now, test the connection with a natural language query:
> "Can you look through my active projects notes and summarise what my top priorities are for this week? Check my tasks folder if you need to."
Claude will determine that it needs to call list_notes, identify files that match (e.g., Projects/Active.md), execute read_note on those specific files, and synthesise an answer entirely locally.
No databases. No embedding pipelines. Just simple, deterministic, fast-acting tools.
---
Troubleshooting Common Issues
If the hammer icon does not appear, or if Claude returns an error when calling your server, check the following:
- Log Files: Claude Desktop writes detailed logs to
~/Library/Logs/Claude(macOS) or%USERPROFILE%\AppData\Local\Claude\Logs(Windows). Openmcp.logto see the exact stdout/stderr from your Python process. - Absolute Paths: Ensure you use absolute paths for your Python binary and script inside the JSON configuration file.
- Environment Variables: Ensure that the
OBSIDIAN_VAULT_PATHenvironment variable in the config points to the actual root of your Obsidian directory.
For more advanced debugging tips on Claude integration, check our dedicated troubleshooting guides at /platforms/claude/articles.
---
Next Steps: Adding Writes and Graph Navigation
Now that you have a working read-only server, you can expand its capabilities. You could add a write_note tool to allow Claude to log daily journals, or a backlink_search tool that parses markdown files to find wiki-style links ([[Note Name]]), letting Claude navigate your knowledge graph just like you do.
To master how to structure your prompts for these tools, visit our guide on creating clean /prompts that prevent the model from generating overly long responses.
Keep going
Build something with the prompt generator, decode the jargon in the glossary, or compare the tools on our platform deep-dives.