Obsidian MCP (模型上下文协议) 服务器
该项目实现了一个 Model Context Protocol (MCP) 服务器,用于连接 AI 模型与 Obsidian 知识库。通过这个服务器,AI 模型可以直接访问和操作 Obsidian 笔记,包括读取、创建、更新和删除笔记,以及管理文件夹结构。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"obsidian-mcp": {
"command": "obsidian-mcp",
"env": {
"OBSIDIAN_API_PORT": "27123",
"OBSIDIAN_API_TOKEN": "your_api_token",
"OBSIDIAN_VAULT_PATH": "/path/to/your/vault"
}
}
}
}
服务介绍
Obsidian MCP (Model Context Protocol) Server
English | Chinese
This project implements a Model Context Protocol (MCP) server for connecting AI models with the Obsidian knowledge base. Through this server, AI models can directly access and manipulate Obsidian notes, including reading, creating, updating, and deleting notes, as well as managing folder structures.
Features
- Seamless integration with the Obsidian knowledge base
- Support for reading, creating, updating, and deleting notes
- Support for creating, renaming, moving, and deleting folders
- Full-text search support
- Compliance with the Model Context Protocol specification
Prerequisites
- Node.js (v16 or higher)
- Obsidian desktop application
- Obsidian Local REST API plugin (needs to be installed in Obsidian)
Installation
- Clone this repository:
bash
git clone https://github.com/newtype-01/obsidian-mcp.git
cd obsidian-mcp
- Install dependencies:
bash
npm install
- Build the project:
bash
npm run build
Configuration
The server is configured via environment variables:
OBSIDIAN_VAULT_PATH: Path to the Obsidian vaultOBSIDIAN_API_TOKEN: API token for the Obsidian Local REST API pluginOBSIDIAN_API_PORT: Port number for the Obsidian Local REST API plugin (default is 27123)
You can set the environment variables as follows:
- Copy the
.env.examplefile to.envand edit the values:
bash
cp .env.example .env
- Edit the
.envfile and fill in your actual configuration:
OBSIDIAN_VAULT_PATH=/path/to/your/vault
OBSIDIAN_API_TOKEN=your_api_token_here
OBSIDIAN_API_PORT=27123
Note: The .env file contains sensitive information and has been added to .gitignore, so it will not be committed to version control.
Usage
Direct Usage
-
Ensure that Obsidian is running and the Local REST API plugin is installed and configured
-
Start the MCP server:
bash
npm start
- The server will communicate with the AI model via standard input/output
Deployment with Docker
Using Docker Compose (Recommended)
-
Ensure Docker and Docker Compose are installed
-
Copy and configure the environment file:
bash
cp .env.example .env
- Edit the
.envfile and fill in your actual configuration:
OBSIDIAN_VAULT_PATH=/path/to/your/vault
OBSIDIAN_API_TOKEN=your_api_token_here
OBSIDIAN_API_PORT=27123
- Build and start the container:
bash
docker-compose up -d
Using Docker Command
- Build the Docker image:
bash
docker build -t obsidian-mcp .
- Run the container:
bash
docker run -d
--name obsidian-mcp
--env-file .env
--network host
-v $(OBSIDIAN_VAULT_PATH):$(OBSIDIAN_VAULT_PATH)
obsidian-mcp
Note: When deploying with Docker, the Docker container needs to access the Obsidian instance and vault on the host. Ensure that the correct paths and ports are set in the .env file, and use network_mode: "host" or appropriate port mapping.
Configuring in MCP Client
Mainstream MCP clients typically require editing the configuration file to set up the MCP server. Here are some common ways to configure:
Using npx Method
json
{
"mcpServers": {
"obsidian-mcp": {
"command": "npx",
"args": [
"obsidian-mcp"
],
"env": {
// If you have already set up the .env file in the project directory, you can leave it empty
// Or you can set the environment variables directly here:
// "OBSIDIAN_VAULT_PATH": "/path/to/your/vault",
// "OBSIDIAN_API_TOKEN": "your_api_token_here",
// "OBSIDIAN_API_PORT": "27123"
}
}
}
}
Using Local Installation Method
json
{
"mcpServers": {
"obsidian-mcp": {
"command": "node",
"args": [
"/path/to/obsidian-mcp/build/index.js"
],
"env": {
// If you have already set up the .env file in the project directory, you can leave it empty
}
}
}
}
Using Docker Method
If you have already deployed the MCP server using Docker, you can configure the MCP client as follows:
json
{
"mcpServers": {
"obsidian-mcp": {
"command": "docker",
"args": [
"exec",
"-i",
"obsidian-mcp",
"npm",
"start"
],
"env": {
// The Docker container is already configured via the .env file or environment variables, so you can leave it empty here
}
}
}
}Note: The env section in the above configuration can be left empty, especially if you have already configured the relevant parameters through a .env file or Docker environment variables. If you wish to specify environment variables directly within the client configuration, you can fill in the corresponding key-value pairs in the env section.
Testing
The project includes a test script for verifying server functionality:
bash
node test-mcp.js
Supported Tools
MCP Server provides the following tools:
list_notes: List all notes in the knowledge baseread_note: Read the content of a specified notecreate_note: Create a new noteupdate_note: Update an existing notesearch_vault: Search for content within the knowledge basedelete_note: Delete a notemanage_folder: Manage folders (create, rename, move, delete)
Development
- Run the server in development mode using
npm run dev - Source code is located in the
srcdirectory
License
ISC
Contributions
Pull Requests and Issues are welcome!