代码上下文提供者 MCP
MCP 服务器为 AI 助手提供代码上下文和分析。它使用 WebAssembly Tree-sitter 解析器提取目录结构和代码符号,且无需任何原生依赖。
特征
- 生成目录树结构
- 分析 JavaScript/TypeScript 和 Python 文件
- 提取代码符号(函数、变量、类、导入、导出)
- 兼容MCP协议,与AI助手无缝集成
快速使用(MCP 设置)
通过 Smithery 安装
要通过Smithery自动为 Claude Desktop 安装 Code Context Provider:
视窗
MacOS/Linux
或者使用npm
全局安装:
然后通过运行来使用它:
可用工具
get_code_context
分析目录并返回其结构以及代码符号(可选)。
参数:
absolutePath
(字符串,必需):要分析的目录的绝对路径analyzeJs
(布尔值,可选):是否分析 JavaScript/TypeScript 和 Python 文件(默认值:false)includeSymbols
(布尔值,可选):是否在响应中包含代码符号(默认值:false)symbolType
(枚举,可选):如果 includeSymbols 为真,则包含的符号类型(选项:'functions'、'variables'、'classes'、'imports'、'exports'、'all',默认值:'all')filePatterns
(字符串数组,可选):要分析的文件模式(例如 [' .js', ' .py', 'config.*'])maxDepth
(数字,可选):要分析的最大目录深度(默认值:5 级)
注意:匿名函数会自动从结果中过滤掉。
工具调用时的输出文本示例
文件模式示例
您可以使用filePatterns
参数指定要分析的文件。这对于包含多种语言或特定文件的复杂项目非常有用。
例子:
["*.js", "*.py"]
- 分析所有 JavaScript 和 Python 文件["config.*"]
- 分析所有配置文件,无论其扩展名是什么。["package.json", "*.config.js"]
- 分析 package.json 和任何 JavaScript 配置文件[".ts", ".tsx", ".py"]
- 分析 TypeScript 和 Python 文件(使用扩展格式)
文件模式匹配支持:
- 带有通配符 (*) 的简单 glob 模式
- 直接文件扩展名(带或不带点)
- 确切的文件名
处理大型项目
对于非常大的项目,您可以使用maxDepth
参数来限制工具遍历目录的深度:
maxDepth: 2
- 仅分析根目录和一层子目录maxDepth: 3
- 分析根目录和两级子目录maxDepth: 0
- 仅分析根目录中的文件
这在以下情况下特别有用:
- 使用大型 monorepos
- 分析具有许多依赖项的项目
- 只关注主要源代码,不关注第三方库
支持的语言
支持以下代码符号分析:
- JavaScript (.js)
- JSX(.jsx)
- TypeScript(.ts)
- TSX(.tsx)
- Python(.py)
使用filePatterns
参数允许您在目录结构中包含其他文件类型,但符号分析可能会受到限制。
发展
设置开发环境
安装后
安装完成后,软件包的prepare
脚本会自动运行,以下载 WASM 解析器。如果由于某种原因下载失败,用户可以手动运行安装程序:
执照
麻省理工学院
如需更多信息或帮助
local-only server
The server can only run on the client's local machine because it depends on local resources.
Tools
通过使用具有零本机依赖性的 WebAssembly Tree-sitter 解析器提取目录结构和代码符号,为 AI 助手提供代码上下文和分析。
Related MCP Servers
- AsecurityAlicenseAqualityAnalyzes source code dependencies across multiple programming languages in the specified directory to identify file relationships, assisting in dependency management and project structure understanding.Last updated -1PythonMIT License
- -securityAlicense-qualityA Cursor-compatible toolkit that provides intelligent coding assistance through custom AI tools for code architecture planning, screenshot analysis, code review, and file reading capabilities.Last updated -7052TypeScriptMIT License
- AsecurityAlicenseAqualityA TypeScript-based Model Context Protocol toolkit that enables AI to interact with code files, manage translations, build projects, and search for files and code content.Last updated -33435TypeScriptMIT License
- -security-license-qualityIntegrates with Dumpling AI to provide data scraping, content processing, knowledge management, and code execution capabilities through tools for web interactions, document handling, and AI services.Last updated -2JavaScriptMIT License