AI助手的高级代码搜索与转换工具
一个全面的模型上下文协议(MCP)服务器,结合了ugrep和ast-grep的理念,提供现代开发工作流程中的智能搜索和替换功能。
<a href="https://glama.ai/mcp/servers/@mixelpixx/CodeSeeker-MCP"> <img width="380" height="200" src="https://gips1.baidu.com/it/u=3080440621,1344487166&fm=3081&app=3081&f=PNG?w=760&h=400" alt="CodeSeeker-MCP MCP服务器" /> </a>CodeSeeker为AI助手提供了完整的搜索和替换功能:
Ubuntu/Debian:
sudo apt-get install ugrep
macOS (Homebrew):
brew install ugrep
Windows (Chocolatey):
choco install ugrep
从源码安装:
git clone https://github.com/Genivia/ugrep.git
cd ugrep
./configure
make
sudo make install
验证安装:
ugrep --version
# 应该显示版本7.4或更高
确保已安装Node.js 18+:
node --version
# 应该显示v18.0.0或更高
git clone https://github.com/yourusername/codeseeker-mcp.git
cd codeseeker-mcp
npm install
npm run build
npm test
# 应该显示所有测试通过
添加到您的Claude Desktop配置文件中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"codeseeker": {
"command": "node",
"args": ["/绝对路径/codeseeker-mcp/build/index.js"]
}
}
}
注意: 将/绝对路径/codeseeker-mcp替换为您实际的安装路径。
在JavaScript文件中搜索"function":
- 模式: function
- 文件类型: js,ts
- 路径: ./src
- 区分大小写: false
查找标记为urgent但未标记为later的TODO项:
- 查询: TODO AND urgent -NOT later
- 文件类型: cpp,h,js,py
查找最多有2个字符错误的"function"(匹配"functoin"、"functio"等):
- 模式: function
- 最大错误数: 2
- 文件类型: js,ts,py
将旧函数名替换为新函数名(先预览):
- 模式: oldFunctionName
- 替换: newFunctionName
- 文件类型: js,ts
- 预览: true (预览更改)
- 备份: true (创建备份)
一次操作中的多个替换:
- 将"var "替换为"const "
- 将"== "替换为"=== "
- 文件类型: js,ts
- 预览: true
在整个代码库中重构函数名:
- 结构类型: function
- 旧模式: getUserData
- 新模式: fetchUserData
- 语言: typescript
- 预览: true
basic_search标准模式搜索,带过滤选项。
参数:
pattern (必需): 搜索模式或正则表达式path (可选): 搜索目录(默认: 当前目录)caseSensitive (可选): 区分大小写的搜索(默认: false)fileTypes (可选): 逗号分隔的文件类型(例如: "js,py,cpp")excludeTypes (可选): 排除的文件类型contextLines (可选): 匹配周围的行数maxResults (可选): 最大结果数(默认: 100)boolean_search类似Google的布尔操作符搜索。
参数:
query (必需): 布尔查询(支持AND、OR、NOT、括号)path, fileTypes, maxResults: 同基础搜索示例查询:
"error AND (critical OR fatal)""TODO AND urgent -NOT completed""function OR method -NOT test"fuzzy_search近似模式匹配。
参数:
pattern (必需): 搜索模式maxErrors (可选): 允许的字符错误数 1-9(默认: 2)path, fileTypes, maxResults: 同基础搜索archive_search搜索压缩文件和归档。
参数:
pattern (必需): 搜索模式path, maxResults: 同基础搜索archiveTypes (可选): 搜索的归档类型code_structure_search查找特定代码结构。
参数:
structureType (必需): 要搜索的类型(function, class, method, import, variable)name (可选): 要搜索的具体名称language (必需): 编程语言(js, ts, py, java, cpp)path, maxResults: 同基础搜索interactive_search启动交互式TUI模式。
参数:
initialPattern (可选): 初始搜索模式path (可选): 初始目录search_and_replace安全的查找和替换,带有预览。
参数:
pattern (必需): 搜索模式或正则表达式replacement (必需): 替换文本(支持$1, $2捕获组)path (可选): 要处理的目录(默认: 当前目录)fileTypes (可选): 要包含的文件类型caseSensitive (可选): 区分大小写的搜索(默认: false)dryRun (可选): 预览模式(默认: true)maxFiles (可选): 最大处理文件数(默认: 50)backup (可选): 创建备份(默认: true)bulk_replace多个查找/替换操作。
参数:
replacements (必需): {pattern, replacement, description}对象数组path, fileTypes, caseSensitive, dryRun, backup: 同search_and_replacecode_refactor语言感知的代码重构。
参数:
structureType (必需): 代码结构类型(function, class, variable, import)oldPattern (必需): 要查找的模式newPattern (必需): 替换模式language (必需): 编程语言(js, ts, py, java, cpp)path, dryRun, backup: 同search_and_replacelist_file_types获取所有支持的文件类型用于过滤。
get_search_stats获取详细的搜索统计信息和性能指标。
codeseeker-mcp/
├── src/
│ └── index.ts # 主服务器实现
├── build/ # 编译后的JavaScript输出
├── package.json # Node.js依赖和脚本
├── tsconfig.json # TypeScript配置
├── test.js # 测试套件
├── README.md # 此文件
└── SETUP.md # 快速设置指南
npm run build # 编译TypeScript
npm run dev # 开发模式监视
npm run inspector # 使用MCP检查器调试
# 测试基本功能
npm test
# 使用MCP检查器进行交互式测试
npm run inspector
# 使用Claude Desktop测试
# (添加到配置并重启Claude Desktop)
所有替换操作默认启用预览模式以保证安全:
在进行更改时:
"ugrep未找到"
ugrep --version以验证安装"权限被拒绝"
chmod +x build/index.js(在Unix系统上)"模块未找到错误"
npm install以安装依赖"Claude Desktop未显示工具"
"未找到要处理的文件"
maxResults参数限制git checkout -b feature/amazing-feature)git commit -m '添加一些惊人的功能')git push origin feature/amazing-feature)MIT许可证 - 详情参见LICENSE文件。
| 工具 | 目的 | 输入 | 输出 |
|---|---|---|---|
basic_search | 标准文本搜索 | 模式 + 过滤器 | 匹配项及上下文 |
boolean_search | 逻辑搜索查询 | 布尔表达式 | 过滤结果 |
fuzzy_search | 近似匹配 | 模式 + 错误容忍度 | 模糊匹配 |
archive_search | 搜索压缩文件 | 模式 + 归档类型 | 归档内容 |
code_structure_search | 查找代码元素 | 结构类型 + 语言 | 代码定义 |
search_and_replace | 查找和替换文本 | 模式 + 替换 | 预览/更改 |
bulk_replace | 多个替换 | 操作数组 | 批量结果 |
code_refactor | 重构代码结构 | 旧/新模式 + 语言 | 重构代码 |
interactive_search | 启动TUI模式 | 初始模式 | 运行命令 |
list_file_types | 显示支持的类型 | 无 | 可用扩展 |
get_search_stats | 搜索指标 | 搜索参数 | 性能统计 |
CodeSeeker - 每次搜索都充满智慧,每次更改都精准无误。
可用工具总数: 11 (8搜索 + 3替换)