CodeBrain MCP Server
Provides vector storage and similarity search for code embeddings using PostgreSQL with the pgvector extension.
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., "@CodeBrain MCP Serversemantically search for 'user login flow' in my-app"
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.
π§ CodeBrain MCP Server
Semantic code search powered by AI embeddings and vector similarity.
Integrate intelligent code search directly into Claude Desktop and Cursor through the Model Context Protocol (MCP).
π― What It Does
CodeBrain indexes your codebase using AST-based splitting and AI embeddings, enabling:
Semantic search - Find code by meaning, not just keywords
Smart chunking - AST-aware code splitting (respects functions, classes, etc.)
Fast retrieval - Vector similarity search with pgvector
Multi-project - Index and search across multiple codebases
Related MCP server: Claude Context MCP
π Quick Start
1. Prerequisites
# Docker running (for PostgreSQL + pgvector)
docker ps | grep codebrain
# Node.js 20+
node --version
# Dependencies installed
cd /Users/conorandrle/Documents/Coding/CodeBrainMCP/CodeBrain
pnpm install2. Setup Database
# Start PostgreSQL with pgvector (if not running)
docker run -d \
--name codebrain \
-p 5484:5432 \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=codebrain \
pgvector/pgvector:pg15
# Setup database schema
pnpm db:setup
pnpm db:migrate3. Configure Environment
Edit .env:
GEMINI_API_KEY=your_api_key_here
DATABASE_URL=postgresql://postgres:postgres@localhost:5484/codebrain?schema=cbmcp4. Test the Server
# Run tests
pnpm test
# Should show: β
28 tests passed
# Test MCP server starts
npx tsx src/index.ts
# Should output: π CodeBrain MCP Server started (stdio mode)
# Press Ctrl+C to stopπ Connect to Cursor/Claude
For Cursor
Open Cursor Settings β MCP Servers
Add server named
codebrainCopy this config:
{
"command": "npx",
"args": [
"-y",
"tsx",
"/Users/conorandrle/Documents/Coding/CodeBrainMCP/CodeBrain/src/index.ts"
],
"env": {
"GEMINI_API_KEY": "your_key_here",
"DATABASE_URL": "postgresql://postgres:postgres@localhost:5484/codebrain?schema=cbmcp"
}
}Restart Cursor
Verify - Check MCP panel shows "codebrain" connected
π Detailed guide: See CURSOR_SETUP.md
For Claude Desktop
Edit ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"codebrain": {
"command": "npx",
"args": [
"-y",
"tsx",
"/Users/conorandrle/Documents/Coding/CodeBrainMCP/CodeBrain/src/index.ts"
],
"env": {
"GEMINI_API_KEY": "your_key_here",
"DATABASE_URL": "postgresql://postgres:postgres@localhost:5484/codebrain?schema=cbmcp"
}
}
}
}Restart Claude Desktop.
π οΈ Available MCP Tools
1. index_codebase
Index a codebase for semantic search.
Parameters:
{
projectName: string; // Unique project identifier
rootPath: string; // Absolute path to code
force?: boolean; // Re-index existing files
}Example:
"Index my React project at /Users/me/projects/my-app with name 'my-app'"
2. semantic_search
Search code semantically across indexed projects.
Parameters:
{
query: string; // What to search for
projectName?: string; // Filter by project
topK?: number; // Number of results (default: 5)
threshold?: number; // Similarity threshold (default: 0.5)
}Example:
"Find authentication logic in my-app"
3. list_projects
List all indexed projects.
Parameters: None
Example:
"Show me all indexed projects"
4. get_project_stats
Get statistics for a project.
Parameters:
{
projectName: string; // Project to query
}Example:
"Show me stats for the my-app project"
π Architecture
βββββββββββββββββββββββββββββββββββββββββββββββ
β Cursor / Claude Desktop β
β (MCP Client) β
βββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β MCP Protocol (stdio)
β
βββββββββββββββββββΌββββββββββββββββββββββββββββ
β CodeBrain MCP Server β
β βββββββββββββββββββββββββββββββββββββββ β
β β AST Code Splitter β β
β β - JavaScript/TypeScript β β
β β - Python, Go, Rust, Java, C++ β β
β ββββββββββββββββ¬βββββββββββββββββββββββ β
β β β
β ββββββββββββββββΌβββββββββββββββββββββββ β
β β Gemini Embeddings β β
β β - 768-dimensional vectors β β
β β - Semantic descriptions β β
β ββββββββββββββββ¬βββββββββββββββββββββββ β
β β β
β ββββββββββββββββΌβββββββββββββββββββββββ β
β β Vector Search β β
β β - Cosine similarity β β
β β - Threshold filtering β β
β ββββββββββββββββ¬βββββββββββββββββββββββ β
βββββββββββββββββββΌββββββββββββββββββββββββββββ
β
βββββββββββββββββββΌββββββββββββββββββββββββββββ
β PostgreSQL + pgvector β
β ββββββββββββββββββββββββββββββββββββββββ β
β β Projects β Files β Chunks β Embeds β β
β β Normalized relational schema β β
β ββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββπ§ͺ Testing
# Run all tests
pnpm test
# Watch mode
pnpm test:watch
# Individual test suites
pnpm test:splitter # AST code splitter
pnpm test:indexing # Indexing workflow
pnpm test:search # Semantic search
pnpm test:embedding # Embedding generation
# Integration test (end-to-end)
pnpm test:integrationπ Graph Viewer (React)
Visualise the code graph in the browser with the React/Vite viewer.
# Start the Graph API server (serves graph JSON on http://localhost:4000)
pnpm graph:server
# In a separate terminal, install and run the viewer UI
cd apps/graph-viewer
pnpm install
pnpm dev
# Open the browser UI β http://localhost:5173Override the API target with VITE_GRAPH_API_URL (inside apps/graph-viewer/.env) if the server runs elsewhere.
π Project Structure
CodeBrain/
βββ src/
β βββ index.ts # MCP server entry point
β βββ core/
β β βββ indexing.ts # Indexing orchestration
β β βββ search.ts # Semantic search
β β βββ splitter.ts # AST-based code splitting
β β βββ embedding/
β β βββ base-embedding.ts # Embedding interface
β β βββ gemini-embedding.ts # Gemini implementation
β βββ test/
β βββ *.test.ts # Unit tests
β βββ utils.ts # Test utilities
βββ db/
β βββ index.ts # Prisma client
β βββ setup.ts # Database setup script
β βββ vector-indexes.ts # Vector index management
βββ prisma/
β βββ schema.prisma # Database schema
βββ .env # Environment variables
βββ mcp-config.json # MCP configuration template
βββ CURSOR_SETUP.md # Cursor integration guide
βββ README.md # This fileποΈ Database Schema
Project (1) ββ
ββ> File (N) ββ
ββ> Chunk (N) ββ
ββ> Embedding (N)Project: Root container (name, rootPath)
File: Individual source files (path, language, hash)
Chunk: Code segments (text, lines, AST metadata)
Embedding: Vector representations (768-dim, model, similarity search)
π§ Development
Scripts
pnpm dev # Start with auto-reload
pnpm start # Start server
pnpm build # Compile TypeScript
pnpm db:setup # Setup database + pgvector
pnpm db:migrate # Run migrations
pnpm db:generate # Generate Prisma client
pnpm db:studio # Open Prisma StudioEnvironment Variables
# Required
GEMINI_API_KEY=your_gemini_api_key
DATABASE_URL=postgresql://user:pass@host:port/db?schema=cbmcp
# Optional
NODE_ENV=developmentπ Troubleshooting
MCP Connection Issues
Problem: Server won't connect in Cursor
Solutions:
Test manually:
npx tsx src/index.ts(should output startup message)Check absolute path in config matches your directory
Verify environment variables in MCP config
Restart Cursor completely (Cmd+Q, then reopen)
Check MCP output panel for error logs
Database Issues
Problem: type "vector" does not exist
Solution:
pnpm db:setup # This installs pgvector in cbmcp schemaProblem: Connection refused
Solution:
docker ps | grep codebrain # Verify container running
docker start codebrain # Start if stoppedEmbedding Issues
Problem: GEMINI_API_KEY is required
Solution: Add API key to .env and MCP config
Performance Issues
Problem: Indexing is slow
Solutions:
Embeddings are cached - subsequent runs are faster
Adjust batch size in
indexing.tsif neededConsider excluding large directories (node_modules, etc.)
π Performance
Indexing: ~2-5 seconds per file (first time, includes embedding generation)
Re-indexing: ~100ms per file (if unchanged, uses hash comparison)
Search: ~500ms per query (includes embedding + vector search)
Storage: ~10KB per code chunk (text + embedding + metadata)
π Security
API keys stored in environment variables (not in code)
Database credentials configurable
MCP runs locally (no external API calls except Gemini)
Vector embeddings don't leave your machine
π License
MIT
π€ Contributing
This is a personal project, but feel free to fork and adapt for your needs!
π Learn More
β Status
β Database setup and migrations
β AST-based code splitting
β Gemini embedding integration
β Vector similarity search
β MCP server implementation
β Comprehensive test suite (28 tests)
β Multi-project support
β Cursor/Claude integration ready
Ready for production use! π
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-qualityFmaintenanceEnables semantic search across your codebase using Google's Gemini embeddings and Qdrant Cloud vector storage. Supports 15+ programming languages with smart code chunking and real-time file change monitoring.Last updated1519MIT
- Flicense-qualityDmaintenanceEnables AI assistants to index and search codebases using semantic search powered by multiple embedding providers (OpenAI, VoyageAI, Gemini, Ollama) and vector database storage.Last updated
- Alicense-qualityAmaintenanceEnables local semantic search over documents and code for Claude Code and Claude Desktop, running entirely offline with local embeddings and vector storage.Last updated3MIT
- Flicense-qualityFmaintenanceSemantic code search for Claude Code, enabling natural language codebase indexing and search using AI embeddings.Last updated1
Related MCP Connectors
Connect your team's living knowledge base β docs, data, issues, CRM β to Claude and ChatGPT.
Search your knowledge bases from any AI assistant using hybrid RAG.
Connect AI assistants to your GitHub-hosted Obsidian vault to seamlessly access, search, and analyβ¦
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- 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/candrle20/codebrain'
If you have feedback or need assistance with the MCP directory API, please join our Discord server