Massive Context Mcp

io.github.egoughnour由 GitHub 帳號 egoughnour 發布v3.0.1更新於 Oct 24, 2026

Handles 10M+ token contexts with chunking, sub-queries, and local Ollama inference.

概覽

AI 產生的概覽

讓助理把超大文件當成外部脈絡載入、切塊,並用本機 Ollama 或 Claude 子查詢進行分析。

可以做什麼
Massive Context MCP 實作遞迴語言模型模式:把大型文件當成外部變數載入,檢查並依行、字元或段落切塊,對各塊平行執行子查詢,再彙整結果。工具包含一步完成分析的 rlm_auto_analyze,以及 rlm_load_context、rlm_inspect_context、rlm_chunk_context、rlm_sub_query、rlm_sub_query_batch,還有在沙箱中對已載入脈絡執行 Python 的 rlm_exec。安裝與狀態工具可檢查系統需求,並偵測或安裝 Ollama。
適用情境
當文件太大、放不進模型脈絡,而需要對它做摘要、找缺陷、擷取結構、安全稽核或回答自訂問題時適用。也可透過 rlm_exec 對大檔案做確定性的正規表示式或資料擷取。
執行需求
以 stdio 在本機執行,可從 PyPI(uvx 或 pip)或 .mcpb 套件安裝;僅支援桌面端。選用環境變數:OLLAMA_URL(預設 RLM_DATA_DIR。免費本機推論需要 Ollama 與 gemma3 模型,否則子查詢會退回 Claude SDK。README 說明本機模型安裝需要 Apple Silicon 的 macOS 與 16GB 以上記憶體。
安裝前請注意
rlm_exec 會在子程序中對已載入脈絡執行任意 Python;選用的防火牆套件(RLM_FIREWALL_ENABLED、RLM_FIREWALL_MODE)預設只警告。退回 Claude SDK 時會把切塊內容送到雲端 API,可能產生依 token 計費。安裝工具會安裝軟體並下載數 GB 的模型。脈絡會持久保存在 RLM_DATA_DIR 下。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Massive Context Mcp,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

Massive Context MCP

[PyPI] [MCP Registry] [Claude Desktop] [Tests] [Release] [License: MIT]

[Top Language] [Code Size] [Last Commit] [Repository Size]

Handle massive contexts (10M+ tokens) with chunking, sub-queries, and free local inference via Ollama.

mermaid
flowchart TD    A[Claude Code] --> B[RLM MCP Server]    B --> C{rlm_ollama_status}    C -->|cached 60s| D{provider = auto}
    D -->|Ollama running| E[🦙 Ollama<br/>gemma3:12b]    D -->|Ollama unavailable| F[☁️ Claude SDK<br/>claude-haiku-4-5]
    E --> G[["💰 $0<br/>Free local inference"]]    F --> H[["💰 ~$0.80/1M<br/>Cloud inference"]]
    style A fill:#ff922b,color:#fff    style B fill:#339af0,color:#fff    style E fill:#51cf66,color:#fff    style F fill:#748ffc,color:#fff    style G fill:#51cf66,color:#fff    style H fill:#748ffc,color:#fff

Based on the Recursive Language Model pattern. Inspired by richardwhiteii/rlm.

📸 Screenshots

[Tools in Claude Desktop]

Core Idea

Instead of feeding massive contexts directly into the LLM:

  1. Load context as external variable (stays out of prompt)
  2. Inspect structure programmatically
  3. Chunk strategically (lines, chars, or paragraphs)
  4. Sub-query recursively on chunks
  5. Aggregate results for final synthesis

Quick Start

Installation

Option 1: PyPI (Recommended)

bash
uvx massive-context-mcp# orpip install massive-context-mcp

With Optional Extras:

bash
# With Code Firewall integration (security filter for rlm_exec)pip install massive-context-mcp[firewall]
# With Claude Agent SDK (for programmatic Claude API access)pip install massive-context-mcp[claude]
# With all extraspip install massive-context-mcp[firewall,claude]

Option 2: Claude Desktop One-Click

Download the .mcpb from Releases and double-click to install.

Option 3: From Source

bash
git clone https://github.com/egoughnour/massive-context-mcp.gitcd massive-context-mcpuv sync

Wire to Claude Code / Claude Desktop

Add to ~/.claude/.mcp.json (Claude Code) or claude_desktop_config.json (Claude Desktop):

json
{  "mcpServers": {    "massive-context": {      "command": "uvx",      "args": ["massive-context-mcp"],      "env": {        "RLM_DATA_DIR": "~/.rlm-data",        "OLLAMA_URL": "http://localhost:11434"      }    }  }}

Tools

Setup & Status Tools

ToolPurpose
rlm_system_checkCheck system requirements — verify macOS, Apple Silicon, 16GB+ RAM, Homebrew
rlm_setup_ollamaInstall via Homebrew — managed service, auto-updates, requires Homebrew
rlm_setup_ollama_directInstall via direct download — no sudo, fully headless, works on locked-down machines
rlm_ollama_statusCheck Ollama availability — detect if free local inference is available

Analysis Tools

ToolPurpose
rlm_auto_analyzeOne-step analysis — auto-detects type, chunks, and queries
rlm_load_contextLoad context as external variable
rlm_inspect_contextGet structure info without loading into prompt
rlm_chunk_contextChunk by lines/chars/paragraphs
rlm_get_chunkRetrieve specific chunk
rlm_filter_contextFilter with regex (keep/remove matching lines)
rlm_execExecute Python code against loaded context (sandboxed)
rlm_sub_queryMake sub-LLM call on chunk
rlm_sub_query_batchProcess multiple chunks in parallel
rlm_store_resultStore sub-call result for aggregation
rlm_get_resultsRetrieve stored results
rlm_list_contextsList all loaded contexts

Quick Analysis with rlm_auto_analyze

For most use cases, just use rlm_auto_analyze — it handles everything automatically:

python
rlm_auto_analyze(    name="my_file",    content=file_content,    goal="find_bugs"  # or: summarize, extract_structure, security_audit, answer:<question>)

What it does automatically:

  1. Detects content type (Python, JSON, Markdown, logs, prose, code)
  2. Selects optimal chunking strategy
  3. Adapts the query for the content type
  4. Runs parallel sub-queries
  5. Returns aggregated results

Supported goals:

GoalDescription
summarizeSummarize content purpose and key points
find_bugsIdentify errors, issues, potential problems
extract_structureList functions, classes, schema, headings
security_auditFind vulnerabilities and security issues
answer:<question>Answer a custom question about the content

Programmatic Analysis with rlm_exec

For deterministic pattern matching and data extraction, use rlm_exec to run Python code directly against a loaded context. This is closer to the paper's REPL approach and provides full control over analysis logic.

Tool: rlm_exec

Purpose: Execute arbitrary Python code against a loaded context in a sandboxed subprocess.

Parameters:

  • code (required): Python code to execute. Set the result variable to capture output.
  • context_name (required): Name of a previously loaded context.
  • timeout (optional, default 30): Maximum execution time in seconds.

Features:

  • Context available as read-only context variable
  • Pre-imported modules: re, json, collections
  • Subprocess isolation (won't crash the server)
  • Timeout enforcement
  • Works on any system with Python (no Docker needed)

Example — Finding patterns in a loaded context:

python
# After loading a contextrlm_exec(    code="""import reamounts = re.findall(r'\$[\d,]+', context)result = {'count': len(amounts), 'sample': amounts[:5]}""",    context_name="bill")

Example Response:

json
{  "result": {    "count": 1247,    "sample": ["$500", "$1,000", "$250,000", "$100,000", "$50"]  },  "stdout": "",  "stderr": "",  "return_code": 0,  "timed_out": false}

Example — Extracting structured data:

python
rlm_exec(    code="""import reimport json
# Find all email addressesemails = re.findall(r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b', context)
# Count by domainfrom collections import Counterdomains = [e.split('@')[1] for e in emails]domain_counts = Counter(domains)
result = {    'total_emails': len(emails),    'unique_domains': len(domain_counts),    'top_domains': domain_counts.most_common(5)}""",    context_name="dataset",    timeout=60)

When to use rlm_exec vs rlm_sub_query:

Use CaseToolWhy
Extract all dates, IDs, amountsrlm_execRegex is deterministic and fast
Find security vulnerabilitiesrlm_sub_queryRequires reasoning and context
Parse JSON/XML structurerlm_execStandard libraries work perfectly
Summarize themes or tonerlm_sub_queryNatural language understanding needed
Count word frequenciesrlm_execSimple computation, no AI needed
Answer "Why did X happen?"rlm_sub_queryRequires inference and reasoning

Tip: For large contexts, combine both — use rlm_exec to filter/extract, then rlm_sub_query for semantic analysis of filtered results.

Code Firewall Integration (Optional)

For enhanced security, integrate code-firewall-mcp to filter dangerous code patterns before execution:

bash
pip install massive-context-mcp[firewall]

When installed, rlm_exec can automatically check code against a blacklist of known dangerous patterns (e.g., os.system(), eval(), subprocess with shell=True). The firewall uses structural similarity matching — normalizing code to its skeleton and comparing against blacklisted patterns via embeddings.

How it works:

  1. Code is parsed to a syntax tree and normalized (identifiers → _, strings → "S")
  2. Normalized structure is embedded via Ollama
  3. Similarity is checked against blacklisted patterns in ChromaDB
  4. Code is blocked if similarity exceeds threshold (default: 0.85)

Configuration (environment variables):

  • RLM_FIREWALL_ENABLED=true — Enable firewall checks (auto-enabled when package installed)
  • RLM_FIREWALL_MODE=warn|block — Warn or block on matches (default: warn)

Example blocked patterns:

  • os.system(user_input) — Command injection
  • eval(untrusted_data) — Code injection
  • subprocess.Popen(..., shell=True) — Shell injection

Use rlm_firewall_status to check firewall availability and configuration.

Providers & Auto-Detection

RLM automatically detects and uses the best available provider:

ProviderDefault ModelCostUse Case
auto(best available)$0 or ~$0.80/1MDefault — prefers Ollama if available
ollamagemma3:12b$0Local inference, requires Ollama
claude-sdkclaude-haiku-4-5~$0.80/1M inputCloud inference, always available

How Auto-Detection Works

When you use provider="auto" (the default), RLM:

  1. Checks if Ollama is running at OLLAMA_URL (default: http://localhost:11434)
  2. Checks if gemma3:12b is available (or any gemma3 variant)
  3. Uses Ollama if available, otherwise falls back to Claude SDK

The status is cached for 60 seconds to avoid repeated network checks.

Check Ollama Status

Use rlm_ollama_status to see what's available:

python
rlm_ollama_status()

Response when Ollama is ready:

json
{  "running": true,  "models": ["gemma3:12b", "llama3:8b"],  "default_model_available": true,  "best_provider": "ollama",  "recommendation": "Ollama is ready! Sub-queries will use free local inference by default."}

Response when Ollama is not available:

json
{  "running": false,  "error": "connection_refused",  "best_provider": "claude-sdk",  "recommendation": "Ollama not available. Sub-queries will use Claude API. To enable free local inference, install Ollama and run: ollama serve"}

Transparent Provider Selection

All sub-query responses include which provider was actually used:

json
{  "provider": "ollama",  "model": "gemma3:12b",  "requested_provider": "auto",  "response": "..."}

Autonomous Usage

Enable Claude to use RLM tools automatically without manual invocation:

1. CLAUDE.md Integration Copy CLAUDE.md.example content to your project's CLAUDE.md (or ~/.claude/CLAUDE.md for global) to teach Claude when to reach for RLM tools automatically.

2. Hook Installation Copy the .claude/hooks/ directory to your project to auto-suggest RLM when reading files >10KB:

bash
cp -r .claude/hooks/ /Users/your_username/your-project/.claude/hooks/

The hook provides guidance but doesn't block reads.

3. Skill Reference Copy the .claude/skills/ directory for comprehensive RLM guidance:

bash
cp -r .claude/skills/ /Users/your_username/your-project/.claude/skills/

With these in place, Claude will autonomously detect when to use RLM instead of reading large files directly into context.

Setting Up Ollama (Free Local Inference)

RLM can automatically install and configure Ollama on macOS with Apple Silicon. There are two installation methods with different trade-offs:

Choosing an Installation Method
Aspectrlm_setup_ollama (Homebrew)rlm_setup_ollama_direct (Direct Download)
Sudo requiredOnly if Homebrew not installed❌ Never
Homebrew required✅ Yes❌ No
Auto-updates✅ Yes (brew upgrade)❌ Manual
Service management✅ brew services (launchd)⚠️ ollama serve (foreground)
Install location/opt/homebrew/~/Applications/
Locked-down machines⚠️ May fail✅ Works
Fully headless⚠️ May prompt for sudo✅ Yes

Recommendation:

  • Use Homebrew method if you have Homebrew and want managed updates
  • Use Direct Download for automation, locked-down machines, or when you don't have admin access
Method 1: Homebrew Installation (Recommended if you have Homebrew)
python
# 1. Check if your system meets requirementsrlm_system_check()
# 2. Install via Homebrewrlm_setup_ollama(install=True, start_service=True, pull_model=True)

What this does:

  • Installs Ollama via Homebrew (brew install ollama)
  • Starts Ollama as a managed background service (brew services start ollama)
  • Pulls gemma3:12b model (~8GB download)

Requirements:

  • macOS with Apple Silicon (M1/M2/M3/M4)
  • 16GB+ RAM (gemma3:12b needs ~8GB to run)
  • Homebrew installed
Method 2: Direct Download (Fully Headless, No Sudo)
python
# 1. Check system (Homebrew NOT required for this method)rlm_system_check()
# 2. Install via direct download - no sudo, no Homebrewrlm_setup_ollama_direct(install=True, start_service=True, pull_model=True)

What this does:

Requirements:

  • macOS with Apple Silicon (M1/M2/M3/M4)
  • 16GB+ RAM
  • No special permissions needed!

Note on PATH: After direct installation, the CLI is at:

bash
~/Applications/Ollama.app/Contents/Resources/ollama

Add to your shell config if needed:

bash
export PATH="$HOME/Applications/Ollama.app/Contents/Resources:$PATH"
For Systems with Less RAM

Use a smaller model on either installation method:

python
rlm_setup_ollama(install=True, start_service=True, pull_model=True, model="gemma3:4b")# orrlm_setup_ollama_direct(install=True, start_service=True, pull_model=True, model="gemma3:4b")
Manual Setup

If you prefer manual installation or are on a different platform:

  1. Install Ollama from https://ollama.ai or via Homebrew:

    bash
    brew install ollama
  2. Start the service:

    bash
    brew services start ollama# or: ollama serve
  3. Pull the model:

    bash
    ollama pull gemma3:12b
  4. Verify it's working:

    python
    rlm_ollama_status()
Provider Selection

RLM automatically uses Ollama when available. You can also force a specific provider:

python
# Auto-detection (default) - uses Ollama if availablerlm_sub_query(query="Summarize", context_name="doc")
# Explicitly use Ollamarlm_sub_query(query="Summarize", context_name="doc", provider="ollama")
# Explicitly use Claude SDKrlm_sub_query(query="Summarize", context_name="doc", provider="claude-sdk")

Usage Example

Basic Pattern

# 0. (Optional) First-time setup on macOS - choose ONE method:
# Option A: Homebrew (if you have it)rlm_system_check()rlm_setup_ollama(install=True, start_service=True, pull_model=True)
# Option B: Direct download (no sudo, fully headless)rlm_system_check()rlm_setup_ollama_direct(install=True, start_service=True, pull_model=True)
# 0b. (Optional) Check if Ollama is available for free inferencerlm_ollama_status()
# 1. Load a large documentrlm_load_context(name="report", content=<large document>)
# 2. Inspect structurerlm_inspect_context(name="report", preview_chars=500)
# 3. Chunk into manageable piecesrlm_chunk_context(name="report", strategy="paragraphs", size=1)
# 4. Sub-query chunks in parallel (auto-uses Ollama if available)rlm_sub_query_batch(    query="What is the main topic? Reply in one sentence.",    context_name="report",    chunk_indices=[0, 1, 2, 3],    concurrency=4)
# 5. Store results for aggregationrlm_store_result(name="topics", result=<response>)
# 6. Retrieve all resultsrlm_get_results(name="topics")

Processing a 2MB Document

Tested with H.R.1 Bill (2MB):

# Loadrlm_load_context(name="bill", content=<2MB XML>)
# Chunk into 40 pieces (50K chars each)rlm_chunk_context(name="bill", strategy="chars", size=50000)
# Sample 8 chunks (20%) with parallel queries# (auto-uses Ollama if running, otherwise Claude SDK)rlm_sub_query_batch(    query="What topics does this section cover?",    context_name="bill",    chunk_indices=[0, 5, 10, 15, 20, 25, 30, 35],    concurrency=4)

Result: Comprehensive topic extraction at $0 cost (with Ollama) or ~$0.02 (with Claude).

Analyzing War and Peace (3.3MB)

Literary analysis of Tolstoy's epic novel from Project Gutenberg:

bash
# Download the textcurl -o war_and_peace.txt https://www.gutenberg.org/files/2600/2600-0.txt
python
# Load into RLM (3.3MB, 66K lines)rlm_load_context(name="war_and_peace", content=open("war_and_peace.txt").read())
# Chunk by lines (1000 lines per chunk = 67 chunks)rlm_chunk_context(name="war_and_peace", strategy="lines", size=1000)
# Sample 10 chunks evenly across the book (15% coverage)sample_indices = [0, 7, 14, 21, 28, 35, 42, 49, 56, 63]
# Extract characters from each sampled sectionrlm_sub_query_batch(    query="List major characters in this section with brief descriptions.",    context_name="war_and_peace",    chunk_indices=sample_indices,    provider="claude-sdk",  # Haiku 4.5    concurrency=8)

Result: Complete character arc across the novel — Pierre's journey from idealist to prisoner to husband, Natásha's growth, Nikolái Rostóv's journey from soldier to landowner — all for ~$0.03.

MetricValue
File size3.35 MB
Lines66,033
Chunks67
Sampled10 (15%)
Cost~$0.03

Data Storage

mermaid
graph TD    A[("$RLM_DATA_DIR")] --> B["📁 contexts/"]    A --> C["📁 chunks/"]    A --> D["📁 results/"]
    B --> B1[".txt files"]    B --> B2[".meta.json"]    C --> C1["by context name"]    D --> D1[".jsonl files"]
    style A fill:#339af0,color:#fff    style B fill:#51cf66,color:#fff    style C fill:#51cf66,color:#fff    style D fill:#51cf66,color:#fff

Contexts persist across sessions. Chunked contexts are cached for reuse.

Learning Prompts

Use these prompts with Claude Code to explore the codebase and learn RLM patterns. The code is the single source of truth.

Understanding the Tools

Read src/rlm_mcp_server.py and list all RLM tools with their parameters and purpose.
Explain the chunking strategies available in rlm_chunk_context.When would I use each one?
What's the difference between rlm_sub_query and rlm_sub_query_batch?Show me the implementation.

Understanding the Architecture

Read src/rlm_mcp_server.py and explain how contexts are stored and persisted.Where does the data live?
How does the claude-sdk provider extract text from responses?Walk me through _call_claude_sdk.
What happens when I call rlm_load_context? Trace the full flow.

Hands-On Learning

Load the README as a context, chunk it by paragraphs,and run a sub-query on the first chunk to summarize it.
Show me how to process a large file in parallel using rlm_sub_query_batch.Use a real example.
I have a 1MB log file. Walk me through the RLM pattern to extract all errors.

Extending RLM

Read the test file and explain what scenarios are covered.What edge cases should I be aware of?
How would I add a new chunking strategy (e.g., by regex delimiter)?Show me where to modify the code.
How would I add a new provider (e.g., OpenAI)?What functions need to change?

License

MIT

來源:README.md,提交 5ee4ad4

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v3.0.1最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分