rlm-mcp-server

rlm-mcp-server

Provides recursive language model capabilities to AI assistants, enabling efficient exploration of large contexts through iterative Python code execution.

Category
访问服务器

README

RLM MCP Server

"The difference between the Enterprise's computer and a Culture Mind is that the Mind doesn't try to hold everything in immediate consciousness—it knows how to efficiently explore vast data stores."

A containerized MCP (Model Context Protocol) server that provides Recursive Language Model capabilities to any AI assistant.

What is RLM?

Based on the paper "Recursive Language Models" from MIT CSAIL, RLM treats large contexts as external environments that can be explored programmatically rather than stuffed into a context window.

Instead of cramming a 500-page document into context, RLM teaches the model to write Python code that explores the document—searching, parsing, counting, extracting—building up understanding iteratively until it can answer your question.

Quick Start

With Docker Compose (recommended)

# Clone and enter directory
cd rlm-mcp-server

# With OpenAI
OPENAI_API_KEY=sk-xxx docker compose up

# With local llama.cpp server (running on port 8080)
RLM_API_BASE=http://host.docker.internal:8080/v1 docker compose up

# With Ollama
RLM_API_BASE=http://host.docker.internal:11434/v1 RLM_MODEL=llama3.2 docker compose up

With Docker directly

# Build
docker build -t rlm-mcp-server .

# Run with OpenAI
docker run -e OPENAI_API_KEY=sk-xxx -p 8765:8765 rlm-mcp-server

# Run with local LLM
docker run \
  -e RLM_API_BASE=http://host.docker.internal:8080/v1 \
  --add-host host.docker.internal:host-gateway \
  -p 8765:8765 \
  rlm-mcp-server

Integration with Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "rlm": {
      "command": "docker",
      "args": [
        "run", "--rm", "-i",
        "--network", "host",
        "-e", "OPENAI_API_KEY",
        "rlm-mcp-server",
        "python", "src/server.py", "--transport", "stdio"
      ],
      "env": {
        "OPENAI_API_KEY": "your-key-here"
      }
    }
  }
}

See examples/ for more configuration options including local LLM setups.

Available Tools

Session Management

Tool Description
rlm_load_context Load text content into a session
rlm_load_file Load a file into a session
rlm_list_sessions List active sessions
rlm_close_session Close a session to free memory

Querying

Tool Description
rlm_query Ask a question about loaded context (iterative exploration)
rlm_quick_query One-shot: load and query in one call
rlm_execute_code Execute Python directly against context (power user)

Configuration

Tool Description
rlm_config View current server configuration

Usage Examples

Load and query a large document

Human: Load this 200-page PDF transcript and find all mentions of "quarterly revenue"

Claude: I'll use RLM to explore this large document.

[Uses rlm_load_context to load the document]
[Uses rlm_query with question "Find all mentions of quarterly revenue with surrounding context"]

Based on exploring the document, I found 47 mentions of quarterly revenue...

Analyze a codebase

Human: Here's our entire codebase (500 files). What authentication methods are used?

Claude: I'll load this into RLM and explore it programmatically.

[Uses rlm_load_context with the codebase]
[Uses rlm_query to explore authentication patterns]

After exploring the codebase, I found three authentication methods:
1. JWT tokens in /api/auth/...
2. OAuth2 in /integrations/...
3. API keys in /external/...

Environment Variables

Variable Default Description
RLM_MODEL gpt-4o-mini Primary model for RLM
RLM_SUB_MODEL Same as RLM_MODEL Model for iterations (can be cheaper)
RLM_MAX_ITERATIONS 15 Max exploration iterations
RLM_API_BASE OpenAI API endpoint (for local models)
RLM_API_KEY / OPENAI_API_KEY - API key
RLM_SUB_API_BASE Same as RLM_API_BASE Separate endpoint for sub-model

Cost Optimization

You can use a cheaper/local model for the iterative exploration while using a more capable model for initialization:

RLM_MODEL=gpt-4o \
RLM_SUB_MODEL=gpt-4o-mini \
docker compose up

Or use a local model for iterations entirely:

RLM_MODEL=gpt-4o \
RLM_SUB_MODEL=local-model \
RLM_SUB_API_BASE=http://host.docker.internal:8080/v1 \
docker compose up

How It Works

  1. Load Context: Your massive document/codebase is stored in a session
  2. Question: You ask a question about the content
  3. Exploration: The LLM writes Python code to explore the context
  4. Iteration: Code executes, LLM sees results, writes more code
  5. Answer: When confident, LLM provides final answer

The REPL environment has access to:

  • CONTEXT - the full loaded text
  • re - regex module
  • json - JSON module
  • Counter, defaultdict - from collections
  • Standard Python builtins

Architecture

┌─────────────────────────────────────────────────────────┐
│                    Claude Desktop                        │
│                         or                               │
│                    Any MCP Client                        │
└────────────────────────┬────────────────────────────────┘
                         │ MCP Protocol
                         ▼
┌─────────────────────────────────────────────────────────┐
│                   RLM MCP Server                         │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐  │
│  │   Sessions   │  │   RLM Core   │  │  REPL Env    │  │
│  │   Storage    │  │   Engine     │  │  (Python)    │  │
│  └──────────────┘  └──────────────┘  └──────────────┘  │
└────────────────────────┬────────────────────────────────┘
                         │ OpenAI-compatible API
                         ▼
┌─────────────────────────────────────────────────────────┐
│           LLM Backend (OpenAI / Local / Ollama)          │
└─────────────────────────────────────────────────────────┘

Development

# Install dependencies
pip install -r requirements.txt

# Run locally (stdio mode for testing)
cd src && python server.py --transport stdio

# Run tests
pytest tests/

Transferring to Offline Lab (Mojoverse)

  1. Build the image on Cybertron:

    docker save rlm-mcp-server:latest | gzip > rlm-mcp-server.tar.gz
    
  2. Transfer to Mojoverse via your usual method

  3. Load on Mojoverse:

    gunzip -c rlm-mcp-server.tar.gz | docker load
    
  4. Run with local L4-powered llama.cpp:

    RLM_API_BASE=http://localhost:8080/v1 docker compose up
    

References

License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选