Skip to main content
Glama
obsidian-brain-mcp
by kalana
README.md
# obsidian-brain-mcp

[![CI](https://github.com/kalana/obsidian-brain-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/kalana/obsidian-brain-mcp/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

A local [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server that lets AI agents
(Claude Code, Claude Desktop/Cowork, Cursor, and any other MCP client) work with your
[Obsidian](https://obsidian.md) vaults as a **second-brain knowledge graph**.

> **Status: early development (pre-0.1).** The read-only and graph tools work today; search and
> write tools are on the [roadmap](docs/ROADMAP.md). Expect breaking changes until `v0.1.0`.

## Why

Andrej Karpathy's [LLM wiki idea](https://gist.github.com/karpathy/442a6bf555914893e9891c11519de94f)
describes an agent that maintains a personal, interlinked markdown wiki: it ingests sources,
writes and links notes, and answers questions from the knowledge it has built up.

This project provides the plumbing for that idea, with one deliberate twist:

**The server does not define your wiki's structure. Your vault does.**

- The server is a **generic, safe gateway**. It understands markdown, YAML frontmatter, wikilinks,
  tags and folders, and nothing about any particular taxonomy.
- Each vault describes **its own** structure, naming rules and ingest workflow in plain files
  inside the vault (`CLAUDE.md`, `AGENTS.md`, `index.md`). The server serves those files to the
  agent (`get_vault_guide`) and the agent follows them.
- All "intelligence" (summarising, deciding where a note goes, linking) lives in the calling
  agent. The server never calls an LLM.

So you can run one server over several very different vaults (a research vault, a work log, a
reading list) and each keeps its own rules.

## Features

- Multiple vaults, each with a description agents use to pick the right one.
- Works directly on the filesystem: Obsidian does not need to be running; no plugins required.
- Obsidian-compatible link resolution: shortest-path names, `[[Note|alias]]`, `[[Note#Heading]]`,
  embeds `![[...]]`, frontmatter `aliases`, and links in frontmatter (e.g. `parent: "[[X]]"`).
- Link graph tools: outgoing links, backlinks, N-hop neighbourhoods, orphans, broken links.
- Safety first: every path is confined to its vault (no `..`, absolute paths or symlink escapes),
  `.obsidian/`, `.git/` and `.trash/` are always hidden, and you can mark folders read-only.
- Content hashes on every read, ready for safe optimistic-concurrency writes.

## Tools

| Tool                | What it does                                                                                                                                          |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `list_vaults`       | Lists configured vaults with their descriptions, note counts and guide files.                                                                         |
| `get_vault_guide`   | Returns the vault's own instructions (`CLAUDE.md`, `AGENTS.md`, `index.md`) and the latest lines of `log.md`. Agents should call this before writing. |
| `list_notes`        | Lists notes, filtered by folder, glob, tag or modified time; paginated.                                                                               |
| `read_note`         | Reads a note by path or by name: frontmatter, body, headings, links, tags, hash. Can return a single section.                                         |
| `get_links`         | Outgoing links and backlinks of a note, with the line each link appears on.                                                                           |
| `get_neighbors`     | Notes within N link-hops of a note (depth and size capped).                                                                                           |
| `find_orphans`      | Notes with no inbound and/or outbound links.                                                                                                          |
| `find_broken_links` | Wikilinks that point to notes that do not exist.                                                                                                      |
| `ping`              | Health check.                                                                                                                                         |

Planned: full-text search (BM25), frontmatter queries, and safe write tools (create, append,
patch section, update frontmatter, rename with link rewriting, delete to OS trash). See the
[roadmap](docs/ROADMAP.md).

## Quick start

Requirements: [Node.js](https://nodejs.org) 20 or newer.

The package is not yet published to npm, so install from source:

```bash
git clone https://github.com/kalana/obsidian-brain-mcp.git
cd obsidian-brain-mcp
npm install
npm run build
```

### 1. Create a config file

Copy the [example config](examples/vaults.example.yaml) to the default location and edit it:

| OS            | Default config path                                                     |
| ------------- | ----------------------------------------------------------------------- |
| macOS / Linux | `~/.config/obsidian-brain-mcp/vaults.yaml` (respects `XDG_CONFIG_HOME`) |
| Windows       | `%APPDATA%\obsidian-brain-mcp\vaults.yaml`                              |

You can also pass `--config <file>` or set `OBSIDIAN_BRAIN_CONFIG`.

```yaml
vaults:
  - name: research
    path: ~/Obsidian/Research
    description: >
      Research papers and course notes. Use for anything about ML theory or papers.
    readonly: ["sources/**"]
```

| Key           | Required | Default                            | Meaning                                                                    |
| ------------- | -------- | ---------------------------------- | -------------------------------------------------------------------------- |
| `name`        | yes      |                                    | Identifier agents pass to tools. Unique.                                   |
| `path`        | yes      |                                    | Vault folder. `~` expands; relative paths resolve against the config file. |
| `description` | no       | `""`                               | When an agent should choose this vault. Be specific.                       |
| `guide_files` | no       | `[CLAUDE.md, AGENTS.md, index.md]` | Files served by `get_vault_guide`.                                         |
| `log_file`    | no       | `log.md`                           | File whose latest lines are shown with the guide; `null` disables.         |
| `readonly`    | no       | `[]`                               | Globs that may be read but never written.                                  |
| `ignore`      | no       | `[]`                               | Extra globs to hide (`.obsidian/`, `.git/`, `.trash/` are always hidden).  |

Your config contains paths on your machine: keep it outside this repository (the default
location is) and never commit it.

### 2. Connect your MCP client

**Claude Code**

```bash
claude mcp add obsidian-brain -- node /absolute/path/to/obsidian-brain-mcp/dist/index.js
```

**Cursor / Claude Desktop** (`mcp.json` / `claude_desktop_config.json`)

```json
{
  "mcpServers": {
    "obsidian-brain": {
      "command": "node",
      "args": ["/absolute/path/to/obsidian-brain-mcp/dist/index.js"]
    }
  }
}
```

Add `"--config", "/path/to/vaults.yaml"` to `args` to use a non-default config.

### 3. Try it

Ask your agent: _"List my vaults, read the guide for `research`, and show me the notes connected
to `Transformers`."_

You can also explore the tools interactively with the
[MCP Inspector](https://github.com/modelcontextprotocol/inspector):

```bash
npx @modelcontextprotocol/inspector node dist/index.js
```

## Writing a vault guide

The guide is where your vault's "brain" lives. A minimal `CLAUDE.md` at the vault root might say:

```markdown
# Vault guide

- `raw/` holds untouched sources. Never edit it.
- `wiki/concepts/` holds one note per concept; `wiki/entities/` one per person, tool or paper.
- Every wiki note has frontmatter `parent: "[[...]]"` pointing to its topic note.
- When ingesting a source: summarise it into `wiki/`, link it from the relevant topic note,
  and append one line to `log.md`.
```

The server never interprets these rules; it hands them to the agent. Change the file and every
agent immediately follows the new conventions.

## Security model

- The server runs locally over stdio and makes **no network calls**.
- It only touches folders listed in your config. Every user-supplied path is resolved and checked
  to stay inside its vault (rejects `..`, absolute paths and symlinks that escape).
- `.obsidian/`, `.git/` and `.trash/` are never exposed. Use `ignore` to hide more and `readonly`
  to protect folders from future write tools.
- Logs go to stderr only (stdout is the MCP protocol channel).

Found a vulnerability? Please follow [SECURITY.md](SECURITY.md).

## Development

```bash
npm install
npm run build       # compile to dist/
npm test            # vitest
npm run lint        # eslint + prettier --check
npm run typecheck
npm run check       # lint + typecheck + tests (run before opening a PR)
```

Project layout:

```text
src/
  config/     config schema (zod) and YAML loader
  vault/      vault registry, safe path resolution, walking, reading, guides
  markdown/   note parser (frontmatter, headings, wikilinks, tags)
  graph/      link index, backlinks, neighbours, orphans, broken links
  tools/      one file per MCP tool (thin wrappers over the modules above)
test/
  fixtures/vault/   small synthetic vault used by the tests
```

See [CONTRIBUTING.md](CONTRIBUTING.md) for the workflow.

## Contributing

Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) and our
[Code of Conduct](CODE_OF_CONDUCT.md). Good first steps: pick an issue labelled
`good first issue`, or open an issue to discuss a new tool before building it.

## License

[MIT](LICENSE)