localgate
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@localgatesearch my local notes and PDFs for project ideas and show the top relevant snippets"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
LocalGate
LocalGate 是一个隐私优先的本地检索网关:把你自己电脑上分散的笔记、PDF、 DOCX、源码、聊天记录导出和图片(本地 OCR)统一建立本机索引,通过 **MCP Server(stdio)+ HTTP API(仅回环)**供本地 AI Agent 调用。
数据不出本机:解析、分块、向量嵌入、检索全部本地执行;索引只写入你 配置的本地目录。
只读红线:对你的文件只读,绝不编辑/创建/删除/重命名白名单内的文件。
默认零扫描:发行版配置的白名单为空——不添加白名单,一个文件都不会被索引。
零强制依赖:核心只用 Python 标准库,离线可用。
不适合的场景:需要云端同步/多人协作的检索;让数据出本机的 RAG 服务; 作为笔记编辑器或聊天界面(它刻意不做这些)。
平台:Linux / macOS / Windows,Python 3.10+。
1. 安装
从源码安装(推荐放入虚拟环境):
python -m pip install . # 核心零第三方依赖
python -m pip install ".[yaml,pdf]" # 可选:更完整的 YAML 解析与 PDF 抽取安装后提供 localgate 命令;也可以不经安装直接运行 python main.py ...。
Related MCP server: bigos
2. 最小配置
当前目录没有 config.yaml 时,程序使用安全的内置默认值(空白名单、
仅回环、索引写入 ./data)。要真正开始检索,创建一份配置:
cp config.yaml myconfig.yaml编辑 myconfig.yaml,把你要检索的目录加入白名单(其他默认值已经安全):
paths:
whitelist:
- /home/me/Notes # 换成你自己的目录;支持 ~/ 展开
- ~/Documents/vault说明:
相对路径(如
data_dir: ./data)一律相对于配置文件所在目录解析,与 启动时的工作目录无关;blacklist优先级高于whitelist;embedding.backend默认local(内置哈希嵌入,离线、确定性); 若改为ollama,只允许本机回环地址(如http://127.0.0.1:11434)。 配置加载时会做严格校验:远程 IP、非回环 DNS 解析、https、URL 用户信息、 非常规路径等一律拒绝(fail closed),并把地址重写为解析后的字面 IP, 防止 DNS rebinding。
3. 运行
localgate serve -c myconfig.yaml # 启动网关:HTTP API + 文件监听 + 自检守护
localgate index -c myconfig.yaml # 一次性扫描白名单建索引后退出
localgate status -c myconfig.yaml # 打印网关状态 JSON
localgate mcp -c myconfig.yaml # 运行 stdio MCP Server(供 Agent 拉起)不加 -c 时读取 ./config.yaml;仍找不到则使用内置默认值(空白名单,
只读服务,索引文档数为 0 并打印告警)。
4. 接入 MCP 客户端
MCP Server 通过 stdio 与客户端通信,把工具调用代理到本机网关(默认
http://127.0.0.1:8770)。客户端配置示例(.mcp.json /
claude_desktop_config.json):
{
"mcpServers": {
"localgate": {
"command": "localgate",
"args": ["mcp"]
}
}
}从源码运行可用:"command": "python3", "args": ["/path/to/localgate/main.py", "mcp"]。
协议支持矩阵:MCP 协议版本 2025-06-18、2025-03-26、2024-11-05
(初始化时与客户端协商,按官方规范回退到服务端最新版本)。已通过 MCP
官方 Python SDK 的客户端完成端到端握手测试;未对全部第三方客户端逐一
验证,遇到问题请附带客户端名称与版本提 issue。
工具:
工具 | 说明 |
| 混合检索(BM25 + 向量融合),返回片段与路径 |
| 索引健康:文档/分块数、自检状态、白名单 |
| 按 doc_id 取回文档元数据与分块 |
5. HTTP API(默认仅绑定 127.0.0.1:8770)
服务端校验 Host 必须是回环地址、Origin 若存在必须是回环来源
(防 DNS rebinding 与跨站请求),JSON POST 接口要求
Content-Type: application/json。
端点 | 说明 |
| 存活检查(自检循环用它自 ping) |
| 最小只读状态面板(索引/进度/错误,HTML 已转义) |
| 索引统计、监听与自检状态、生效配置 |
|
|
| 文档元数据与分块; |
| 最近自检 JSONL 记录(1 ≤ lines ≤ 1000) |
| 最近服务 JSONL 记录(同上) |
| 触发一次白名单扫描;返回真实调度状态 |
POST /api/rescan 的响应是可观察的执行状态,例如:
{"rescan_started": true, "mode": "watcher", "reason": ""}watcher 线程存活:
mode: "watcher",请求进入其下一轮;watcher 未启用/已停止:直接启动一次性后台扫描(
mode: "oneshot");已有扫描在跑:
rescan_started: false,原因写明。
进度与完成情况通过 GET /api/status 的 ingest.scanning 与
watcher.last_pass 观察;空白名单时 rescan 明确拒绝(reason: "whitelist is empty; nothing to scan"),绝不假成功。
错误约定:参数/校验错误返回 4xx 与简短消息;内部错误统一返回
{"error": "internal server error"},详细堆栈只写入本地结构化日志。
6. OCR 与嵌入
OCR:
ocr.mode: auto时按 tesseract → macOS Vision(首次用系统 swiftc 在本地编译助手,缓存于索引目录bin/)→ 跳过并计数的顺序降级, 绝不联网。配置里的语言标签是 BCP-47(如zh-Hans),Vision 直接使用; 传给 tesseract 前会映射为chi_sim+eng风格的语言码。嵌入:
local后端为纯本地哈希嵌入(离线、确定性、无模型下载);ollama后端调用本机 Ollama(地址强制回环,禁用跟随重定向)。
7. 自检循环
服务启动后,自检守护按配置间隔(默认 300 秒)执行 7 项检查:文件源、 索引完整性、性能指标、嵌入健康、服务存活、资源阈值、安全自动优化 (孤儿清理/段合并/单文件重试)。每轮写一条 JSONL 结构化日志;连续出错 按指数退避降频;白名单根目录暂时不可访问(如外置卷未挂载)时保留索 引不清空,只有可确认的文件删除才会移除对应索引条目。
8. 故障排查
现象 | 处理 |
启动即告警 "whitelist is empty" | 正常。把你的目录加入 |
| 嵌入地址必须能解析到本机回环;远程地址一律拒绝 |
文件改了但检索结果没更新 | watcher 轮询有间隔;或 |
OCR 全部 | 未安装 tesseract 且(非 macOS 或无 swiftc);属预期降级,图片仍会建立索引记录 |
索引疑似损坏 | 重启服务即可:加载器容忍坏行并记录,自检会定位并单文件重建 |
端口被占用 | 换 |
9. 开发与测试
python -m pip install -e .[dev]
python -m pytest tests --cov=localgate # 单元 + 安全边界测试(覆盖率报告)
python tests/run_scenarios.py # 端到端场景套件(真实子进程服务)
python -m ruff check localgate tests main.py
python -m mypy
python -m build && python -m twine check dist/*测试全部使用临时目录与动态端口,不依赖开发者机器上的路径或既有索引。
10. 卸载
python -m pip uninstall localgate
# 索引与日志是本地数据,不会被包管理器删除;确认无用后手动删除:
# rm -rf ./data ./logs11. 文档与社区
许可证:LICENSE(MIT)
安全策略与漏洞报告:SECURITY.md
贡献指南:CONTRIBUTING.md
行为准则:CODE_OF_CONDUCT.md
变更记录:CHANGELOG.md
支持渠道与边界:SUPPORT.md
GitHub 标签:local-rag mcp-server ollama privacy-first vector-search agent-tool local-index
Available Tools
3 toolslocalgate_get_documentB
Fetch one indexed document's metadata and chunk texts by doc_id.
| Name | Required | Description | Default |
|---|---|---|---|
| doc_id | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full burden of behavioral disclosure. "Fetch" implies a read-only operation and the return contents are mentioned (metadata and chunk texts), but there is no explicit statement about side effects, permissions, rate limits, pagination, or error behavior.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
A single sentence with no filler; the core action, resource, return content, and key parameter are front-loaded efficiently.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple one-parameter read tool with no output schema and no annotations, the description covers the basic purpose and the returned fields. However, it omits sibling-routing guidance and parameter format details, leaving some gaps for an agent choosing between document retrieval and search.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%, so the description must compensate for the single undocumented parameter. Saying "by doc_id" identifies the parameter's role as the document identifier, but it adds no format, matching rules, or example beyond the parameter name itself.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description uses a specific verb ("Fetch") and resource ("one indexed document's metadata and chunk texts") with a clear scope ("by doc_id"). This distinguishes it clearly from sibling tools localgate_search and localgate_status without needing to open the schema.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance is given about when to use this tool instead of localgate_search or localgate_status, nor about prerequisites or exclusions. The description only states what it does, leaving usage inference to the agent.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
localgate_searchB
Hybrid (full-text + vector) search over the user's local indexed files: notes, PDFs, docx, source code, chat exports, OCR'd images. All data stays on this machine.
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | search query | |
| top_k | No | max results (default from config) |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full behavioral burden. It does add genuinely useful non-obvious context — the retrieval is hybrid and all data stays local — but omits whether the call is read-only, what happens when nothing is indexed, latency/cost characteristics, and the shape of results.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two sentences, no filler, with the core action stated first and the corpus/privacy detail following. Every clause earns its place.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple 2-parameter, no-output-schema search tool this is nearly adequate, but it never indicates what a result contains (paths, snippets, scores) or how results relate to the localgate_get_document follow-up, leaving a small but real gap.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100% for both parameters, so the baseline of 3 applies. The description adds no syntax, ranking, or defaulting detail beyond what 'query' and 'top_k' already state in the schema.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description gives a specific verb+resource ('Hybrid search over the user's local indexed files') and even names the retrieval mechanism (full-text + vector) and the corpus (notes, PDFs, docx, source code, chat exports, OCR'd images). It is clearly distinct from localgate_status and localgate_get_document without naming them, so it falls just short of the explicit sibling differentiation a 5 requires.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
There is no when-to-use guidance at all: nothing says to call this first and then retrieve full documents via localgate_get_document, nor whether localgate_status must be checked to confirm the index exists. The agent must infer routing from the sibling names alone.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
localgate_statusA
Index health: doc/chunk counts, self-check status, whitelist.
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden. It does disclose what the call surfaces (counts, self-check status, whitelist), which is meaningful for a zero-parameter tool, but it never states that it is a side-effect-free read or whether whitelist output is sensitive configuration data.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
A single front-loaded fragment with no filler; the resource leads and the returned fields follow as a compact list. Nothing could be removed without losing information.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
With no output schema, the description sensibly enumerates the return contents, which is the key thing an agent needs. Minor gaps remain around authentication requirements and what 'self-check status' concretely reports, but for a zero-param status call this is close to sufficient.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The tool takes zero parameters and the schema confirms an empty object, so the baseline is 4. There are no arguments whose semantics could be clarified.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Names the resource (index health) and enumerates the concrete signals returned: doc/chunk counts, self-check status, whitelist. The verb is only implied by the 'status' name, but the tool is unambiguously distinct from the search and get_document siblings, which retrieve content rather than report index state.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Usage is implied rather than stated: 'Index health' tells an agent this is a diagnostic/monitoring call, but there is no explicit guidance on when to reach for it versus search or get_document, and no preconditions or alternatives are named.
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.
3 tool updates
v0.1.0- First observed
localgate_get_document - First observed
localgate_search - First observed
localgate_status
TDQS
Scored across 3 tools
Each tool targets a distinct operation: search performs discovery, get_document retrieves full content by id, and status reports index health. There is no overlap in purpose or selection ambiguity.
All tools share the same localgate_ prefix and use snake_case consistently. The verb/noun structure (search, get_document) is predictable, with only status being a natural noun exception.
Three tools is well-scoped for a focused local search server. Each tool covers a core need—querying, retrieving, and monitoring the index—without redundant or bloated operations.
The surface covers the essential read-only lifecycle: searching, fetching a document by id, and checking index status. Minor gaps like listing available documents or triggering a reindex may exist, but agents can work around them via search.
Maintenance
Related MCP Connectors
Securely search and manage workspace context files for AI agents and teams.
Search your knowledge bases from any AI assistant using hybrid RAG.
Cloud or self-hosted knowledge for AI agents: hybrid search, reranking, GraphRAG, scoped MCP tools.
Universal persistent memory and knowledge retrieval layer for AI agents and LLMs.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to index and search local files, websites, GitHub repos, and packages with hybrid AI-powered retrieval, all locally through IDE chat.Apache 2.0
- AlicenseNot gradedqualityFmaintenanceEnables fully local, cross-lingual retrieval over documents and source code by indexing files and providing search and ingest tools, with all data staying on the machine.GPL 2.0
- AlicenseAqualityCmaintenanceEnables local-first hybrid knowledge retrieval from authorized Markdown and plain-text files, combining full-text and vector search with reranking and traceable source references via a single search tool.1MIT
- FlicenseNot gradedqualityAmaintenanceEnables AI agents and MCP hosts to search and question a local, hybrid-indexed corpus of scattered notes, docs, and chat logs, returning section-level citations rather than whole files.-