mcp-codesearch
mcp-codesearch is an MCP server providing AI-powered semantic code search with AST-aware chunking, hybrid vector search, and intelligent indexing for one or more codebases.
Search Tools
code_search– Search using natural language or a rich query syntax (function:name,class:name,path:prefix,file:pattern,-path:exclude,scope:function, etc.); auto-indexes on first use with incremental updatessearch_multiple– Search across multiple codebases concurrently, with results grouped per codebase or globally ranked via Reciprocal Rank Fusionsearch_changed– Search only files changed since a given git commit or time reference (e.g.,HEAD~5,3.days.ago)find_similar– Find code snippets semantically similar to a provided code excerptfind_references– Find all usages/references of a function, class, or variable
Index Management
index_status– Check indexing status (file count, last indexed time, pending changes)force_reindex– Force a complete re-index of a codebasepreview_index– Preview which files/chunks would be indexed without actually indexing
Collection Management
list_collections– List all indexed codebases and their collection namesdelete_collection– Remove the index for a specific codebasecleanup_orphans– Detect and delete orphaned collections whose directories no longer exist
Key Features
18+ languages with full AST-aware chunking (Python, JS/TS, Go, Rust, Java, C/C++, Ruby, PHP, Swift, Kotlin, Scala, C#, SQL, JSON, YAML, TOML) plus line-based fallback; Jupyter notebook support
Hybrid search combining dense embeddings and sparse TF-IDF with RRF fusion
Query synonym expansion (e.g.,
fn→function,db→database)Incremental indexing using mtime+size change detection
Flexible ignore support via
.gitignore,.git/info/exclude, and.codesearchignorePath boosting/demotion based on path patterns (e.g.,
src/+10%,vendor/-25%)Multiple output formats:
text,json, ormarkdown
Integrates with Git for change-aware search, allowing searches over files changed since a specific revision, and respects .gitignore patterns.
Supports Ollama as an embedding API for semantic code search, providing an OpenAI-compatible endpoint.
Supports OpenAI-compatible embedding APIs for semantic code search, enabling the use of models like text-embedding-3-small.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-codesearchsearch for function:processData path:src"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-codesearch
MCP server for semantic code search with AST-aware chunking, hybrid vectors, and query syntax.
Prerequisites
Python 3.12+
Linux or macOS (uses POSIX file locking via vector-core; not compatible with Windows)
Qdrant vector database (default:
localhost:6333)An OpenAI-compatible embedding API (e.g., llama.cpp, Ollama, or any
/v1/embeddingsendpoint; default:localhost:8080)
Related MCP server: reporelay
Installation
Requires vector-core.
pip install git+https://github.com/michaelkrauty/vector-core.git@v1.3.0
pip install git+https://github.com/michaelkrauty/mcp-codesearch.gitOr clone both repos and install locally:
git clone https://github.com/michaelkrauty/vector-core.git
git clone https://github.com/michaelkrauty/mcp-codesearch.git
pip install -e vector-core/
pip install -e mcp-codesearch/Quick Start
# Register with Claude Code:
claude mcp add codesearch -- mcp-codesearch
# Or add to your MCP client config (e.g., claude_desktop_config.json):
# {
# "mcpServers": {
# "codesearch": {
# "command": "mcp-codesearch",
# "env": {
# "VECTOR_QDRANT_URL": "http://localhost:6333",
# "VECTOR_EMBEDDING_URL": "http://localhost:8080",
# "VECTOR_EMBEDDING_MODEL": "your-model-name",
# "VECTOR_EMBEDDING_DIM": "768"
# }
# }
# }
# }Features
Hybrid Search: Dense embeddings + sparse TF-IDF with RRF fusion
AST-Aware Chunking: Tree-sitter extracts functions, classes, methods with context
18 Languages with AST Support: Python, JS/TS, Go, Rust, Java, C/C++, Ruby, PHP, Swift, Kotlin, Scala, C#, SQL, JSON, YAML, TOML (line-based fallback for Bash, HTML, CSS, and other file types)
Query Syntax:
function:name,class:name,file:pattern,path:prefix,-path:excludeIncremental Indexing: Change detection via mtime+size before hashing
Query Preprocessing: Synonym expansion (
fn→function,db→database)Flexible Ignores: Nested
.gitignore,.git/info/exclude, and.codesearchignore(gitignore syntax) honored at every directory level
Tools (11 total)
Search (5)
Tool | Description |
| Main search with auto-indexing |
| Search across multiple codebases |
| Search in recently changed files (git-aware) |
| Find code similar to a snippet |
| Find all usages of a symbol |
Index Management (3)
Tool | Description |
| Check indexing status, file count, pending changes |
| Force complete re-indexing |
| Preview what would be indexed |
Collection Management (3)
Tool | Description |
| List all indexed codebases |
| Remove index for a codebase |
| Remove orphaned collections |
Query Syntax
# Natural language (semantic search)
code_search("websocket reconnection logic")
# Function search
code_search("function:handleRequest")
code_search("fn:handleRequest") # alias
# Class search
code_search("class:WebSocketClient")
code_search("cls:WebSocketClient") # alias
# Path filtering
code_search("auth path:src/services")
code_search("test -path:vendor -path:node_modules")
# Filename filtering (glob, case-insensitive, matches filename only)
# Pushed into the retrieval layer when possible, so a match in the named
# file is found even if it would rank below the candidate pool
code_search("connection pooling file:db.py")
code_search("schema migration file:*.sql")
# Struct search (Rust, C, Go)
code_search("struct:Message")
# Combined
code_search("function:process_data path:src -path:test")
# Exact phrase
code_search('"exact function name"')Synonym Expansion
Common abbreviations automatically expanded:
fn,func→functioncls→classdb→databasews→websocketauth→authentication,authorizationreq,res→request,response
Additional Query Syntax
# Alternative function search aliases
code_search("def:processData")
code_search("method:handleRequest")
# Type/struct alias
code_search("type:UserConfig")
# Scope filters (restrict to chunk types)
code_search("error scope:function") # Only function chunks
code_search("model scope:class") # Only class chunks
code_search("validate scope:test") # Only test functions
code_search("handler scope:impl") # Non-test code only
# scope:method is an alias for scope:function; scope:struct, scope:enum,
# scope:interface, scope:type and scope:module are aliases for scope:classSearch Modes
Mode | Description |
| File-level results (overview) |
| Function/class-level results (detailed) |
| Combined ranking (default) |
AST Chunking
Tree-sitter extracts semantic units:
Functions (with docstrings)
Classes (with methods if small, or overview + separate methods if large)
Methods (with parent class context)
Modules (imports, top-level statements)
Fallback to line-based chunking for non-code files (JSON, YAML, TOML, Markdown).
Path Boosting
Search results boosted/demoted by path:
Pattern | Adjustment |
| +10% |
| +8% |
| -10% |
| -25% |
| -30% |
Git Integration
search_changed searches only files changed since a git revision or time. The
changed-file set is applied as a retrieval-layer filter, so results are ranked
within the changed files rather than intersected against a bounded whole-codebase
candidate pool (change sets over 500 files fall back to post-filtering).
search_changed("auth logic", since="HEAD~5")
search_changed("database", since="main")
search_changed("fix", since="abc123")
search_changed("config", since="3.days.ago")Configuration
Variable | Default | Description |
|
| Qdrant server |
|
| OpenAI-compatible embeddings API |
| (required) | Embedding model name (e.g., |
| (required) | Vector dimension (must match your model, e.g., |
Changing the embedding model. A codebase's index is tied to the embedding model it was built with. If you switch
VECTOR_EMBEDDING_MODEL, the next search or index of that codebase fails fast with a clear error pointing atforce_reindex, instead of a cryptic Qdrant dimension error (different-dimension swap) or silently meaningless results from incompatible embedding spaces (same-dimension swap — the model name is recorded in each collection's metadata and checked on reuse). Runforce_reindexon the affected codebase to rebuild it with the new model — each codebase is reindexed independently.
Codesearch-specific settings (configured via environment variables with the CODESEARCH_ prefix):
Variable | Default | Description |
|
| Lines threshold for splitting large classes |
|
| Merge chunks smaller than this |
|
| Max lines per fallback chunk |
|
| Overlap between fallback chunks |
|
| Max cached search results |
|
| Search cache TTL (seconds) |
|
| Fraction of cache to evict when full |
|
| Batch operation timeout (seconds) |
|
| Max concurrent upsert batches |
|
| Concurrent Qdrant operations during incremental indexing |
Change Detection
Fast incremental updates:
Check mtime + size (skip unchanged files)
Hash only modified files
Re-index only changed chunks
Avoids full re-embedding on every search.
Ignoring files
File discovery honors gitignore-syntax exclude rules at every directory level:
.gitignore— nested.gitignorefiles are respected, matching git semantics (deeper files override shallower,!negations re-include)..git/info/exclude— repo-local excludes that are not committed to git..codesearchignore— exclude paths from indexing without changing git's behavior. Same syntax as.gitignore; useful for vendored code, generated files, or large data you want tracked by git but kept out of the index.
Ignored directories are pruned during traversal, so excluded subtrees cost nothing. The global core.excludesFile is intentionally not consulted, so indexing stays reproducible regardless of per-machine git configuration.
Storage
Data | Location |
Index | Qdrant collection |
Metadata | Stored in Qdrant point payloads |
Each indexed codebase gets a unique collection based on path hash.
Supported Languages
Full tree-sitter AST support (18 languages): Python, JavaScript, TypeScript, Go, Rust, Java, C, C++, Ruby, PHP, Swift, Kotlin, Scala, C#, SQL, JSON, YAML, TOML
Line-based fallback: Bash, HTML, CSS, and all other file types (Markdown, Vue, Svelte, config files, etc.) are indexed with line-based chunking.
Jupyter notebooks (.ipynb): Notebooks are indexed by their code. Code cells are extracted (markdown, raw, and output cells are skipped) and chunked as Python with full AST support, so a notebook's functions and classes are searchable just like any other source file. Code-less or unparseable notebooks are skipped.
Dependencies
Requires vector-core components:
EmbeddingClient, GlobalVocabulary (embeddings)
QdrantStorage, HybridSearcher (storage)
External libraries:
tree-sitter-language-pack (AST parsing)
pathspec (.gitignore / .codesearchignore support)
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/michaelkrauty/mcp-codesearch'
If you have feedback or need assistance with the MCP directory API, please join our Discord server