Skip to main content
Glama
egoughnour

Massive Context MCP

by egoughnour

rlm_filter_context

Apply regex filtering to a context, keeping or removing lines that match a pattern, to create a new filtered subset for targeted analysis.

Instructions

Filter context using regex/string operations. Creates a new filtered context.

Args: name: Source context identifier output_name: Name for filtered context pattern: Regex pattern to match mode: 'keep' or 'remove' matching lines

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
output_nameYes
patternYes
modeNokeep

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler for the rlm_filter_context tool. Loads a context by name, applies a regex pattern to filter lines in 'keep' or 'remove' mode, creates a new filtered context in memory and on disk, and returns metadata about the filtering operation.
    @mcp.tool()
    async def rlm_filter_context(
        name: str,
        output_name: str,
        pattern: str,
        mode: str = "keep",
    ) -> dict:
        """Filter context using regex/string operations. Creates a new filtered context.
    
        Args:
            name: Source context identifier
            output_name: Name for filtered context
            pattern: Regex pattern to match
            mode: 'keep' or 'remove' matching lines
        """
        error = _ensure_context_loaded(name)
        if error:
            return {"error": "context_not_found", "message": error}
    
        content = contexts[name]["content"]
        lines = content.split("\n")
        regex = re.compile(pattern)
    
        if mode == "keep":
            filtered = [line for line in lines if regex.search(line)]
        else:
            filtered = [line for line in lines if not regex.search(line)]
    
        new_content = "\n".join(filtered)
        meta = _context_summary(
            output_name,
            new_content,
            hash=_hash_content(new_content),
            source=name,
            filter_pattern=pattern,
            filter_mode=mode,
            chunks=None,
        )
        contexts[output_name] = {"meta": meta, "content": new_content}
        _save_context_to_disk(output_name, new_content, meta)
    
        return {
            "status": "filtered",
            "name": output_name,
            "original_lines": len(lines),
            "filtered_lines": len(filtered),
            "length": len(new_content),
        }
  • Registration of rlm_filter_context as a FastMCP tool via the @mcp.tool() decorator on line 1499.
    @mcp.tool()
    async def rlm_filter_context(
        name: str,
        output_name: str,
        pattern: str,
        mode: str = "keep",
    ) -> dict:
        """Filter context using regex/string operations. Creates a new filtered context.
    
        Args:
            name: Source context identifier
            output_name: Name for filtered context
            pattern: Regex pattern to match
            mode: 'keep' or 'remove' matching lines
        """
  • The complete handler function for the rlm_filter_context tool (same as registration since it uses @mcp.tool decorator).
    async def rlm_filter_context(
        name: str,
        output_name: str,
        pattern: str,
        mode: str = "keep",
    ) -> dict:
        """Filter context using regex/string operations. Creates a new filtered context.
    
        Args:
            name: Source context identifier
            output_name: Name for filtered context
            pattern: Regex pattern to match
            mode: 'keep' or 'remove' matching lines
        """
        error = _ensure_context_loaded(name)
        if error:
            return {"error": "context_not_found", "message": error}
    
        content = contexts[name]["content"]
        lines = content.split("\n")
        regex = re.compile(pattern)
    
        if mode == "keep":
            filtered = [line for line in lines if regex.search(line)]
        else:
            filtered = [line for line in lines if not regex.search(line)]
    
        new_content = "\n".join(filtered)
        meta = _context_summary(
            output_name,
            new_content,
            hash=_hash_content(new_content),
            source=name,
            filter_pattern=pattern,
            filter_mode=mode,
            chunks=None,
        )
        contexts[output_name] = {"meta": meta, "content": new_content}
        _save_context_to_disk(output_name, new_content, meta)
    
        return {
            "status": "filtered",
            "name": output_name,
            "original_lines": len(lines),
            "filtered_lines": len(filtered),
            "length": len(new_content),
        }
  • Helper function called by rlm_filter_context to ensure the source context is loaded into memory before filtering.
    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"
  • Helper function used by rlm_filter_context to build metadata for the new filtered context.
    def _context_summary(name: str, content: str, **extra: Any) -> dict:
        """Build a common context summary dict."""
        summary = {
            "name": name,
            "length": len(content),
            "lines": content.count("\n") + 1,
        }
        summary.update(extra)
        return summary
Behavior2/5

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

No annotations are present, so the description must disclose behavioral traits. It mentions 'creates a new filtered context', implying the original is unchanged, but does not specify error handling for invalid regex, input size limits, or whether the operation is reversible. Minimal beyond basic purpose.

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?

The description is concise at two sentences plus a bullet-style Args list. It front-loads the purpose and then details parameters efficiently with no unnecessary words.

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

Completeness4/5

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

Given the tool has an output schema (though not shown), return values need not be explained. The description covers the core purpose and parameters. However, it lacks details on how to use the result (e.g., accessing the new context) and error scenarios, but overall is sufficient for a filter tool.

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?

Schema coverage is 0%, so the description must compensate. It provides brief explanations for all four parameters (name, output_name, pattern, mode) in the Args section, adding meaning beyond the raw schema. This is adequate but could be more detailed (e.g., pattern format).

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 filters context using regex/string operations and creates a new filtered context. The verb 'filter' combined with resource 'context' is specific, and the tool is distinct from siblings like rlm_chunk_context or rlm_inspect_context.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives (e.g., rlm_chunk_context for splitting, rlm_inspect_context for viewing). The description only states what it does, not when or when not to use it.

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