本地代码知识库同步 MCP 工具
这是一个基于 模型上下文协议(Model Context Protocol, MCP)开发的服务端工具,旨在将你的本地项目代码目录无缝连接到支持 MCP 的 AI 应用(如 Claude 桌面版),从而将你的本地代码库变成一个可供 AI 实时查询和分析的动态知识库。
你不再需要手动上传文件或依赖云端仓库同步,AI 可以直接与你本地最新的代码进行交互。
主要功能
本项目通过实现多个 MCP 工具,为 AI 提供了与本地文件系统交互的超能力:
基础工具
list_project_files
:递归地列出所有已配置目录中的文件,提供项目全貌read_file_content
:读取单个指定文件的完整内容,用于深度代码分析analyze_project_structure
:生成项目结构的概览和统计信息,帮助快速了解项目
智能搜索工具
search_code_content
:在整个代码库中进行智能搜索,支持:- 普通文本搜索和正则表达式搜索
- 深层目录结构精确定位
- 可配置的上下文行数,避免返回过多内容
- 文件类型过滤和结果数量控制
高效读取工具
read_multiple_files
:使用glob
模式批量读取多个文件的内容,方便提供模块级上下文extract_function_definition
:精确提取指定函数/方法的完整定义,包括注释和装饰器read_file_section
:读取文件的指定行范围,获取精确的代码片段
快速开始
安装与配置
- 克隆仓库
- 安装依赖
- 配置同步路径
- 打开
src/index.ts
文件 - 找到
SYNC_PATHS
这个常量数组 - 将其中的示例路径替换为你自己电脑上希望同步的项目的绝对路径。你可以配置一个或多个路径:
- 打开
- 构建项目 运行构建命令,将 TypeScript 代码编译为 JavaScript:成功后,会在项目根目录下生成一个
build
文件夹。
连接到 Claude 桌面版
- 找到并编辑 Claude 配置文件:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
如果文件或目录不存在,请手动创建它。
- Windows:
- 添加 MCP 服务器配置 将以下 JSON 内容添加到配置文件中(注意:必须将
args
中的路径替换为你自己项目build/index.js
文件的绝对路径): - 重启 Claude完全退出并重新启动 Claude 桌面应用。成功后,你可以在聊天输入框下的
Search and Tools
菜单项内看到localProjectSync
这个工具。
使用示例
基础项目探索
智能代码搜索
精确代码提取
批量文件分析
组合使用示例
高级搜索技巧
注意事项
- 安全: 本工具具有读取指定目录内所有文件的权限。请确保你配置的
SYNC_PATHS
指向的是安全的项目目录,切勿将其指向包含敏感信息(如私钥、密码文件等)的系统目录 - 性能: 对于包含数十万个文件的超大型项目,
list_project_files
和search_code_content
的首次执行可能会比较慢 - 路径格式: 在与 AI 交互时,请尽量使用工具返回的、带前缀的完整文件路径(例如
[backend/src]/main.ts
),以确保 AI 能准确调用工具
更新日志
v3.0.0
- 新增
extract_function_definition
工具 - 新增
read_file_section
工具 search_code_content
支持正则表达式和上下文行- 修复深层目录搜索问题
- 优化conversation length使用
v2.0.0
- 新增
search_code_content
和read_multiple_files
- 新增
analyze_project_structure
local-only server
The server can only run on the client's local machine because it depends on local resources.
Tools
A Model Context Protocol (MCP) server that enables AI applications to access and analyze local code repositories without manual uploads, providing file listing, content reading, code searching, and project structure analysis capabilities.
Related MCP Servers
- -securityAlicense-qualityA Model Context Protocol (MCP) server that allows AI models to safely access and interact with local file systems, enabling reading file contents, listing directories, and retrieving file metadata.Last updated -139JavaScriptMIT License
- AsecurityFlicenseAqualityAn all-in-one Model Context Protocol (MCP) server that connects your coding AI to numerous databases, data warehouses, data pipelines, and cloud services, streamlining development workflow through seamless integrations.Last updated -2Python
- -securityAlicense-qualityModel Context Protocol (MCP) server that provides AI assistants with advanced web research capabilities, including Google search integration, intelligent content extraction, and multi-source synthesis.Last updated -283TypeScriptMIT License
- AsecurityFlicenseAqualityA Model Context Protocol (MCP) server that enables AI assistants to perform comprehensive file operations including finding, reading, writing, editing, searching, moving, and copying files with security validations.Last updated -7TypeScript