The Code Context MCP Server provides semantic search capabilities over local git repositories. It allows you to clone repositories, process code, generate embeddings for code chunks, and perform semantic searches to find relevant code snippets based on natural language queries.
# Clone the repository
git clone <repository-url>
cd code-context-mcp
# Install dependencies
npm install
# Build the project
npm run build
Set the following environment variables:
DATA_DIR
: Directory for SQLite database (default: '~/.codeContextMcp/data')REPO_CACHE_DIR
: Directory for cloned repositories (default: '~/.codeContextMcp/repos')For better embeddings performance:
# Install Ollama from https://ollama.ai/
# Pull the recommended embedding model
ollama pull unclemusclez/jina-embeddings-v2-base-code
Add the server to your Claude Desktop configuration file (claude_desktop_config.json
):
{
"mcpServers": {
"code-context-mcp": {
"command": "/path/to/your/node",
"args": ["/path/to/code-context-mcp/dist/index.js"]
}
}
}
The server provides a tool to clone repositories and perform semantic search:
{
"repoUrl": "https://github.com/username/repo.git",
"branch": "main",
"query": "Your search query",
"keywords": ["keyword1", "keyword2"],
"filePatterns": ["**/*.ts", "src/*.js"],
"excludePatterns": ["**/node_modules/**"],
"limit": 10
}
If you encounter architecture compatibility errors with better-sqlite3:
# Check your Node.js architecture
node -p "process.arch"
# Rebuild the SQLite package for ARM
npm rebuild better-sqlite3 --build-from-source
# Or for a clean installation:
npm uninstall better-sqlite3
export npm_config_arch=arm64
export npm_config_target_arch=arm64
npm install better-sqlite3 --build-from-source
For persistent configuration, add to your .zshrc or .bashrc:
export npm_config_arch=arm64
export npm_config_target_arch=arm64
To verify Ollama is working properly:
curl http://localhost:11434/api/embed -d '{"model":"unclemusclez/jina-embeddings-v2-base-code","input":"Llamas are members of the camelid family"}'
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.