$ show forloopcodes/contextplus
Context+ is an MCP (Model Context Protocol) server that provides AI agents with structural and semantic awareness of large codebases. It operates over stdio and exposes 17 tools for code discovery, analysis, version control, and memory management. The architecture is layered: a core layer handles multi-language AST parsing via tree-sitter (36 languages with WASM grammars and regex fallback), gitignore-aware recursive directory walking with nested .gitignore support, vector embedding generation (Ollama or OpenAI-compatible APIs) with disk caching and adaptive batching, and an in-memory property graph for long-term memory with decay scoring and auto-similarity edges. A tools layer wraps these capabilities into MCP tools for context tree generation, file skeleton extraction, semantic search (file-level and identifier-level with call-site ranking), blast radius analysis, static analysis runner, commit validation with shadow restore points, spectral clustering-based semantic navigation, and Obsidian-style feature hub navigation. A git layer provides a shadow restore point system for undo without touching git history. The server includes process lifecycle management (idle timeout, parent process monitoring, broken pipe detection) and a realtime embedding tracker that incrementally refreshes embeddings on file changes. The landing page is a separate Next.js application deployed on Cloudflare Workers that serves the documentation and instructions API.
The LLM identified 4 files worth highlighting for reuse:
Implements spectral clustering with an eigengap heuristic to automatically determine the optimal number of clusters without manual tuning. Builds an affinity matrix from cosine similarity, computes the normalized Laplacian, performs eigenvalue decomposition, and applies k-means on the eigenvectors. Also includes a path pattern detection utility for finding common prefixes/suffixes in file paths. This module is self-contained (only depends on ml-matrix) and can be extracted for any clustering task on vector data.
A multi-provider vector embedding engine supporting Ollama (local) and OpenAI-compatible APIs (Gemini, OpenAI, Groq, vLLM). Features include disk-based embedding caching with content hashing for incremental updates, adaptive batch processing with automatic batch splitting on context length errors, chunking of large inputs with weighted vector merging, and a SearchIndex class that indexes documents and performs hybrid semantic/keyword search with configurable weights and score thresholds. The engine handles runtime options (num_gpu, num_thread, etc.) for Ollama and provides robust error recovery for oversized inputs.
An in-memory property graph with JSON persistence for linking memory nodes. Supports node types (concept, file, symbol, note) and relation types (relates_to, depends_on, implements, references, similar_to, contains). Features include automatic embedding generation for nodes, cosine similarity-based auto-linking with configurable threshold, exponential decay scoring for edges (e^(-λt)), graph traversal with depth limits and edge filtering, stale link pruning, and bulk interlinked context import. The graph is persisted to disk with debounced saves and provides a complete RAG memory layer for AI agents.
A gitignore-aware recursive directory walker that correctly handles nested .gitignore files with scope merging and negation support. It builds an ignore chain from the root directory down to each subdirectory, evaluating paths relative to each scope's directory. Supports anchored patterns, directory-specific rules, and cross-scope negation. Also provides a walkRoots function that indexes extra root directories (e.g., monorepo sub-projects) independently of the workspace's top-level .gitignore, with deduplication and workspace-relative depth reporting. This is a robust, reusable file system traversal utility.