Skip to main content
Glama

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

Related MCP server: MCP-RLM

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

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 šŸš€

Available Tools

17 tools
rlm_clear_sessionClear SessionA
DestructiveIdempotent

Clear all data from a session (contexts, variables, history).

Inputs: session_id.

rlm_create_sessionCreate SessionA

Create a new isolated RLM session.

Use this when you need multiple independent processing contexts. Most use cases can use the default session.

Inputs: no named parameters.

rlm_decompose_contextDecompose ContextA
Read-onlyIdempotent

Split context into chunks using various strategies.

Strategies:

  • fixed_size: Fixed character chunks with overlap

  • by_lines: Chunk by number of lines

  • by_paragraphs: Split on double newlines

  • by_sections: Split on markdown headers

  • by_regex: Split on custom pattern

  • by_sentences: Split into sentences

Returns chunk metadata (indices, offsets). Use rlm_get_chunks to retrieve content.

Inputs: overlap, pattern, strategy, chunk_size, +4 more.

rlm_execute_codeExecute CodeA

Execute JavaScript code in the session's REPL environment.

Available functions:

  • print(...args) - Output text

  • getContext(id) - Get context content

  • getContextMetadata(id) - Get context metadata

  • len(str), slice(str,s,e), split(str,sep), join(arr,sep)

  • search(pattern,text,flags), findAll(pattern,text), replace(text,pattern,repl)

  • range(start,end,step), map(arr,fn), filter(arr,fn), reduce(arr,fn,init)

  • setVar(name,value), getVar(name), listVars()

  • setAnswer(content,ready), getAnswer()

  • JSON.parse(), JSON.stringify()

Use this for custom data manipulation and aggregation.

Inputs: code (required), session_id.

rlm_find_allFind All OccurrencesA
Read-onlyIdempotent

Find all occurrences of a substring (faster than regex for simple searches).

Returns character offsets of all matches.

Inputs: substring (required), context_id, session_id, case_sensitive.

rlm_get_answerGet AnswerA
Read-onlyIdempotent

Get the current answer state.

Returns the content and whether it's marked as ready/complete.

Inputs: session_id.

rlm_get_chunksGet Specific ChunksA
Read-onlyIdempotent

Retrieve content of specific chunks by index.

Use after rlm_decompose_context to get the actual content of chunks you want to process. You can request multiple chunks at once (up to 50).

Inputs: chunk_indices (required), overlap, strategy, chunk_size, +2 more.

rlm_get_context_infoGet Context InfoA
Read-onlyIdempotent

Get metadata and preview of a loaded context.

Returns:

  • Length, line count, word count

  • Detected structure type (json, csv, markdown, code, etc.)

  • Optional content preview

Use this to understand the context before deciding how to process it.

Inputs: context_id, session_id, preview_length, include_preview.

rlm_get_session_infoGet Session InfoA
Read-onlyIdempotent

Get information about a session including loaded contexts and variables.

Inputs: session_id.

rlm_get_statisticsGet Context StatisticsB
Read-onlyIdempotent

Get detailed statistics about a context.

Returns length, line/word/sentence/paragraph counts, and averages.

Inputs: context_id, session_id.

rlm_get_variableGet VariableA
Read-onlyIdempotent

Retrieve a variable from the session.

Inputs: name (required), session_id.

rlm_load_contextLoad ContextA
Idempotent

Load text content into the RLM session for processing.

This is typically the first step in RLM processing. Load your long context here, then use other tools to decompose, search, and analyze it.

The context is stored in the session and can be referenced by its ID in other tools.

Example workflow:

  1. rlm_load_context - Load your document

  2. rlm_get_context_info - Understand structure and size

  3. rlm_decompose_context - Split into manageable chunks

  4. rlm_search_context - Find relevant sections

  5. rlm_read_context - Read specific portions

  6. rlm_set_answer - Build up your response

Inputs: context (required), context_id, session_id.

rlm_read_contextRead Context PortionA
Read-onlyIdempotent

Read a specific portion of the context.

Modes:

  • chars: Read by character offsets (start, end)

  • lines: Read by line numbers (start, end)

Use this to examine specific sections without loading the entire context.

Inputs: end, mode, start, context_id, +1 more.

rlm_search_contextSearch ContextA
Read-onlyIdempotent

Search context using regex patterns.

Returns matches with surrounding context and line numbers. Use this to find relevant sections before reading in detail.

Examples:

  • Pattern: "error|warning" - Find all errors and warnings

  • Pattern: "function\s+\w+" - Find function definitions

  • Pattern: "TODO|FIXME" - Find code comments

Inputs: pattern (required), flags, context_id, session_id, +3 more.

rlm_set_answerSet AnswerA
Idempotent

Set or update the answer for the current RLM task.

Call this to build up your answer incrementally:

  • ready=false: Store partial/intermediate answer

  • ready=true: Mark answer as complete/final

The answer can be retrieved later with rlm_get_answer.

Inputs: content (required), ready, session_id.

rlm_set_variableSet VariableA
Idempotent

Store a variable in the session for later use.

Use this to save intermediate results during RLM processing.

Inputs: name (required), value, session_id.

rlm_suggest_strategySuggest Decomposition StrategyA
Read-onlyIdempotent

Get a suggested decomposition strategy based on the context's structure.

Analyzes the content type and size to recommend the best chunking approach.

Inputs: context_id, session_id.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.1/5.0

    Scored across 17 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: loading context, retrieving metadata, reading portions, decomposing, fetching chunks, searching, executing code, managing variables, managing answers, and session management. No two tools are interchangeable, and overlapping tools like rlm_search_context and rlm_find_all are differentiated by regex vs. substring search.

    Naming Consistency5/5

    All tool names follow a consistent rlm_<verb>_<noun> pattern with snake_case (e.g., rlm_load_context, rlm_get_context_info, rlm_decompose_context). Verbs and nouns are clear and predictable, making the API easy to navigate.

    Tool Count4/5

    With 17 tools, the set is slightly above the ideal 3-15 range, but the count is justified by the comprehensive workflow: context loading, analysis, decomposition, search, code execution, variable storage, answer management, and session lifecycle management. Each tool adds meaningful functionality.

    Completeness5/5

    The tool surface covers the full RLM processing lifecycle: load context, inspect structure, read specific sections, decompose into chunks, retrieve chunks, search, manipulate via code, store intermediate variables, build answers incrementally, and manage sessions. There are no obvious gaps or dead ends for the stated purpose.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Enables LLMs to chat with long PDFs using a reasoning-based, tree-structured document index that navigates content like a human would, without requiring vector databases or hitting context limits.
      10
      332 npm
      411
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      An implementation of the Recursive Language Models architecture that enables AI agents to process massive documents by programmatically decomposing them into sub-queries. It allows for cost-effective and accurate reasoning across millions of tokens by treating long-form data as an external environment for root and worker models.
      11
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Implements the Recursive Language Model pattern, enabling LLMs to process arbitrarily long contexts through session-based document management, on-demand chunking, BM25 search, and artifact storage.
      12
      1
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides recursive language model capabilities to AI assistants, enabling efficient exploration of large contexts through iterative Python code execution.
      1
      -