topos-search-agent
A highly optimized string pattern-matching service, built for rapid querying against file contents and arbitrary text segments. This component is engineered for deep interoperability within the infinity-topos computational framework.
Author

bmorphism
Quick Info
Actions
Tags
Topos Pattern Discovery Engine (krep-mcp-server Rework)
This service interfaces the superior speed of the underlying 'krep' utility—a pattern analysis engine vastly superior to legacy tools like grep—with the Model Context Protocol (MCP). It is tailored specifically for integration into the infinity-topos ecosystem, enabling sophisticated, context-aware searching by AI agents.
Note: This implementation is a direct functional replacement for the deprecated krep-mcp-server.
THE KREP-MCP-SERVER REFACTORING MANDATE
========================================
+-----------------------------------------------------+
| Abstraction & Simplicity Zone |
| |
+-----^--------------------+------------------------+-+
| | |
+-----------+----------+ +------+-------------+ +------+-------+
| | | | | |
| D A T A S H A P | | S I N G L E A P I | | P E R F O R - |
| E X T R A C T I O N | | N A M E C O H E R E N C E| | M A N C E H U B |
| | | | | |
+-----+----------+-----+ +---+-----------+----+ +------+-------+
| | | | |
v v v v v
+--------+--+ +----+-----+ +---+----+ +---+-----+ +----+------+ | | | | | | | | | | | "Canonical" | | 1 Entry | | krep | |krepSearch| | Central | | Function | | To Define| | | |krepMatch | | Error | | That Maps | | Specific | | | |krepCount | | Logic | | All Needs | | Function | | | | | | | | | |ality | | | | | | | +-----------+ +----------+ +--------+ +----------+ +-----------+
+-----------------------------------------------------+
| Configuration & Script Discipline |
| |
+-----^--------------------+------------------------+-+
| | |
+-----------+----------+ +------+-------------+ +------+-------+
| | | | | |
| 1 Script for | | Type-Safe | | Test/Mock Mode|
| Deployment | | Integer Check | | Validates |
| | | via Native Call | | Success Only |
| | | | | When All OK |
+----------------------+ +--------------------+ +--------------+
"Simplicity is the ultimate sophistication."
- Re-architect, probably
Service Overview
The Topos Pattern Discovery Engine delivers streamlined access to the krep binary, an advanced, multi-threaded text searching utility. It exposes this capability via the Model Context Protocol (MCP), enabling AI systems to execute high-velocity pattern retrieval tasks against file systems or dynamic string buffers.
Key Capabilities
- Algorithmic Superiority: Dynamically selects the best search method (KMP, BMH, RK) contingent on the provided pattern's characteristics.
- Hardware Optimization: Maximizes throughput by utilizing available low-level instructions (e.g., SSE4.2, AVX2, NEON).
- Parallel Execution: Automatically leverages all available processor threads to ensure maximum concurrent search throughput.
- Unified API Surface: All search permutations (file scan, string check, occurrence tally) are exposed via a singular, consistent function signature.
- MCP Native: Fully compliant interface for immediate deployment within AI workflow engines.
Codebase Pathology (The Legacy Issues Addressed)
This prior implementation suffered from significant structural complexity, which this rewrite aims to eliminate:
- Feature Obfuscation: Essential text searching logic was obscured by excessive architectural layers.
- Documentation Sprawl: Excessive documentation artifacts led to information fragmentation.
- Integration Silos: Three distinct integration pathways (Cline, Claude Desktop, SDK) required redundant setup routines.
- Installer Bloat: Deployment relied on numerous disparate setup scripts where a single, parameterized installer is sufficient.
- Decentralized Error Reporting: Error handling logic was scattered, undermining system resilience.
- Test Layout Chaos: Test suites were distributed without logical grouping.
- Configuration Overlap: Redundant environment variables and configuration file entries complicated maintenance.
- Binary Location Ambiguity: The utility searched an excessively large, fixed set of locations for the core binary.
The Idealized State:
┌──────────────────────┐ │ topos-search-agent │ │ ┌────────────────┐ │ │ │ handler.js │ │ │ │ - Single entry│ │ │ │ point │ │ │ └────────────────┘ │ │ ┌────────────────┐ │ │ │ README.md │ │ │ │ - Concise docs│ │ │ └────────────────┘ │ │ ┌────────────────┐ │ │ │ deploy.sh │ │ │ │ - Single CLI │ │ │ └────────────────┘ │ └──────────────────────┘
Project Topology
(The complex legacy structure is omitted, focusing only on essential deployment artifacts.)
Deployment Procedure
- Verify the
krepexecutable is compiled and accessible:
cd /path/to/krep-native make
- Configure the agent within your primary MCP configuration manifest:
{ "mcpServers": { "search_engine": { "command": "node", "args": [ "/path/to/topos-search-agent/handler.js" ], "env": { "TOPOS_MODE": "true", "KREP_BINARY_LOC": "/path/to/krep-native/krep", "VERBOSITY": "INFO" }, "description": "Ultra-fast pattern discovery service for infinity-topos", "disabled": false, "autoApprove": [ "search_engine" ] } } }
Execution Interface
The agent exposes a singular, universally applicable function via MCP:
Parameter Definitions
- query (Mandatory): The textual or regex pattern to be matched.
- scope (Mandatory): The resource container, either a file system path or a raw string.
- operation (Optional): Defines the result type:
scan(Default): Returns matching lines/contexts.extract: Extracts only the matched segments.tally: Returns only the total count of matches.- case_sensitive (Optional): Boolean flag; defaults to strict matching (
true). - parallelism (Optional): Explicit thread count override; null permits system auto-detection.
Operational Flow
The agent processes incoming MCP requests by:
- Validating parameters against the canonical schema.
- Constructing the optimal command structure for the underlying
krepbinary based on the requestedoperation. - Invoking the binary execution layer.
- Post-processing raw output into structured JSON for transmission back through the MCP channel.
Performance Characteristics
- Adaptive Algorithm Engine: Utilizes KMP for low-complexity searches, BMH for mid-range complexity, and Rabin-Karp hashing for extensive pattern matching.
- SIMD Utilization: Native integration exploits vectorized CPU capabilities for substantial speed gains.
- Asynchronous Multi-Core Scaling: Search tasks are automatically partitioned across all logical processors.
Infinity-Topos Synergy
This tool is primed for deep integration within the topos environment:
- Data Pipelining: Search results are perfectly formatted for immediate consumption by Babashka processing streams.
- Auditory Feedback: Output can be routed to the Say MCP service for vocalized reporting.
Configuration Environment
Key environment variables govern runtime behavior:
TOPOS_MODE: Activates MCP protocol handling.KREP_BINARY_LOC: Absolute pointer to the compiledkrepexecutable.VERBOSITY: Logging level control.KREP_MOCK_MODE: Enables simulated operational responses for testing.KREP_BINARY_CHECK_SKIP: Bypasses filesystem verification of the executable path.
Commercial Terms
Licensed under the MIT Covenant.
(The lengthy, redundant sections relating to old setup scripts, obsolete documentation artifacts, and the historical context of XMLHttpRequest have been omitted for conciseness.)
