Skip to main content
Glama
bborbe

Semantic Search MCP

by bborbe

语义搜索

对 Markdown 文件进行语义搜索。通过含义而非仅仅关键词查找相关笔记。在创建新笔记前检测重复内容。

支持两种服务器传输方式:

  • stdio MCP — 用于 Claude Code 集成(每个会话一个进程)

  • HTTP — 在一个端口上结合了 MCP-over-HTTP 和 REST;所有客户端共享一个预热进程

功能

  • 使用 sentence-transformers 进行语义搜索

  • 重复/相似笔记检测

  • 通过文件监视器自动更新索引

  • 支持多目录

  • 内联标签提取 (#tag-name)

Related MCP server: mcp-recall-md

安装

仅 CPU 安装 — 推荐用于 macOS(任何 Mac,Apple Silicon 或 Intel)以及 没有 NVIDIA GPU 的 Linux/Windows。可节省约 5GB 的 CUDA 二进制文件。在 macOS 上,Apple GPU (MPS) 仍会通过 PyTorch 内置的 MPS 后端自动检测并使用 —— “CPU” 标签仅指没有 CUDA,并不指运行时的计算设备。

uv tool install --index https://download.pytorch.org/whl/cpu \
  git+https://github.com/bborbe/semantic-search

CUDA 安装 — 仅适用于 带有专用 NVIDIA GPU 的 Linux/Windows。不适用于 macOS(Mac 不支持 NVIDIA CUDA)。

uv tool install git+https://github.com/bborbe/semantic-search

升级

uv tool upgrade semantic-search

服务器模式

stdio MCP (每个会话的 Claude Code)

每个 Claude Code 会话生成一个进程。简单,但每个会话都会加载其自己的约 400 MB–1 GB 的模型副本。

claude mcp add -s project semantic-search \
  --env CONTENT_PATH=/path/to/vault \
  -- \
  uvx --from git+https://github.com/bborbe/semantic-search semantic-search-mcp

可用工具:

  • search_related(query, top_k=5) — 查找语义相关的笔记

  • check_duplicates(file_path) — 检测重复/相似笔记

HTTP (所有客户端共享)

单个长期运行的进程在 /mcp 提供 MCP-over-HTTP,并在 /search、/duplicates、/health、/reindex 提供 REST 服务。所有 Claude Code 会话和 REST 客户端共享一个预热索引器。

CONTENT_PATH=/path/to/vault semantic-search-http --host 127.0.0.1 --port 8321

通过 MCP 配置将 Claude Code 指向它:

{
  "mcpServers": {
    "semantic-search": {
      "type": "http",
      "url": "http://127.0.0.1:8321/mcp"
    }
  }
}

REST 端点:

端点

方法

描述

/mcp

POST

MCP-over-HTTP (Claude Code)

/search?q=...&top_k=5

GET

语义搜索

/duplicates?file=...&threshold=0.85

GET

查找重复笔记

/health

GET

带有索引统计信息的健康检查

/reindex

GET/POST

强制重建索引

查询示例:

# Search
curl 'http://127.0.0.1:8321/search?q=kubernetes+deployment'

# Find duplicates
curl 'http://127.0.0.1:8321/duplicates?file=notes/my-note.md'

# Health check
curl 'http://127.0.0.1:8321/health'

Claude Code 插件

此仓库也作为 Claude Code 市场插件发布,包含用于设置、搜索和研究的命令。

安装

claude plugin marketplace add bborbe/semantic-search
claude plugin install semantic-search

更新

claude plugin marketplace update semantic-search
claude plugin update semantic-search@semantic-search

快速入门

# One-shot interactive setup: installs the binary, writes the launchd/systemd
# unit, registers the MCP server in your Claude config.
/semantic-search:configure

# Search indexed markdown
/semantic-search:search kubernetes deployment

# Multi-step research across results
/semantic-search:research kafka backup strategy

命令

命令

描述

/semantic-search:configure

将 semantic-search-http 安装为 launchd (macOS) 或 systemd-user (Linux) 服务,并在 Claude Code 中注册 MCP 服务器

/semantic-search:search <query> [top_k]

通过运行中的 MCP 服务器进行语义搜索

/semantic-search:research <topic>

多步研究 —— 搜索、分类、阅读顶级来源、综合

后台运行

对于生产环境的使用,请将 semantic-search-http 作为后台服务运行,以便每个 Claude Code 会话(以及任何 REST 客户端)共享一个预热进程。

平台

指南

macOS (launchd)

docs/launchd-service.md

Linux (systemd)

docs/systemd-user-service.md

快速示例 (macOS):

launchctl load ~/Library/LaunchAgents/com.github.bborbe.semantic-search-http.plist

快速示例 (Linux):

systemctl --user enable --now semantic-search-http.service

CLI 命令

无需运行服务器的一次性命令:

# Search
CONTENT_PATH=/path/to/vault semantic-search search "kubernetes deployment"

# Find duplicates
CONTENT_PATH=/path/to/vault semantic-search duplicates path/to/note.md

二进制文件

二进制文件

用途

semantic-search-http

组合式 HTTP 服务器 —— MCP 在 /mcp + REST 端点。运行一次,跨客户端共享。

semantic-search-mcp

stdio MCP 服务器 —— 每个 Claude Code 会话一个。在未设置 HTTP 服务时使用。

semantic-search

仅 CLI —— search 和 duplicates 一次性命令。

配置

环境变量

变量

描述

默认值

CONTENT_PATH

要索引的目录(多个目录用逗号分隔)

./content

LOG_LEVEL

日志级别 (DEBUG, INFO, WARNING, ERROR)

INFO

多目录

通过用逗号分隔路径来索引多个目录:

CONTENT_PATH=/path/to/vault1,/path/to/vault2,/path/to/docs

所有目录会被一起索引,并作为一个统一的索引进行搜索。

工作原理

首次运行时会下载一个小型的嵌入模型(约 90MB)并索引您的 markdown 文件(典型知识库耗时 <1 秒)。当文件通过文件系统监视器发生更改时,索引会自动更新。

索引内容

每个 markdown 文件都使用加权组件进行索引:

组件

权重

备注

文件名

3x

Frontmatter title

3x

Frontmatter tags

2x

与内联标签合并

Frontmatter aliases

2x

内联标签 (#tag)

2x

从正文中提取

第一个 H1 标题

2x

正文内容

1x

前 500 个单词

开发

# Clone
git clone https://github.com/bborbe/semantic-search
cd semantic-search

# Install dev dependencies
make install

# Run checks
make check

# Run tests
make test

许可证

BSD 2-Clause 许可证 —— 参见 LICENSE。

Available Tools

3 tools
check_duplicatesA

Find notes that are potential duplicates of the given file.

ParametersJSON Schema
NameRequiredDescriptionDefault
file_pathYesPath to the file (absolute or relative to content directory)

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.6/5.0
Behavior2/5

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

No annotations are provided, and the description does not disclose behavioral details beyond the basic 'Find' action—such as how duplicates are determined, whether the operation is read-only, or any side effects. The burden falls on the description, which is minimal.

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?

The description is a single, front-loaded sentence with no wasted words, making it highly concise and easy to parse.

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?

Given the tool's simplicity (one parameter, output schema present), the description conveys the main purpose adequately. However, it lacks guidance on when to use vs alternatives, which is somewhat a gap but not critical for such a straightforward tool.

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% for the single parameter, so the schema fully describes file_path. The description adds no extra semantic meaning beyond what the schema already states.

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 uses a specific verb ('Find') and resource ('notes that are potential duplicates of the given file'), clearly distinguishing it from sibling tools like search_related and get_content.

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

Usage Guidelines3/5

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

The description implies usage for checking duplicates but does not explicitly state when to use this tool versus alternatives, nor any exclusions or prerequisites.

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

get_contentB

Fetch the content of a file from the indexed vault.

ParametersJSON Schema
NameRequiredDescriptionDefault
pathYesFile path (absolute or relative to an indexed root)
queryNoSearch string to find the best-matching line (only used when snippet=True)
snippetNoIf True, return a snippet around the best-matching line instead of the full file
context_linesNoNumber of lines before and after the match to include (default 20)

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

B3.3/5.0
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It only states the primary action but does not disclose edge cases (e.g., file not found, path resolution), or behavior around optional parameters like snippet and query despite their existence in the schema. This leaves significant behavioral aspects undisclosed.

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?

The description is a single, tightly worded sentence that immediately conveys the core purpose. There is no fluff or redundancy, and the information is front-loaded. For the tool's purpose, this length is appropriately concise.

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

Completeness3/5

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

The tool has moderate complexity with optional snippet/query parameters and an output schema, and the schema covers parameter semantics. However, the description is thin on operational context, such as how path resolution works or when to use snippet mode. While not incomplete for basic selection, the description itself needed to provide more contextual glue; the schema partially compensates, but gaps remain.

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 a baseline of 3 is appropriate. The description itself does not add any parameter semantics beyond the schema, but the schema already documents each parameter (path, query, snippet, context_lines) clearly. The description neither enhances nor detracts from what the schema provides.

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 clearly states the tool's action ('Fetch the content of a file') and the resource ('indexed vault'), using a specific verb and resource. It distinguishes itself from sibling tools 'search_related' and 'check_duplicates' by focusing on direct content retrieval rather than search or duplication checks.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It does not mention related tools or any exclusionary conditions (e.g., 'use search_related instead when looking for related content'). The intended usage is only implicitly derived from the tool's name and action.

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. 3 tool updatesv0.1.0
    • First observedcheck_duplicates
    • First observedget_content
    • First observedsearch_related

TDQS

A4/5.0

Scored across 3 tools

Disambiguation5/5

Each tool serves a distinct purpose: semantic search, duplicate detection, and content retrieval. There is no overlap or ambiguity between them.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern (search_related, check_duplicates, get_content) using snake_case. The naming is predictable and readable.

Tool Count5/5

Three tools is an appropriate, focused set for a semantic search server. Each tool earns its place and the scope is well-defined.

Completeness5/5

The server covers the core needs of semantic search: finding related notes, detecting duplicates, and retrieving content. There are no missing operations that would hinder its stated purpose.

Maintenance

ActivityActive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

Appeared in Searches