Model Context Protocol (MCP) is an open standard created by Anthropic in November 2024 that enables LLM-powered software to connect with external services. They describe it as the “USB-C port for AI applications” - which is apt.
The most powerful advantage of MCP servers over traditional APIs is dynamic tool discovery and context-awareness. This means that if you adhere to the protocol, your AI assistant can automatically discover and utilize new capabilities without any additional integration work. Instead of hard-coding specific endpoints or behaviors, the AI dynamically adapts to whatever tools or data sources the MCP server makes available.
In this article, we’ll build a lightweight MCP server for Obsidian (markdown note taking app) that allows Cursor and other MCP clients to read and write to your knowledge base. We’ll see that we only need a few simple tools to enable a lot of functionality. For example you could ask:
- “Create a new note for standup tomorrow describing the code changes I’ve made today” (this should also run a git command if you’re using Cursor)
- “Check what todos I have related to refactoring and implement them” (also relevant to Cursor)
- “Draft a plan to help me prioritise my todos”
Protocol Basics
MCP consists of:
- Servers: Lightweight programs that expose specific capabilities through the protocol
- Clients: Applications like Cursor that maintain connections to servers and benefit from access to external services.
The protocol works through a standardized message exchange system using JSON-RPC 2.0, with a transport layer handling the actual communication: stdio for local servers like this one, and Streamable HTTP (which replaced the older HTTP with SSE transport) for remote ones.
Setting Up Your Project
To get started, you’ll need:
- Node.js and npm/yarn
- TypeScript
- The MCP SDK (
@modelcontextprotocol/sdk) - Zod for schema validation
This guide was last tested on 31 October 2026 with @modelcontextprotocol/sdk 1.32.2, zod 4.6.7, typescript 7.0.2, @types/node 26.6.6 and Node.js 24.3.0, so those are the versions pinned below.
Create a new TypeScript project and install the dependencies:
mkdir obsidian-mcp-server && cd obsidian-mcp-server
npm init -y
npm pkg set type=module
npm install @modelcontextprotocol/sdk@1.32.2 zod@4.6.7
npm install --save-dev typescript@7.0.2 @types/node@26.6.6Then add a tsconfig.json:
{
"compilerOptions": {
"target": "ES2022",
"module": "Node16",
"moduleResolution": "Node16",
"outDir": "./build",
"rootDir": "./src",
"types": ["node"],
"strict": true,
"skipLibCheck": true
},
"include": ["src/**/*"]
}The types line is new. TypeScript 7 no longer picks up @types/node by itself, so without it the build fails on process and every node: import.
Server Implementation
Our MCP server will have two main components:
- Read functionality to access vault files
- Write functionality to create & update vault files
Note: since Obsidian is essentially a directory of Markdown files, your MCP server can directly interact with these notes at the file-system level, allowing immediate reading, editing, and creation of notes without needing to run or interface directly with the Obsidian application itself.
The core of our server is quite simple - we initialize an MCP server and set up a transport layer. This goes in src/index.ts:
#!/usr/bin/env node
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { registerReadTools } from "./read.js";
import { registerWriteTools } from "./write.js";
// Get vault path from command line arguments
const vaultPath = process.argv[2];
if (!vaultPath) {
console.error("Usage: obsidian-mcp-server /path/to/your/vault");
process.exit(1);
}
// Initialize the server
const server = new McpServer({
name: "obsidian",
version: "1.0.0",
});
registerReadTools(server, vaultPath);
registerWriteTools(server, vaultPath);
// Connect to transport
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
// stdout carries the protocol, so log to stderr
console.error("Obsidian MCP Server running on stdio");
}
main().catch((error) => {
console.error(error);
process.exit(1);
});Creating MCP Tools
The power of MCP comes from the tools we create. Each tool has a name, description, schema, and handler function. The description is very important as it helps the LLM understand precisely what the tool does and when to use it.
One of the challenges in this use case is searching through the knowledge base to find information. Embedding / vector search is a bit too involved, but I found keyword search to be much too restrictive. Instead we will create a tool for listing all the file names in the vault and another tool that can read the contents of multiple files at once, given their file names. The assumption here is that the file names are indicative of their contents - which clearly isn’t always true but works pretty well.
Reading Operations
Our server implements three main tools that read the given Obsidian vault. These go in src/read.ts:
import fs from "node:fs";
import path from "node:path";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
const toResult = (text: string) => ({
content: [{ type: "text" as const, text }],
});
// Skips dot folders, which keeps .obsidian and .trash out of the results
function listFiles(vaultPath: string): string[] {
return fs
.readdirSync(vaultPath, { recursive: true, encoding: "utf8" })
.filter((file) => !file.split(path.sep).some((part) => part.startsWith(".")))
.filter((file) => fs.statSync(path.join(vaultPath, file)).isFile())
.sort();
}
export function registerReadTools(server: McpServer, vaultPath: string) {
server.registerTool(
"getAllFilenames",
{
description:
"Get a list of all filenames in the Obsidian vault. Useful for retrieving their contents later.",
},
() => toResult(listFiles(vaultPath).join("\n")),
);
server.registerTool(
"readMultipleFiles",
{
description:
"Retrieves the contents of specified files from the Obsidian vault. Accepts exact paths, partial names or case-insensitive matches.",
inputSchema: { filenames: z.array(z.string()) },
},
({ filenames }) => {
const files = listFiles(vaultPath);
const contents = filenames.map((name) => {
const target = name.toLowerCase();
const match =
files.find((file) => file.toLowerCase() === target) ??
files.find((file) => file.toLowerCase().includes(target));
return match
? `# File: ${match}\n\n${fs.readFileSync(path.join(vaultPath, match), "utf8")}`
: `# File: ${name}\n\nFile not found in vault.`;
});
return toResult(contents.join("\n\n"));
},
);
server.registerTool(
"getOpenTodos",
{
description:
"Retrieves all open TODO items from markdown files in the Obsidian vault.",
},
() => {
const todos = listFiles(vaultPath)
.filter((file) => file.endsWith(".md"))
.flatMap((file) =>
fs
.readFileSync(path.join(vaultPath, file), "utf8")
.split("\n")
.filter((line) => line.trimStart().startsWith("- [ ]"))
.map((line) => `${file}: ${line.trim()}`),
);
return toResult(todos.join("\n") || "No open TODOs found.");
},
);
}I use Obsidian to track todos so that last tool might not be relevant to you.
Writing Operations
For writing, we have a single powerful tool, which goes in src/write.ts:
import fs from "node:fs";
import path from "node:path";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
export function registerWriteTools(server: McpServer, vaultPath: string) {
server.registerTool(
"updateFileContent",
{
description:
"Creates or overwrites a file in the Obsidian vault. filePath is relative to the vault root.",
inputSchema: { filePath: z.string(), content: z.string() },
},
({ filePath, content }) => {
const root = path.resolve(vaultPath);
const fullPath = path.resolve(root, filePath);
// The model chooses this path, so never let it climb out of the vault
if (!fullPath.startsWith(root + path.sep)) {
return {
content: [{ type: "text", text: `Outside the vault: ${filePath}` }],
isError: true,
};
}
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
fs.writeFileSync(fullPath, content);
return { content: [{ type: "text", text: `Wrote ${filePath}` }] };
},
);
}Don’t skip the path check. Without it, ../../.ssh/authorized_keys is a perfectly valid filePath.
Registering Tools with the MCP Server
Each tool goes through server.registerTool, which takes a name, a config object and a handler. The SDK turns the Zod fields in inputSchema into the JSON schema clients see, validates incoming arguments against them and types the handler’s arguments for you. Older examples use server.tool, which still runs but is deprecated.
The two calls in index.ts are all the wiring we need:
registerReadTools(server, vaultPath);
registerWriteTools(server, vaultPath);Design Considerations
- Simplicity Over Complexity: We’ve focused on a few powerful tools rather than many specialised ones. You’ll find that by combining these tools you can get a lot done.
- Flexible Matching: The reading functionality is forgiving, allowing clients to find files even with imperfect queries
- Directory Creation: When writing files, the server automatically creates any necessary directories.
Using the Server
Add a build script to your package.json:
{
"scripts": {
"build": "tsc && node -e \"require('fs').chmodSync('build/index.js', '755')\""
},
"bin": {
"obsidian-mcp-server": "./build/index.js"
}
}Testing
The easiest way to test any MCP server is using the official visual MCP inspector tool. Which lets you debug MCP servers by running the tools in isolation.
To run the inspector (tested with 2.13.0):
npx @modelcontextprotocol/inspector@2.13.0 node build/index.js /path/to/your/vaultIf you’d rather stay in the terminal, --cli lists the tools without opening a browser:
npx @modelcontextprotocol/inspector@2.13.0 --cli node build/index.js /path/to/your/vault --method tools/listUsage with Cursor & Claude Desktop
First make sure you’ve built the server:
npm run buildTo use your MCP server with Claude Desktop add it to claude_desktop_config.json. Use absolute paths, because the app doesn’t launch the server from your project folder:
{
"mcpServers": {
"obsidian": {
"command": "node",
"args": [
"/absolute/path/to/obsidian-mcp-server/build/index.js",
"/path/to/your/vault"
]
}
}
}For Cursor, put the same mcpServers block in ~/.cursor/mcp.json, or in .cursor/mcp.json if you only want it in one project.
The build, the tools and the inspector were all run for this guide, with the tools called from an MCP SDK client. The Cursor and Claude Desktop configs follow each app’s current docs but weren’t run in either app.
Extending and Comparing
While our implementation is intentionally lightweight, you could extend it with:
- Advanced search capabilities (to deal with poorly named files)
- Support for Obsidian-specific features like links and tags
For comparison, the project jacksteamdev/obsidian-mcp-tools offers a more feature-rich approach as an Obsidian plugin. Our standalone server is simpler but has the advantage of direct filesystem access without requiring the Obsidian application to be running.