Code Context (Semantic Code Search) MCP server

Enables semantic code search and understanding by cloning git repositories, splitting code into semantic chunks, and generating embeddings for natural language querying of large codebases
Back to servers
Provider
Foad K
Release date
Mar 25, 2025
Language
TypeScript
Stats
7 stars

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.

Prerequisites

  • Node.js (v16+)
  • Git
  • Ollama with an embedding model

Installation

# Clone the repository
git clone <repository-url>
cd code-context-mcp

# Install dependencies
npm install

# Build the project
npm run build

Configuration

Set the following environment variables:

  • DATA_DIR: Directory for SQLite database (default: '~/.codeContextMcp/data')
  • REPO_CACHE_DIR: Directory for cloned repositories (default: '~/.codeContextMcp/repos')

Setting Up Ollama for Embeddings

For better embeddings performance:

# Install Ollama from https://ollama.ai/

# Pull the recommended embedding model
ollama pull unclemusclez/jina-embeddings-v2-base-code

Integration with Claude Desktop

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"]
    }
  }
}

Using the Server

The queryRepo Tool

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
}

Parameters

  • repoUrl: URL of the git repository to clone (required)
  • branch: Branch to use (optional, defaults to repository's default branch)
  • query: Search query in natural language (required)
  • keywords: Optional list of keywords to filter results (case-insensitive)
  • filePatterns: Optional glob patterns to include specific files
  • excludePatterns: Optional glob patterns to exclude files
  • limit: Maximum number of results to return (default: 10)

Troubleshooting

Mac M-series (ARM) Architecture Issues

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

Testing Ollama Embeddings

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"}'

How to add this MCP server to Cursor

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.

Adding an MCP server to Cursor globally

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"
            ]
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later