Codebase MCP Server

by mengtoumingren

Not rated
GitHub

About

An intelligent codebase search engine that transforms local codebases into a natural language queryable knowledge base.

Details

Author
mengtoumingren
Categories
Developer Tools, Knowledge Base, Search

Setup

Install Codebase MCP Server in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/mengtoumingren/CodebaseIndexMCP

Follow the installation instructions in the repository README, then restart your MCP client.

An intelligent codebase search engine that transforms local codebases into a natural language queryable knowledge base.

Codebase MCP Server是一个专为开发者设计的智能代码库搜索引擎。它基于模型上下文协议(MCP),将本地代码库转化为一个可通过自然语言查询的智能知识库。与传统的文件遍历和文本搜索不同,本工具通过先进的语义理解能力,帮助开发者快速、精准地定位代码片段,从而大幅提升开发效率和代码理解深度。

- 告别繁琐的代码查找: 无需再手动浏览成百上千的文件,只需用自然语言描述您要找的功能,即可获得最相关的代码。
- 快速理解项目: 快速掌握新项目或复杂模块的核心逻辑,无论是功能实现、错误处理还是特定算法。
- 提升开发效率: 将更多时间用于编码,而非在代码的海洋中迷航。

- 多代码库支持: 可同时管理和搜索多个代码库的索引。
- 增量索引与自动更新: 监视文件系统变更,自动更新索引,确保搜索结果始终最新。
- 多嵌入模型支持: 支持多种嵌入模型提供商(如 DashScope、Ollama 等),灵活适应不同需求。
- 智能代码解析: 深度解析 C# 代码,识别类、方法、属性等关键结构。
- 持久化任务管理: 索引任务在后台持久化运行,即使服务器重启也能恢复。
- MCP 标准协议: 作为标准的 MCP 服务器,可与任何兼容的 MCP 客户端(如 Claude Desktop)无缝集成。

- .NET 9.0 或更高版本
- Qdrant 向量数据库 (localhost:6334)
- DashScope API 密钥

git clone <项目地址> cd CodebaseMcpServer
{ "CodeSearch": { "DashScopeApiKey": "your-dashscope-api-key", "QdrantConfig": { "Host": "localhost", "Port": 6334, "CollectionName": "codebase_embeddings" }, "DefaultCodebasePath": "D:\\Path\\To\\Your\\Codebase", "SearchConfig": { "DefaultLimit": 10, "MaxTokenLength": 8192, "BatchSize": 10 } } }
docker run -p 6333:6333 -p 6334:6334 qdrant/qdrant

- 工具:CreateIndexLibrary
- 示例: 假设您的项目位于D:\Projects\MyApp

{ "tool_name": "CreateIndexLibrary", "arguments": { "codebasePath": "D:\\Projects\\MyApp", "friendlyName": "My Awesome App" } }

索引创建需要一些时间,具体取决于代码库的大小。您可以使用GetIndexingStatus工具来监控进度。

- 工具:GetIndexingStatus
- 示例:

- 查看所有索引库的概览:

{ "tool_name": "GetIndexingStatus" }
{ "tool_name": "GetIndexingStatus", "arguments": { "codebasePath": "D:\\Projects\\MyApp" } }

- 工具:SemanticCodeSearch
- 示例: 查找用户认证相关的逻辑。

{ "tool_name": "SemanticCodeSearch", "arguments": { "query": "用户登录验证逻辑", "codebasePath": "D:\\Projects\\MyApp", "limit": 5 } }

- 重建索引: 当代码库发生重大变化或怀疑索引损坏时使用。

- 工具:RebuildIndex

首选代码查询工具。根据自然语言描述,精准定位相关的代码片段。它避免了完整读取和遍历文件,通过语义相似度直接找到目标代码,极大提升了代码查找和理解的效率。

- query(string, 必需): 自然语言搜索查询。

- 高效示例:'用户登录验证逻辑','数据库连接池管理','JWT令牌生成'
- 避免: 过于宽泛的查询,如'函数','类'

- 示例:'d:/VSProject/MyApp','./src'

{ "tool_name": "SemanticCodeSearch", "arguments": { "query": "如何实现文件上传的错误处理", "codebasePath": "D:\\Projects\\WebApp", "limit": 3 } }

为指定的代码库目录创建语义索引。索引是实现SemanticCodeSearch的前提。此过程会在后台运行,并自动启用文件监控以进行增量更新。

- codebasePath(string, 必需): 要索引的代码库目录的完整绝对路径。
- friendlyName(string, 可选): 为索引库指定一个易于识别的名称。如果未提供,则默认使用目录名。

{ "tool_name": "CreateIndexLibrary", "arguments": { "codebasePath": "C:\\Users\\Dev\\Documents\\MyProject", "friendlyName": "Main Project" } }

- codebasePath(string, 可选): 如果提供,则显示该特定代码库的详细状态。
- taskId(string, 可选): 如果提供,则查询特定索引任务的状态。
- : 如果两个参数均未提供,则显示所有索引库的状态总览。

{ "tool_name": "GetIndexingStatus", "arguments": { "codebasePath": "C:\\Users\\Dev\\Documents\\MyProject" } }

当代码结构发生重大变更或怀疑索引数据损坏时,此工具可用于清除旧索引并从头开始重新构建。

{ "tool_name": "RebuildIndex", "arguments": { "codebasePath": "C:\\Users\\Dev\\Documents\\MyProject" } }

- codebasePath(string, 必需): 要删除索引的代码库路径。
- confirm(bool, 必需, 默认false): 必须将此参数设置为true才能执行删除。首次调用(不带或带false)会返回一条确认提示。
- 首次调用 (获取确认提示):

{ "tool_name": "DeleteIndexLibrary", "arguments": { "codebasePath": "C:\\Path\\To\\OldProject" } }
{ "tool_name": "DeleteIndexLibrary", "arguments": { "codebasePath": "C:\\Path\\To\\OldProject", "confirm": true } }
{ "mcpServers": { "codebase-search": { "url": "http://localhost:5000/sse", "alwaysAllow": [ "SemanticCodeSearch", "GetIndexingStatus" ], "timeout": 30 } } }
graph TD subgraph MCP Client A[User/Client Application] end subgraph CodebaseMcpServer B[MCP Protocol Layer] C[MCP Tools Layer] D[Service Layer] E[Data & Infrastructure] end A -- MCP Request --> B B -- Tool Call --> C C -- Calls --> D D -- Interacts with --> E subgraph C [MCP Tools Layer] C1[CodeSearchTools] C2[IndexManagementTools] end subgraph D [Service Layer] D1[EnhancedCodeSemanticSearch] D2[IndexLibraryService] D3[FileWatcherService] D4[BackgroundTaskService] end subgraph E [Data & Infrastructure] E1["Embedding Providers\n(DashScope, Ollama, etc.)"] E2["Qdrant DB\n(Vector Storage)"] E3["LiteDB\n(Metadata & Task Storage)"] E4[C# Code Parser] end C1 -- Uses --> D1 C2 -- Uses --> D2 D1 -- Needs --> E1 D1 -- Needs --> E2 D2 -- Manages --> E2 D2 -- Manages --> E3 D2 -- Uses --> D3 D2 -- Uses --> D4 D1 -- Uses --> E4

- .NET 9.0: 运行时环境
- ModelContextProtocol: MCP 协议实现
- Qdrant.Client: 向量数据库客户端
- Newtonsoft.Json: JSON 序列化
- DashScope API: 文本嵌入服务
- Microsoft.Extensions.Hosting: 应用程序主机
- 在Tools/目录下创建新的工具类
- 使用[McpServerToolType][McpServerTool]特性
- 在Program.cs中注册新工具
- 扩展CodeSemanticSearch.cs中的代码解析逻辑
- 添加对应语言的正则表达式模式
- 更新文件模式配置

This is a web browser that enables your coding agent, such as Claude Code, to visit websites on your behalf and assist you in identifying bugs or creating UI test cases.

A local MCP server for AI coding agents. AST-aware indexing, semantic search, and automatic compression. Your agent stops re-reading your entire codebase every session.

Searching and access your AI coding sessions from Claude Code, Gemini CLI, opencode, and OpenAI Codex.

A platform-agnostic code analysis library with semantic search capabilities and MCP server support.

MCP server that ingests project docs once and lets Claude search by meaning instead of reading everything — saving tokens on large codebases

Easily provide codebase context to Large Language Models (LLMs).

A server for code indexing, searching, and analysis, enabling LLMs to interact with code repositories.

A knowledge management tool for code repositories using vector embeddings, powered by a local Ollama service.

Graph-powered code intelligence MCP server with semantic search, knowledge graph, and dependency analysis for Claude Code, Cursor, and Copilot.

Finds relevant code snippets, developer articles, and blog posts based on your queries.

MCP server for embedded C/C++ firmware — gives AI assistants (Claude Code, Cursor, OpenCode, etc.) real understanding of your codebase. Parses your actual build with libclang, extracts every symbol, and builds a persistent index with full-text search, call graph, and vector embeddings.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.