Code Context MCP Server

by fkesheh
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Allows cloning and processing of local git repositories, extracting code context from different branches and files for semantic search.

代码上下文 MCP 服务器

一个模型上下文协议 (MCP) 服务器,用于提供来自本地 Git 代码库的代码上下文。此服务器允许您:

  1. 本地克隆 git 存储库
  2. 处理分支和文件
  3. 为代码块生成嵌入
  4. 对代码执行语义搜索

特征

  • 使用本地 git 存储库而不是 GitHub API
  • 将数据存储在 SQLite 数据库中
  • 将代码拆分成语义块
  • 使用 Ollama 为代码块生成嵌入
  • 提供代码语义搜索

先决条件

  • Node.js(v16+)
  • Git
  • 带有嵌入模型的 Ollama

安装

# Clone the repository git clone <repository-url> cd code-context-mcp # Install dependencies npm install # Build the project npm run build

配置

设置以下环境变量:

  • DATA_DIR :SQLite 数据库目录(默认值:'~/.codeContextMcp/data')
  • REPO_CACHE_DIR :克隆存储库的目录(默认值:'~/.codeContextMcp/repos')

使用 Ollama

为了获得更快、更强大的嵌入,您可以使用 Ollama:

# Install Ollama from https://ollama.ai/ # Pull an embedding model (unclemusclez/jina-embeddings-v2-base-code is recommended) ollama pull unclemusclez/jina-embeddings-v2-base-code

用法

与 Claude Desktop 一起使用

将以下配置添加到您的 Claude Desktop 配置文件( claude_desktop_config.json ):

{ "mcpServers": { "code-context-mcp": { "command": "/path/to/your/node", "args": ["/path/to/code-context-mcp/dist/index.js"] } } }

工具

服务器提供以下工具:

查询Repo

克隆存储库、处理代码并执行语义搜索:

{ "repoUrl": "https://github.com/username/repo.git", "branch": "main", // Optional - defaults to repository's default branch "query": "Your search query", "keywords": ["keyword1", "keyword2"], // Optional - filter results by keywords "filePatterns": ["**/*.ts", "src/*.js"], // Optional - filter files by glob patterns "excludePatterns": ["**/node_modules/**"], // Optional - exclude files by glob patterns "limit": 10 // Optional - number of results to return, default: 10 }

branch参数是可选的。如果没有提供,工具将自动使用仓库的默认分支。

keywords参数是可选的。如果提供,结果将被过滤,仅包含至少包含一个指定关键字的区块(不区分大小写匹配)。

filePatternsexcludePatterns参数是可选的。它们允许你使用 glob 模式(例如, **/*.ts表示所有 TypeScript 文件)来过滤需要处理和搜索的文件。

数据库架构

该服务器使用具有以下架构的 SQLite:

  • repository :存储有关存储库的信息
  • branch :存储有关分支的信息
  • file :存储有关文件的信息
  • branch_file_association :将文件与分支关联
  • file_chunk :存储代码块及其嵌入

执照

麻省理工学院

-
security - not tested
A
license - permissive license
-
quality - not tested

MCP 服务器提供对本地 git 存储库的语义搜索,使用户能够克隆存储库、处理分支以及通过矢量化代码块搜索代码。

  1. Features
    1. Prerequisites
      1. Installation
        1. Configuration
          1. Using Ollama
        2. Usage
          1. Using with Claude Desktop
        3. Tools
          1. queryRepo
        4. Database Schema
          1. License
            ID: ciwrw699vq