space-ngrams
MCP server that enables AI agents to search code, find files, and read files in a codebase at lightning speed using ripgrep.
README
space-ngrams
MCP server that gives AI agents superpowers to search through your codebase at lightning speed.
Space-nGrams connects to AI coding assistants (Claude Code, Codex CLI, Qwen CLI, OpenCode) and provides them with three essential tools: search code, find files, and read files. All powered by ripgrep for millisecond-level performance.
ποΈ How It Works
Architecture
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β AI Agent β β Space-nGrams β β ripgrep β
β (Claude Code, ββββββΆβ MCP Server ββββββΆβ (rg) β
β Qwen, etc.) βββββββ (Python) βββββββ Search Engine β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β β
β βΌ β
β ββββββββββββββββββββ β
β β Cache Layer β β
β β (~/.space-ngramsβ β
β β /cache/) β β
β ββββββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββββββ β
βββββββββββββββΆβ Metrics & Logs βββββββββββββββββ
β (~/.space-ngramsβ
β /server.log) β
ββββββββββββββββββββ
Why MCP?
MCP (Model Context Protocol) is a standard that allows AI agents to access external tools and data sources. Instead of embedding all your code into the AI's context (which is slow and expensive), Space-nGrams gives the AI the ability to:
- Search on demand β Find any pattern, function, or string in your codebase in milliseconds
- Navigate efficiently β Locate files by name, then read only what's needed
- Work with large codebases β No need to load everything into context
Why ripgrep?
- Blazing fast β SIMD acceleration, regex compilation, parallel search
- Smart filtering β Respects
.gitignore, skips binary files - Rich output β JSON format with line numbers and context
- Battle tested β Used by developers worldwide daily
Why caching?
Repeated searches are common when AI agents explore code. Our cache layer:
- Stores results for 5 minutes (configurable)
- Persists across sessions on disk
- Reduces latency from ~100ms to ~2ms on cache hits
- Automatically manages size limits (50 MB default)
β‘ Features
| Feature | Benefit |
|---|---|
| Caching | 10-50x faster for repeated searches |
| Metrics | Track performance and cache hit rates |
| Configuration | Customize limits, timeouts, ignore patterns |
| Logging | Debug issues via ~/.space-ngrams/server.log |
π οΈ Tools
| Tool | Description |
|---|---|
search_code |
Search for regex/string in code with context |
find_files |
Find files by glob pattern |
read_file |
Read file content (max 200 lines/call) |
get_metrics |
Get session performance statistics |
π¦ Installation
1. Clone the repository
git clone https://github.com/your-username/space-ngrams.git
cd space-ngrams
2. Install ripgrep
# Windows
winget install BurntSushi.ripgrep.MSVC
# macOS
brew install ripgrep
# Linux
sudo apt install ripgrep
Verify: rg --version
3. Install Python dependencies
pip install mcp
4. Verify the server starts
python src/server.py
The process will wait on stdin β that's correct. Stop with Ctrl+C.
π Connecting to AI Tools
Claude Code
claude mcp add space-ngrams -- python /path/to/space-ngrams/src/server.py
Verify:
claude mcp list
# space-ngrams: python ... - β Connected
Codex CLI
Add to ~/.codex/config.toml:
[mcp_servers.space-ngrams]
command = "python"
args = [ "/path/to/space-ngrams/src/server.py" ]
Qwen CLI
Add to ~/.qwen/settings.json:
{
"mcpServers": {
"space-ngrams": {
"command": "python",
"args": ["/path/to/space-ngrams/src/server.py"]
}
}
}
OpenCode
Add to opencode.json in your project root or home directory:
{
"mcp": {
"space-ngrams": {
"type": "local",
"command": ["python", "/path/to/space-ngrams/src/server.py"]
}
}
}
π¬ Usage
The AI agent automatically uses these tools when needed. You can also trigger them explicitly:
find all calls to getUserById in D:/Projects/MyApp
show all .ts files in the src folder
read D:/Projects/MyApp/src/auth/service.ts lines 50-100
Tool Parameters
search_code
| Parameter | Required | Description |
|---|---|---|
pattern |
yes | Regex or literal string |
path |
yes | Directory or file to search in |
file_glob |
no | File type filter, e.g. *.py or **/*.ts |
context_lines |
no | Lines of context (default: 2) |
find_files
| Parameter | Required | Description |
|---|---|---|
pattern |
yes | Glob, e.g. *.py, **/*controller* |
path |
yes | Root directory to search in |
max_results |
no | Maximum results (default: 100) |
read_file
| Parameter | Required | Description |
|---|---|---|
path |
yes | Absolute or relative path |
start |
no | First line to read (default: 1) |
end |
no | Last line (inclusive) |
get_metrics
Returns performance statistics:
{
"search_code": {
"total_calls": 15,
"cache_hits": 8,
"cache_hit_rate": 53.3,
"avg_duration_ms": 45.2,
"min_duration_ms": 2.1,
"max_duration_ms": 234.5
}
}
βοΈ Configuration
Create a config file at ./space-ngrams.toml (project-specific) or ~/.space-ngrams/config.toml (global):
[cache]
enabled = true
ttl_seconds = 300 # 5 minutes
max_size_mb = 50
[limits]
max_search_results = 50
max_files_results = 100
max_read_lines = 200
default_context_lines = 2
search_timeout_seconds = 15
[ignore_patterns]
# Additional patterns to ignore (beyond .gitignore)
ignore_patterns = [
"*.log",
"*.tmp",
"node_modules/**",
"__pycache__/**",
]
[metrics]
enabled = true
See space-ngrams.example.toml for a full example with comments.
π Project Structure
space-ngrams/
βββ src/
β βββ server.py # MCP server implementation
βββ pyproject.toml # Python package metadata
βββ space-ngrams.example.toml # Example configuration
βββ LICENSE
βββ README.md # This file (English)
βββ README_RU.md # Russian translation
βββ docs/
βββ ARCHITECTURE.md # Architecture notes (optional)
π Also available in Russian.
π Logs and Cache
| Location | Purpose |
|---|---|
~/.space-ngrams/server.log |
Server logs and metrics |
~/.space-ngrams/cache/ |
Persistent cache storage |
π License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.