Skip to main content
Glama
second-brain-mcp

second-brain-mcp

by nanthansr

second-brain-mcp

CI License: MIT Node >= 18

一个只读的 MCP 服务器,适用于任何 Obsidian 或纯 Markdown 仓库,检索协议由服务器强制执行,而不是在提示词中请求。

将它指向一个 Markdown 笔记文件夹,任何 MCP 客户端——Claude Code、Claude Desktop、Cursor 等——都可以通过四个受管工具查询该知识库。服务器在构造上无法写入,无法离开仓库目录,并且在达到硬性的页面读取预算后会切断会话。

实时会话:先索引,三次预算内读取,带引用的回答

为什么

个人知识库最终被焊死在单一工具上。笔记存放在 Obsidian 中,而能够使用这些笔记的 AI 助手却在别处,于是你只能复制粘贴。即便助手确实获得了文件访问权限,“请只读取你需要的内容”也只是一句礼貌请求,而非规则。

这个服务器修复了这两点:

  • 一个连接器,所有应用通用。 MCP 就是 AI 工具界的 USB-C——只需编写一次仓库连接器,任何 MCP 客户端都能使用它。

  • 协议即法律,而非建议。 索引优先检索、硬性页面读取预算、只读访问和路径沙箱均在代码中强制执行。存在的操作只有这些受管控的操作。

Related MCP server: obsidian-gate

安装

需要 Node.js 18 或更高版本。

选项 A - 通过 npm 安装

claude mcp add second-brain -- npx -y @nanthansr/second-brain-mcp /abs/path/to/your/vault

这一条命令即可将服务器注册到 Claude Code;npx 会自动获取并运行该软件包。其他客户端请参阅下面的配置块。

选项 B - 从源码安装

git clone https://github.com/nanthansr/second-brain-mcp
cd second-brain-mcp
npm install && npm run build
npm test   # 15-check integration suite - should end with SMOKE PASS
claude mcp add second-brain -- node /abs/path/to/second-brain-mcp/dist/index.js /abs/path/to/your/vault

Claude Desktop

添加到 claude_desktop_config.json(设置 → 开发者 → 编辑配置):

{
  "mcpServers": {
    "second-brain": {
      "command": "npx",
      "args": ["-y", "@nanthansr/second-brain-mcp", "/abs/path/to/your/vault"]
    }
  }
}

Cursor

将相同的配置块添加到 ~/.cursor/mcp.json(或 Cursor 设置 → MCP → 添加新服务器)。

手边没有仓库?

完全省略仓库参数,服务器就会提供其自带的虚构演示仓库(“Alex Rivera”)——适合在 30 秒内快速试用:

claude mcp add second-brain-demo -- npx -y @nanthansr/second-brain-mcp

指向你的 Obsidian 仓库

你的仓库就是一个文件夹——就是 Obsidian 提示“将文件夹作为仓库打开”时你选择的那一个。将该文件夹的绝对路径作为参数传入:

操作系统

示例

Windows

C:/Users/you/Documents/my-vault

macOS / Linux

/Users/you/Documents/my-vault

注意:

  • index.md 位于仓库根目录 可解锁索引优先流程(get_index):一个每篇笔记占一行的目录页。如果你没有它,一切仍能正常工作——模型会回退到 search_notes。

  • Obsidian 自身的配置(.obsidian/)以及任何其他点文件夹对服务器都是不可见的。

  • 服务器从不修改任何内容——运行期间 Obsidian 可以保持打开。

用法

连接后,直接提问即可。典型流程(来自一次对演示仓库的真实会话):

“Alex Rivera 正在做什么?Sam 是谁?” → get_index → read_note ×3(每次都会标注 read 1/5、read 2/5、read 3/5)→ 带引用的回答。

“这周我的仓库里有什么变化?” → list_recent(days: 7) → 按日期排列的列表,最新的在前。

“我把关于定价的笔记放在哪里了?” → search_notes(query: "pricing") → 匹配的页面及带行号的摘录,不消耗预算。

支持 MCP 提示(prompt)的客户端还可获得 vault-retrieval——一个斜杠命令模板,针对给定问题将模型固定到索引优先协议。

客户端获得的能力

类型

名称

作用

预算

工具

get_index

返回 index.md,每页一行的目录。先调用它。

免费

工具

search_notes

不区分大小写的搜索,返回页面及带行号的摘录

免费

工具

read_note

按仓库相对路径读取一个页面的完整内容

计入预算

工具

list_recent

最近 N 天内修改过的页面,最新的在前

免费

资源

vault://index

作为 MCP 资源的索引

免费

提示

vault-retrieval

将索引优先协议作为可复用的提示模板

-

预期流程模仿了一个细心的人使用 Wiki 的方式:先读目录,打开相关的一两页,然后带引用作答。定位成本低;读取有预算限制。

配置

设置

方式

默认值

仓库路径

第一个 CLI 参数,或 VAULT_PATH 环境变量

内置的 sample-vault/

页面读取预算

VAULT_READ_BUDGET 环境变量

每个会话 5 次

安全模型

  • 构造上只读。 代码库中不存在任何写入、编辑或删除工具。

  • 路径沙箱。 每个路径都会先用 path.resolve 进行规范化,然后对照仓库根目录检查——拒绝目录穿越尝试(../…)。只有 .md 文件可读。

  • 硬性页面预算。 在 N 次 read_note 调用(默认 5 次)之后,服务器会拒绝进一步读取,并告诉模型根据已有内容进行综合。失败的读取不消耗预算。

  • 大小上限。 笔记截断为 50KB;搜索结果和最近列表也设有上限。

  • 点文件夹会被跳过。 .obsidian、.git 及其他点文件夹均不可见。

  • 代码公开,数据不公开。 该仓库只包含服务器代码和一个虚构的演示仓库。你的真实仓库就是运行时挂载的任何文件夹;它永远不会离开你的机器。

常见问题

我的数据会离开我的机器吗? 不会。服务器作为 MCP 客户端的子进程在本地运行,从磁盘读取文件。它不包含任何网络代码。

它能修改或删除我的笔记吗? 不能。不存在任何写入工具。这是代码本身的特性,而非某项设置。

当模型达到预算上限时会发生什么? 第 6 次读取会返回一个错误,告诉模型根据已有的页面进行综合。新的对话拥有全新的预算。

为什么演示回答提到“Alex Rivera”? 因为你正在使用内置的虚构演示仓库。请将你自己的仓库路径作为第一个参数传入。

开发

npm run build   # tsc -> dist/
npm test        # build + 15-check smoke test (spawns the real server over stdio)

npm 测试输出:15 项检查,SMOKE PASS

冒烟测试使用 SDK 自带的客户端对接编译后的服务器——真实协议,无任何模拟。它验证了全部四个工具、资源、提示、路径穿越拒绝,以及读取预算会拒绝第 N+1 次读取。CI 在 Linux 和 Windows 上、Node 20 和 22 下运行它。

好奇为什么这样构建?请参阅 docs/design-notes.md——传输层、MCP 的三种原语、模式即提示(schemas-as-prompts),以及沙箱和预算决策。

路线图

  • 远程变体(可流式 HTTP),让仓库可从托管客户端访问,并带身份验证

  • 可选的按文件夹范围限制(只提供 wiki/,隐藏 journal/)

贡献

欢迎提交 Issue 和 PR。请保持这些不变式:没有写入工具,没有网络调用,冒烟测试保持通过且不被削弱。

许可证

MIT · 变更记录见 CHANGELOG.md

Available Tools

4 tools
get_indexGet the vault indexA

Returns index.md, the catalog of every page in the vault (one line each). ALWAYS call this first to locate relevant pages, then read only the 1-2 pages that matter. Does not count against the page budget.

NameRequiredDescriptionDefault

No parameters

TDQS

A4.5/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses the output behavior (one line per page) and adds a meaningful operational trait: 'Does not count against the page budget,' which is beyond what the schema or title conveys. It could mention side-effect-free/read-only nature, but the context strongly implies a safe read.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three short sentences deliver the core purpose, usage directive, and budget behavior in order of importance. No filler or redundant restating of the title.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a zero-parameter tool with no output schema, the description fully covers what the agent needs: what it returns, how to use it first, and why it is safe to invoke. There are no missing details that would prevent a correct call.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has zero parameters and schema coverage is 100%, so there are no parameter semantics to document. The description adds useful meaning about the returned content, which is more than necessary for a parameterless tool.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb ('Returns') and resource ('index.md'), and precisely defines the output as 'the catalog of every page in the vault (one line each).' This clearly differentiates it from the sibling tools like search_notes or read_note.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly directs the agent to 'ALWAYS call this first' and then 'read only the 1-2 pages that matter,' giving a clear workflow. It does not explicitly name search_notes or list_recent as alternatives, but the sequential guidance is strong enough to establish when this tool should be used.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

list_recentList recently updated pagesA

Lists pages modified in the last N days (default 7), newest first. Good for 'what changed lately'. Does not count against the page budget.

NameRequiredDescriptionDefault
daysNoLook-back window in days (default 7)

TDQS

A4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden and does disclose useful behavioral traits: a default look-back window, newest-first ordering, and that it does not consume page budget. It does not describe the returned page format or any limits beyond the schema, but for a simple read-only list tool this is solid transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two short sentences carry the core behavior, the primary use case, and a key operational constraint with no filler. The most important information is front-loaded, and every sentence earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple tool with one fully documented optional parameter and no output schema, the description covers the essential behaviors: what is listed, the time window, ordering, and budget impact. It could be more complete by describing what fields/details appear in the returned page list, but it is sufficient for an agent to select and invoke the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100% and the single 'days' parameter is already documented with type, range, and default. The description only repeats the default window, adding no new semantic meaning beyond what the schema already provides, so the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states a specific verb ('Lists') and resource ('pages'), with a defined time window and sort order ('last N days (default 7), newest first'). It does not explicitly name or differentiate itself from sibling tools like search_notes or get_index, but the 'recently modified' framing makes its distinct purpose reasonably clear.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives clear usage context with 'Good for what changed lately' and adds a practical benefit ('Does not count against the page budget'). However, it does not mention when not to use it or point to alternative sibling tools, so it stops short of full routing guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

read_noteRead one pageA

Returns the full content of one markdown page by vault-relative path (e.g. wiki/people/sam-okafor.md). Counts against the hard page budget of 5 reads per session - locate pages via get_index or search_notes first, then read only what matters.

NameRequiredDescriptionDefault
pathYesVault-relative path to a .md file

TDQS

A4.5/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and discloses a key non-obvious behavior: the hard page budget of 5 reads per session. It also clarifies that the tool returns full content. It could additionally mention error behavior for missing paths or confirm it is a pure read, but it is already meaningfully transparent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences with no filler. The first sentence establishes the core function and path format; the second adds the budget constraint and recommended preceding workflow. Every sentence earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a single-parameter read tool with no output schema, the description is complete: it states what is returned, how to address the resource, and a critical usage constraint. It also routes the agent to the right discovery tools before reading.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3. The description adds value with a concrete path example ('wiki/people/sam-okafor.md') and reinforces the vault-relative .md semantics, making the expected input format clearer to the agent.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb ('Returns the full content') and a precise resource ('one markdown page by vault-relative path'). With the title 'Read one page' and sibling tools like search_notes and list_recent, it is immediately distinguishable as a targeted read operation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It explicitly tells the agent to locate pages via get_index or search_notes first and to 'read only what matters', plus it warns about the hard 5-read budget. It does not explicitly mention list_recent or state when not to use this tool, so it falls just short of full exclusion guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

search_notesSearch the vaultA

Case-insensitive text search across every markdown page. Returns matching pages with line-numbered snippets. Use when the index does not answer 'where does this live'. Does not count against the page budget.

NameRequiredDescriptionDefault
queryYesText to search for (literal, not regex)
max_resultsNoMax pages to return (default 10, cap 30)

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the behavioral disclosure burden. It discloses case-insensitive matching, global scope, snippet return format, and the useful operational fact that it does not count against the page budget. It does not explicitly state read-only behavior, but this is strongly implied by 'search'.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three sentences, each carrying distinct value: the core behavior, the return format, and the usage trigger plus budget note. It is front-loaded and free of filler.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple two-parameter search tool with no output schema, the description covers scope, matching behavior, return shape, and when to use it. Nothing essential for correct invocation is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the parameters are already fully documented. The description adds context about case-insensitivity and scope but does not materially extend what the schema provides for query and max_results.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb ('search') and resource ('every markdown page'), with concrete details like case-insensitivity and line-numbered snippets. It is clearly distinct from sibling tools like get_index, read_note, and list_recent.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly says to use it 'when the index does not answer where does this live', giving a clear trigger condition. It does not enumerate exclusions or compare against read_note/list_recent, but the context is unambiguous enough for an agent to route correctly.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 4 tool updatesv0.1.0
    • First observedget_index
    • First observedlist_recent
    • First observedread_note
    • First observedsearch_notes

TDQS

A4.3/5.0

Scored across 4 tools

Disambiguation5/5

Each tool has a clearly distinct role: index for catalog lookup, search for text search, read for content retrieval, and list_recent for recency. The descriptions even specify when to prefer one over another, removing ambiguity.

Naming Consistency4/5

All tool names use snake_case with an imperative verb first, creating a predictable pattern. list_recent is slightly less parallel than list_recent_notes, but the deviation is minor and does not confuse the set.

Tool Count5/5

Four tools is well-scoped for a retrieval-focused note vault: discovery via index/search/recent and content access via read. Each tool serves a distinct workflow step with no redundancy.

Completeness4/5

The surface fully covers read-oriented workflows: locating notes, finding content by text, checking recent changes, and reading full pages. The only notable gap is write/edit operations, but the tool descriptions consistently frame this as a read-only vault interface.

Maintenance

ActivityStale
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    Provides read-only access to an Obsidian vault, enabling file listing, content reading, and text search across notes via MCP.
    4
    2
    Apache 2.0
  • F
    license
    Not graded
    quality
    C
    maintenance
    Enables MCP clients to search, read, list, and append to markdown notes in a local Obsidian vault or folder of .md files.
    -