大文件分析服务器

RLM MCP Server是一个实现MIT递归语言模型的服务,允许Claude Code分析超出其上下文窗口限制的大文件,无需API密钥。

  • by NextTokens
  • Python
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 ahmedm224/rlm-mcp

使用说明

RLM MCP服务器

使用克劳德代码分析10GB+文件 -不需要API密钥。

MCP服务器实现 麻省理工学院的递归语言模型 这使得Claude Code可以分析对于其上下文窗口来说太大的文件。

┌─────────────────────────────────────────────────────────────┐
│  "Find all errors in this 5GB log file"                     │
│                                                             │
│  Claude → writes Python → RLM executes → returns results    │
│                                                             │
│  Result: 78% fewer tokens, same accuracy                    │
└─────────────────────────────────────────────────────────────┘

快速开始

1.安装:

pip install rlm-mcp

2.配置克劳德代码 (~/.claude/settings.json):

{
  "mcpServers": {
    "rlm": {
      "command": "rlm-mcp"
    }
  }
}

3.使用它:

Load /var/log/syslog and find all kernel errors

就是这样。Claude自动使用RLM进行大文件分析。


为什么选择RLM?

问题 传统 RLM解决方案
10GB日志文件 ❌ 与上下文不符 ✅ 外部加载,通过Python查询
令牌使用情况 📈 ~12500个令牌 📉 ~2700个代币(减少78%)
复杂分析 ❌ 仅限于grep模式 ✅ 完整的Python(正则表达式、统计数据、聚合)

真实基准

使用Claude Code Opus 4.5在300KB的系统日志上进行测试:

┌───────────┬──────────────┬───────────────┬─────────┐
│  Method   │ Input Tokens │ Output Tokens │  Total  │
├───────────┼──────────────┼───────────────┼─────────┤
│ Grep/Read │ ~10,000      │ ~2,500        │ ~12,500 │
│ RLM       │ ~1,500       │ ~1,200        │ ~2,700  │
└───────────┴──────────────┴───────────────┴─────────┘

Both methods found identical results.
RLM used 78% fewer tokens.

科学

基于 递归语言模型 来自MIT CSAIL:

“我们建议将长上下文视为通过Python REPL进行交互的‘外部环境’…” — Alex L. Zhang,Tim Kraska,Omar Khattab(麻省理工学院),2025

论文结果

基准 传统 RLM
S-NIAH(800万代币) 39.3% 96.0%
乌龙茶 36.2% 56.7%

运作原理

┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│   Claude Code   │────▶│   RLM Server    │────▶│  Python REPL    │
│   (The Brain)   │◀────│   (MCP)         │◀────│  (Execution)    │
└─────────────────┘     └─────────────────┘     └─────────────────┘

1. You ask: "Find errors in this huge log"
2. Claude loads file via rlm_load_file()
3. Claude writes Python: re.findall(r'ERROR.*', context)
4. RLM executes on full file (outside Claude's context)
5. Only results return to Claude
6. Claude answers with findings

关键见解: 克劳德是大脑,RLM是双手。无需API密钥-使用您的Claude Code订阅。


可用工具

工具 说明
rlm_load_file 加载大容量文件
rlm_load_multiple_files 将多个文件作为字典加载
rlm_execute_code 在加载的内容上运行Python
rlm_get_variable 获取变量的值
rlm_session_info 检查会话状态
rlm_reset_session 清除会话内存

何时使用

┌─────────────────────────────┬────────────────────┐
│          Use Case           │    Recommended     │
├─────────────────────────────┼────────────────────┤
│ Small files (<50KB)         │ Direct read        │
│ Single pattern search       │ Grep               │
│ Large files (>200KB)        │ ✅ RLM             │
│ Complex analysis/statistics │ ✅ RLM             │
│ Multi-pattern correlation   │ ✅ RLM             │
│ Aggregation/counting        │ ✅ RLM             │
│ Cross-file analysis         │ ✅ RLM             │
└─────────────────────────────┴────────────────────┘

示例会话

# Load a large log
>>> rlm_load_file("/var/log/app.log")
File loaded: 2,847,392 chars

# Search for errors
>>> rlm_execute_code("""
import re
errors = re.findall(r'ERROR.*', context)
print(f"Found {len(errors)} errors")
""")
Found 156 errors

# Analyze patterns
>>> rlm_execute_code("""
from collections import Counter
types = re.findall(r'ERROR.*?\] (\w+)', context)
print(Counter(types).most_common(5))
""")
[('Connection', 67), ('Database', 43), ('Timeout', 28)]

安全

  • 30秒超时 --失控代码自动终止
  • 进程隔离 --使用多处理
  • 输出截断 --防止内存问题

需求

  • Python 3.10+
  • 支持MCP的Claude代码
  • 不需要API密钥

链接

  • github: https://github.com/ahmedm224/rlm-mcp
  • 纸张: https://arxiv.org/abs/2512.24601
  • 问题: https://github.com/ahmedm224/rlm-mcp/issues

引用

@article{zhang2025recursive,
  title={Recursive Language Models},
  author={Zhang, Alex L. and Kraska, Tim and Khattab, Omar},
  journal={arXiv preprint arXiv:2512.24601},
  year={2025}
}

许可证

麻省理工学院©艾哈迈德·阿里