RLM MCP Server

RLM MCP Server

Enables any LLM to process arbitrarily long contexts through recursive decomposition, without requiring external LLM APIs.

Category
访问服务器

README

RLM MCP Server v2.0

Recursive Language Model Infrastructure Server - Enables ANY LLM to process arbitrarily long contexts through recursive decomposition.

🎯 Key Design Principle

No external LLM API required!

This server provides infrastructure only - your MCP client's LLM performs all the reasoning. This means:

  • ✅ Works with any LLM (Claude, GPT, Llama, Gemini, local models, etc.)
  • ✅ No API keys needed
  • ✅ No additional costs
  • ✅ Full control over the reasoning process
  • ✅ Cross-platform (Windows, macOS, Linux)
infographic compare-binary-horizontal-simple-fold
data
  title RLM Architecture Comparison
  items
    - label Traditional Approach
      desc Server calls external LLM API
      icon mdi:server-network
    - label This Server (v2.0)
      desc Client LLM does all reasoning
      icon mdi:brain

How It Works

The RLM pattern treats long contexts as external data that the LLM interacts with programmatically:

infographic sequence-steps-simple
data
  title RLM Processing Flow
  items
    - label 1. Load
      desc Load long context into server
    - label 2. Analyze
      desc Get structure and statistics
    - label 3. Decompose
      desc Split into manageable chunks
    - label 4. Process
      desc LLM reasons over chunks
    - label 5. Aggregate
      desc Combine into final answer

Your client's LLM uses the provided tools to:

  1. Load context - Store arbitrarily long text
  2. Analyze - Understand structure and size
  3. Decompose - Split into chunks using various strategies
  4. Search - Find relevant sections with regex
  5. Execute code - Manipulate data with JavaScript
  6. Build answer - Incrementally construct the response

Installation

# Clone or navigate to project
cd rlm-mcp-server

# Install dependencies
npm install

# Build
npm run build

# Run
npm start

No environment variables needed!

MCP Client Configuration

Claude Desktop (Windows)

Edit %APPDATA%\Claude\claude_desktop_config.json:

{
  "mcpServers": {
    "rlm": {
      "command": "node",
      "args": ["C:\\path\\to\\rlm-mcp-server\\dist\\index.js"]
    }
  }
}

Claude Desktop (macOS/Linux)

Edit ~/.config/claude/claude_desktop_config.json:

{
  "mcpServers": {
    "rlm": {
      "command": "node",
      "args": ["/path/to/rlm-mcp-server/dist/index.js"]
    }
  }
}

Alma

Add to your MCP server configuration:

{
  "rlm-mcp-server": {
    "command": "node",
    "args": ["/path/to/rlm-mcp-server/dist/index.js"]
  }
}

Available Tools

Context Management

Tool Description
rlm_load_context Load text content into session
rlm_get_context_info Get metadata and preview
rlm_read_context Read portion by chars or lines

Decomposition

Tool Description
rlm_decompose_context Split into chunks (multiple strategies)
rlm_get_chunks Retrieve specific chunk contents
rlm_suggest_strategy Get recommended chunking strategy

Search

Tool Description
rlm_search_context Search with regex patterns
rlm_find_all Find all substring occurrences

Code Execution

Tool Description
rlm_execute_code Run JavaScript in REPL
rlm_set_variable Store variable in session
rlm_get_variable Retrieve variable

Answer Management

Tool Description
rlm_set_answer Set/update answer (partial or final)
rlm_get_answer Get current answer state

Session & Utilities

Tool Description
rlm_create_session Create isolated session
rlm_get_session_info Get session details
rlm_clear_session Clear session data
rlm_get_statistics Get detailed statistics

Decomposition Strategies

Strategy Description Best For
fixed_size Fixed character chunks with overlap General use, JSON
by_lines Chunk by number of lines Code, CSV, logs
by_paragraphs Split on double newlines Articles, documents
by_sections Split on markdown headers Markdown docs
by_regex Split on custom pattern Custom formats
by_sentences Split into sentences Dense text

REPL Environment Functions

When using rlm_execute_code:

// Output
print(...args)                    // Print to output

// Context
getContext(id)                    // Get full content
getContextMetadata(id)            // Get metadata

// String Operations
len(str)                          // Length
slice(str, start, end)            // Substring
split(str, sep)                   // Split to array
join(arr, sep)                    // Join to string
trim(str), lower(str), upper(str) // String transforms

// Regex
search(pattern, text, flags)      // Find matches
findAll(pattern, text)            // All matches with index
replace(text, pattern, repl)      // Replace

// Array
range(start, end, step)           // Generate range
map(arr, fn)                      // Transform
filter(arr, fn)                   // Filter
reduce(arr, fn, init)             // Reduce
sort(arr, fn)                     // Sort (copy)
unique(arr)                       // Remove duplicates
chunk(arr, size)                  // Split array

// Variables
setVar(name, value)               // Store
getVar(name)                      // Retrieve
listVars()                        // List all

// Answer
setAnswer(content, ready)         // Set answer
getAnswer()                       // Get answer state

// JSON
JSON.parse(str)                   // Parse
JSON.stringify(obj, indent)       // Stringify

Example Workflow

Here's how an LLM might process a very long document:

1. Load the document:
   rlm_load_context(context="...", context_id="doc")

2. Analyze structure:
   rlm_get_context_info(context_id="doc")
   → Returns: 500,000 chars, markdown, 12,000 lines

3. Get strategy suggestion:
   rlm_suggest_strategy(context_id="doc")
   → Returns: by_sections (markdown content)

4. Decompose:
   rlm_decompose_context(context_id="doc", strategy="by_sections")
   → Returns: 45 chunks (sections)

5. Search for relevant sections:
   rlm_search_context(context_id="doc", pattern="climate change")
   → Returns: Matches in chunks 3, 7, 12, 23

6. Get those chunks:
   rlm_get_chunks(chunk_indices=[3, 7, 12, 23])
   → Returns: Content of those sections

7. Process each chunk (LLM reasoning)
   Build understanding from each section...

8. Save intermediate results:
   rlm_set_variable(name="findings", value=[...])

9. Aggregate into final answer:
   rlm_set_answer(content="Based on analysis...", ready=true)

Use Cases

Long Document Analysis

  • Research paper summarization
  • Legal document review
  • Code repository understanding

Multi-Document Processing

  • Literature review
  • Comparative analysis
  • Information aggregation

Log Analysis

  • Error pattern detection
  • Timeline reconstruction
  • Anomaly identification

Data Extraction

  • Entity extraction from large texts
  • Pattern mining
  • Content classification

Architecture

┌─────────────────────────────────────────────────────────┐
│                     MCP Client                          │
│  ┌─────────────────────────────────────────────────┐   │
│  │                Your LLM                          │   │
│  │  (Claude, GPT, Llama, Gemini, etc.)             │   │
│  │                                                  │   │
│  │  Performs all reasoning and recursive calls     │   │
│  └─────────────────────────────────────────────────┘   │
│                         │                               │
│                    MCP Protocol                         │
│                         │                               │
└─────────────────────────┼───────────────────────────────┘
                          │
┌─────────────────────────┼───────────────────────────────┐
│              RLM MCP Server (this)                      │
│                         │                               │
│  ┌──────────────────────┴──────────────────────────┐   │
│  │              Tools Layer                         │   │
│  │  load, read, decompose, search, execute, etc.   │   │
│  └─────────────────────────────────────────────────┘   │
│                         │                               │
│  ┌──────────────────────┴──────────────────────────┐   │
│  │            Services Layer                        │   │
│  │  ┌─────────────┐  ┌────────────────────────┐   │   │
│  │  │  Session    │  │  Context Processor     │   │   │
│  │  │  Manager    │  │  (decompose, search)   │   │   │
│  │  └─────────────┘  └────────────────────────┘   │   │
│  └─────────────────────────────────────────────────┘   │
│                                                         │
│  No external dependencies - pure JavaScript             │
└─────────────────────────────────────────────────────────┘

Running Modes

Stdio (Default)

For MCP clients like Claude Desktop:

node dist/index.js

HTTP

For remote access or testing:

node dist/index.js --http --port=3000

Endpoints:

  • POST /mcp - MCP protocol
  • GET /health - Health check
  • GET /info - Server info

Why This Design?

The original RLM paper describes a system where the LLM calls sub-LLMs recursively. However, in the MCP context:

  1. The client already has an LLM - No need for another API
  2. Cost efficiency - No additional API calls/costs
  3. Flexibility - Works with any LLM
  4. Control - The client controls the reasoning
  5. Simplicity - Pure infrastructure, no API keys

The tools in this server provide everything needed for the LLM to implement RLM patterns itself.

Contributing

Contributions welcome! Areas of interest:

  • Additional decomposition strategies
  • Performance optimizations
  • New REPL helper functions
  • Documentation improvements

License

MIT License

References


Built for the long-context AI community 🚀

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选