Skip to main content
Glama
egoughnour

Massive Context MCP

by egoughnour

rlm_sub_query

Perform a focused sub-query on a chunk or filtered context to enable recursive analysis of large documents. Supports multiple LLM providers for flexible querying within massive datasets.

Instructions

Make a sub-LLM call on a chunk or filtered context. Core of recursive pattern.

Args: query: Question/instruction for the sub-call context_name: Context identifier to query against chunk_index: Optional: specific chunk index provider: LLM provider - 'auto', 'ollama', or 'claude-sdk'. 'auto' prefers Ollama if available (free local inference) model: Model to use (provider-specific defaults apply)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
context_nameYes
chunk_indexNo
providerNoauto
modelNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The actual handler function for the 'rlm_sub_query' tool. It makes a sub-LLM call on a chunk or filtered context. Resolves provider/model, loads context, optionally selects a chunk, then calls _make_provider_call and returns the response.
    @mcp.tool()
    async def rlm_sub_query(
        query: str,
        context_name: str,
        chunk_index: Optional[int] = None,
        provider: str = "auto",
        model: Optional[str] = None,
    ) -> dict:
        """Make a sub-LLM call on a chunk or filtered context. Core of recursive pattern.
    
        Args:
            query: Question/instruction for the sub-call
            context_name: Context identifier to query against
            chunk_index: Optional: specific chunk index
            provider: LLM provider - 'auto', 'ollama', or 'claude-sdk'. 'auto' prefers Ollama if available (free local inference)
            model: Model to use (provider-specific defaults apply)
        """
        # Resolve auto provider and model
        resolved_provider, resolved_model = await _resolve_provider_and_model(provider, model)
    
        error = _ensure_context_loaded(context_name)
        if error:
            return {"error": "context_not_found", "message": error}
    
        if chunk_index is not None:
            chunks = contexts[context_name].get("chunks")
            if not chunks or chunk_index >= len(chunks):
                return {"error": "chunk_not_available", "message": f"Chunk {chunk_index} not available"}
            context_content = chunks[chunk_index]
        else:
            context_content = contexts[context_name]["content"]
    
        result, call_error = await _make_provider_call(resolved_provider, resolved_model, query, context_content)
    
        if call_error:
            return {
                "error": "provider_error",
                "provider": resolved_provider,
                "model": resolved_model,
                "requested_provider": provider,
                "message": call_error,
            }
    
        return {
            "provider": resolved_provider,
            "model": resolved_model,
            "requested_provider": provider if provider == "auto" else None,
            "response": result,
        }
  • Registration of 'rlm_sub_query' as a FastMCP tool via the @mcp.tool() decorator. This is the point where the tool is registered with the MCP server.
    @mcp.tool()
  • Helper that resolves the 'auto' provider to either 'ollama' or 'claude-sdk', and selects the best model for the chosen provider.
    async def _resolve_provider_and_model(
        provider: str,
        model: Optional[str],
    ) -> tuple[str, str]:
        """Resolve 'auto' provider and get appropriate model."""
        # Handle auto provider selection
        if provider == "auto":
            # Check Ollama status (uses cache)
            await _check_ollama_status()
            provider = _get_best_provider()
    
        # Get model if not specified
        if not model:
            model = _get_best_model_for_provider(provider)
    
        return provider, model
  • Helper that routes the sub-call to the appropriate provider (Ollama or Claude SDK) after resolving provider/model.
    async def _make_provider_call(
        provider: str,
        model: str,
        query: str,
        context_content: str,
    ) -> tuple[Optional[str], Optional[str]]:
        """Route a sub-call to the appropriate provider. Returns (result, error)."""
        # Resolve auto provider
        resolved_provider, resolved_model = await _resolve_provider_and_model(provider, model)
    
        if resolved_provider == "ollama":
            return await _call_ollama(query, context_content, resolved_model)
        elif resolved_provider == "claude-sdk":
            return await _call_claude_sdk(query, context_content, resolved_model)
        else:
            return None, f"Unknown provider: {resolved_provider}"
  • Helper that ensures a context is loaded into memory (from disk if needed), returning an error string if the context doesn't exist.
    def _ensure_context_loaded(name: str) -> Optional[str]:
        """Ensure context is loaded into memory. Returns error message if not found."""
        if name in contexts:
            return None
    
        disk_context = _load_context_from_disk(name)
        if disk_context:
            content = disk_context.pop("content")
            contexts[name] = {"meta": disk_context, "content": content}
            return None
    
        return f"Context '{name}' not found"
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, and description lacks behavioral details such as side effects, required permissions, rate limits, or what happens to data; only lists parameters.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Concise with clear header and bulleted args, no redundant information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Adequate for parameter listing but lacks behavioral context and integration details with sibling tools; output schema exists so return values not needed, but behavioral transparency gap remains.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Adds meaning for provider (with 'auto' explanation) and chunk_index (optional), but does not explain query or context_name beyond names; schema coverage 0% makes description necessary.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool makes a sub-LLM call on a chunk or filtered context, distinguishing it from siblings like rlm_sub_query_batch and rlm_filter_context.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implied usage as 'core of recursive pattern' but no explicit when-to-use or when-not-to-use, nor comparison with alternatives like rlm_sub_query_batch.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/egoughnour/massive-context-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server