LODA MCP服务器
LLM优化文档访问 -Claude Desktop和Claude Code中用于令牌高效文档搜索的模型上下文协议服务器。
 ](https://nodejs.org/)  
______________________________________________________________________
什么是LODA?
矿脉 (LLM优化文档访问)是一种专为LLM如何使用文档而设计的搜索策略。LODA不返回原始匹配或任意块,而是理解文档结构并返回最相关的 *章节* 在您的代币预算范围内。
问题
当LLM处理大型文档时,他们面临着一个根本性的挑战:
| 传统方法 | 问题 |
|---|---|
| 加载整个文档 | 超出上下文限制 |
| 关键字搜索 | 没有相关性排名,返回太多 |
| RAG/矢量搜索 | 需要基础设施,延迟200-500ms |
| 基于块的检索 | 任意边界破坏一致性 |
我们发现了 “间隙区” 在25-35%的文档位置,传统智能检索实际执行 *更糟* 而不是暴力加载。
解决方案
LODA结合了轻量级技术来实现 矢量搜索质量 在 类似grep的速度:
┌─────────────────┐ ┌──────────────────────┐ ┌─────────────────┐
│ Large Document │────▶│ LODA Search Engine │────▶│ Relevant Sections│
│ (5000+ lines) │ │ • Bloom Filters │ │ within budget │
│ │ │ • Token Budget │ │ (~200 tokens) │
│ │ │ • Relevance Scoring │ │ │
└─────────────────┘ │ • Smart Caching │ └─────────────────┘
└──────────────────────┘结果:
- 70-95%的代币节省 与加载完整文档相比
- 1-5ms搜索延迟 (缓存)与RAG的200-500ms相比
- 零外部依赖 -无需矢量数据库
______________________________________________________________________
快速开始
1.安装
git clone https://github.com/patrickkarle/loda-mcp-server.git
cd loda-mcp-server
npm install2.配置克劳德桌面
查找您的配置文件:
- 视窗:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
将以下内容添加到文件中:
{
"mcpServers": {
"loda": {
"command": "node",
"args": ["/full/path/to/loda-mcp-server/document_access_mcp_server.js", "--mode=stdio"]
}
}
}3.配置克劳德代码
添加到您的项目 .claude/settings.json 或全球 ~/.claude/settings.json:
{
"mcpServers": {
"loda": {
"command": "node",
"args": ["/full/path/to/loda-mcp-server/document_access_mcp_server.js", "--mode=stdio"]
}
}
}4.使用它!
问克劳德:
“使用loda_search在api-docs.md中查找身份验证部分”
“在architecture.md中搜索500代币预算的部署说明”
______________________________________________________________________
LODA的工作原理
1.布隆过滤器消除
在评分之前,LODA使用 布隆过滤器 立即删除绝对不包含搜索词的部分。这种O(1)操作通常会消除80%以上的部分。
2.节感知解析
LODA尊重文档的结构。它理解markdown标题,并返回完整的逻辑部分,而不是任意的文本块。
3.相关性评分
每个候选部分的评分基于:
- 查询术语存在 内容(0.8基本分)
- 头球比赛奖金 (头球比赛+0.2)
- 多期保险 (所有术语权重相等)
4.代币预算选择
您指定一个令牌预算,LODA将返回最合适的部分:
// "I need info about auth, but only have 500 tokens of context"
{
query: "authentication",
contextBudget: 500
}5.积极的缓存
文档结构和布隆过滤器使用TTL缓存(默认60秒)。对同一文档的重复搜索速度快10倍以上。
______________________________________________________________________
api参考
loda_search
主要的搜索工具。
参数:
| 参数 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
documentPath | string | 是 | - | 文档路径(相对于暂存或绝对) |
query | string | 是 | - | 搜索关键字或短语 |
contextBudget | number | No | null | 要返回的最大令牌数(null=无限制) |
maxSections | number | 否 | 5 | 要返回的最大节数 |
请求示例:
{
"documentPath": "api-docs.md",
"query": "authentication oauth",
"contextBudget": 500,
"maxSections": 3
}示例响应:
{
"query": "authentication oauth",
"documentPath": "/path/to/api-docs.md",
"sections": [
{
"id": "section-5",
"header": "OAuth 2.0 Authentication",
"level": 3,
"score": 1.0,
"lineRange": [27, 41],
"tokenEstimate": 88
},
{
"id": "section-4",
"header": "API Key Authentication",
"level": 3,
"score": 0.8,
"lineRange": [15, 26],
"tokenEstimate": 66
}
],
"metadata": {
"totalSections": 21,
"candidatesAfterBloom": 5,
"scoredAboveZero": 3,
"returnedSections": 2,
"totalTokens": 154,
"budgetStatus": "SAFE",
"truncated": false,
"cacheHit": true
}
}预算状态值
| 状态 | 含义 |
|---|---|
UNLIMITED | 未指定预算 |
SAFE | 代币总额低于预算的80% |
WARNING | 代币总额在预算的80-100%之间 |
EXCEEDED | 超出预算(第一部分总是被退回) |
其他工具
| 工具 | 说明 |
|---|---|
list_document_sections | 获取文档的层次结构 |
read_section | 按ID和上下文读取特定部分 |
read_lines | 读取特定行范围 |
search_content | 基本正则表达式搜索(无LODA优化) |
______________________________________________________________________
分段目录
默认情况下,LODA在 staging/ 子目录:
loda-mcp-server/
├── staging/ ← Put documents here
│ ├── api-docs.md
│ ├── architecture.md
│ └── user-guide.md
└── document_access_mcp_server.js您还可以使用绝对路径搜索系统上的任何文档。
______________________________________________________________________
HTTP模式(开发/测试)
对于没有Claude的测试,请在HTTP模式下运行服务器:
node document_access_mcp_server.js --mode=http --port=49400然后用curl进行测试:
# Health check
curl http://localhost:49400/health
# List tools
curl http://localhost:49400/tools
# Search
curl -X POST http://localhost:49400/tools/loda_search \
-H "Content-Type: application/json" \
-d '{"documentPath": "api-docs.md", "query": "authentication"}'______________________________________________________________________
演出
| 指标 | 目标 | 已实现 |
|---|---|---|
| 搜索延迟(缓存) | \70% | 70-95% |
| 布隆过滤器效率 | >80% | ~85% |
| 缓存命中率 | >80% | ~90% |
______________________________________________________________________
测试
# Run all LODA tests
npm test
# Run specific component tests
npm test -- tests/loda_search_handler.test.js
# Run with coverage
npm test -- --coverage测试结果:46/46通过
| 组件 | 测试 | 状态 |
|---|---|---|
| token_estimator | 6 | ✅ |
| 相关性_得分手 | 8 | ✅ |
| 预算经理 | 6 | ✅ |
| 布隆过滤器 | 10 | ✅ |
| loda_index | 8 | ✅ |
| loda_search_handler | 8 | ✅ |
______________________________________________________________________
建筑
loda/
├── token_estimator.js # Pure token estimation (~4 chars/token)
├── relevance_scorer.js # Section relevance scoring
├── budget_manager.js # Token budget selection
├── loda_index.js # Cached document structure (TTL + LRU)
├── bloom_filter.js # O(1) section elimination
├── loda_search_handler.js # Main orchestrator
└── index.js # Module entry
document_access_mcp_server.js # MCP server with 5 tools______________________________________________________________________
研究与开发
该项目是使用 持续发展过程(CDP),一种强调可追溯性和质量门的13阶段方法。
我们为什么建造这个
在达到LODA之前,我们尝试了几种方法:
| 方法 | 为什么失败 |
|---|---|
| 语义分块 | 任意边界分割逻辑单元 |
| RAG+矢量搜索 | 单个文档访问的基础设施太多 |
| JIT Steg检索 | “间隙区”为25-35%,开销超过暴力 |
| 简单的Grep | 没有相关性排名,没有代币意识 |
LODA结合了每种方法的优点:节意识、快速消除、预算控制和零外部依赖。
研究文件
______________________________________________________________________
配置示例
克劳德桌面(Windows)
%APPDATA%\Claude\claude_desktop_config.json:
{
"mcpServers": {
"loda": {
"command": "node",
"args": ["C:/Users/YourName/loda-mcp-server/document_access_mcp_server.js", "--mode=stdio"]
}
}
}克劳德桌面(macOS/Linux)
~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"loda": {
"command": "node",
"args": ["/home/yourname/loda-mcp-server/document_access_mcp_server.js", "--mode=stdio"]
}
}
}克劳德代码(项目级)
.claude/settings.json:
{
"mcpServers": {
"loda": {
"command": "node",
"args": ["/path/to/loda-mcp-server/document_access_mcp_server.js", "--mode=stdio"]
}
}
}______________________________________________________________________
贡献
- 复刻仓库
- 创建要素分支
- 为新功能编写测试
- 提交附有文件的PR
______________________________________________________________________
许可证
MIT许可证-请参阅 许可证 了解详情。
______________________________________________________________________
致谢
______________________________________________________________________
由...制作🧠 对于需要高效阅读文档的LLM。
