msenol/CodeSight
GitHub: msenol/CodeSight
企业级 AI 代码智能 MCP 服务器,将 Rust 高性能静态分析与 AI 能力结合,为 IDE 内的代码搜索、安全审计和质量评估提供一站式解决方案。
Stars: 0 | Forks: 1
# CodeSight MCP Server
[](https://github.com/msenol/CodeSight/actions/workflows/ci.yml)
[](https://opensource.org/licenses/MIT)
[](https://nodejs.org/)
[](https://www.rust-lang.org/)
**16 个工具** — 搜索、解释、追踪数据流、查找重复代码、安全分析、复杂度检查、AI 代码审查、Bug 预测等。
**8 种语言** — JavaScript, TypeScript, Python, Rust, Go, Java, C/C++, Ruby。
## 安装
**前置条件**:[Node.js](https://nodejs.org/) v20+ 和 [Rust](https://www.rust-lang.org/) 1.88+
```
git clone https://github.com/msenol/CodeSight.git
cd CodeSight
npm run setup
```
`npm run setup` 将安装依赖项,编译 Rust 原生模块,并构建 TypeScript。
## 在您的 IDE 中使用
### Claude Desktop
编辑 `claude_desktop_config.json`:
- **macOS**:`~/Library/Application Support/Claude/claude_desktop_config.json`
- **Windows**:`%APPDATA%\Claude\claude_desktop_config.json`
```
{
"mcpServers": {
"codesight": {
"command": "node",
"args": ["/path/to/CodeSight/typescript-mcp/dist/index.js"]
}
}
}
```
### VS Code (Continue)
编辑 `~/.continue/config.json`:
```
{
"mcpServers": {
"codesight": {
"command": "node",
"args": ["/path/to/CodeSight/typescript-mcp/dist/index.js"]
}
}
}
```
### VS Code (Cline)
添加至 Cline MCP 设置中:
```
{
"codesight": {
"command": "node",
"args": ["/path/to/CodeSight/typescript-mcp/dist/index.js"]
}
}
```
### Cursor
编辑 `~/.cursor/mcp.json`:
```
{
"mcpServers": {
"codesight": {
"command": "node",
"args": ["/path/to/CodeSight/typescript-mcp/dist/index.js"]
}
}
}
```
### Windsurf
编辑 `~/.codeium/windsurf/mcp_config.json`:
```
{
"mcpServers": {
"codesight": {
"command": "node",
"args": ["/path/to/CodeSight/typescript-mcp/dist/index.js"]
}
}
}
```
### Zed
编辑 `~/.config/zed/settings.json`:
```
{
"context_servers": {
"codesight": {
"command": "node",
"args": ["/path/to/CodeSight/typescript-mcp/dist/index.js"]
}
}
}
```
编辑配置后请重启您的 IDE。
## 为您的项目建立索引
```
cd typescript-mcp
# Index
node dist/cli/index.js index /path/to/your/project
# 检查 stats
node dist/cli/index.js stats
```
然后就可以向您的 AI 助手询问任何关于您代码的问题。
## 您可以问什么?
### 导航代码
| 提问 | 执行的操作 |
|-----|--------------|
| "显示所有身份验证函数" | 在您的代码库中搜索与 auth 相关的函数 |
| "`validateToken` 是做什么的?" | 结合代码上下文解释该函数 |
| "`UserService` 在哪里被使用?" | 查找跨文件的所有引用 |
| "追踪 `userId` 的数据流" | 展示该变量如何在代码中流转 |
| "列出所有 API 端点" | 发现 Express/Fastify/NestJS 路由 |
### 检查质量
| 提问 | 执行的操作 |
|-----|--------------|
| "这个模块的复杂度是多少?" | 圈复杂度与认知复杂度分析 |
| "查找重复的代码模式" | 检测复制粘贴的代码块 |
| "为这个文件提供重构建议" | 提供可操作的改进建议 |
| "分析整个代码库的复杂度" | 生成系统级的复杂度报告 |
### 安全
| 提问 | 执行的操作 |
|-----|--------------|
| "检查是否存在安全漏洞" | 扫描 SQL 注入、XSS、硬编码密钥 |
| "是否存在任何 SQL 注入风险?" | 针对性的安全分析 |
### AI 驱动功能(需要 API 密钥)
| 提问 | 执行的操作 |
|-----|--------------|
| "审查此代码的质量问题" | 带评分的 AI 代码审查 |
| "预测此模块中的潜在 Bug" | ML 增强的 Bug 预测 |
| "生成一个用于 users 的 REST 端点" | 上下文感知的代码生成 |
| "如何重构这个 service?" | AI 驱动的重构建议 |
| "我们的技术债是什么?" | 附带 ROI 的技术债评估 |
## MCP 工具 (16)
### 核心工具 (11) — 由 Rust 提供支持
| 工具 | 描述 |
|------|-------------|
| `search_code` | 自然语言搜索(通过 SQLite 实现约 4ms) |
| `explain_function` | 结合代码库上下文的函数解释 |
| `find_references` | 跨文件的符号引用查找 |
| `trace_data_flow` | 变量数据流追踪 |
| `analyze_security` | 安全漏洞检测 |
| `get_api_endpoints` | API 端点发现 |
| `check_complexity` | 基于 AST 的复杂度分析 |
| `find_duplicates` | Rabin-Karp 重复代码检测 |
| `suggest_refactoring` | 重构建议 |
| `index_codebase` | 基于 SQLite 持久化的并行索引 |
| `analyze_codebase_complexity` | 系统级复杂度分析 |
### AI 工具 (5)
| 工具 | 描述 |
|------|-------------|
| `ai_code_review` | 带质量评分的 AI 驱动代码审查 |
| `intelligent_refactoring` | AI 驱动的重构建议 |
| `bug_prediction` | 前瞻性 Bug 预测与风险评估 |
| `context_aware_code_generation` | 结合项目上下文的代码生成 |
| `technical_debt_analysis` | 带优先级排序的技术债评估 |
## CLI
```
cd typescript-mcp
node dist/cli/index.js index # Index a codebase
node dist/cli/index.js search # Search code
node dist/cli/index.js stats # Show statistics
node dist/cli/index.js server # Start MCP server (stdio)
```
## AI 功能
AI 工具需要 API 密钥。请将其添加至 `typescript-mcp/.env`:
```
OPENROUTER_API_KEY=sk-or-v1-your-key-here
OPENROUTER_MODEL=xiaomi/mimo-v2-flash:free
```
在 [openrouter.ai/keys](https://openrouter.ai/keys) 获取免费密钥。
**支持的提供商**:OpenRouter(100 多个模型)、Anthropic、OpenAI、Ollama(本地)。
如果未设置密钥,CodeSight 将回退到基于规则的分析——所有功能仍可正常使用,只是没有 AI。
## REST API
CodeSight 也可作为 HTTP 服务器运行(端口 4000):
```
# 启动
cd typescript-mcp && node dist/index.js
# 搜索
curl -X POST http://localhost:4000/api/search \
-H "Content-Type: application/json" \
-d '{"query": "authentication"}'
# Index
curl -X POST http://localhost:4000/api/index \
-H "Content-Type: application/json" \
-d '{"path": "/path/to/project"}'
# Health
curl http://localhost:4000/health
# 调用任意 MCP tool
curl -X POST http://localhost:4000/mcp/call \
-H "Content-Type: application/json" \
-d '{"tool": "check_complexity", "args": {"file_path": "src/index.ts"}}'
```
## Docker
```
# 生产环境 (PostgreSQL + Redis)
docker-compose up -d
# 开发环境 (hot reload)
docker-compose -f docker-compose.dev.yml up -d
# 检查状态
docker-compose ps
```
| 服务 | 端口 | 用途 |
|---------|------|---------|
| code-intelligence | 4000, 8080 | MCP Server + REST API |
| postgres | 5432 | 数据库 |
| redis | 6379 | 缓存 |
## 支持的语言
| 语言 | 解析 | 复杂度 | 重复检测 |
|----------|---------|------------|------------|
| JavaScript | ✅ | ✅ | ✅ |
| TypeScript | ✅ | ✅ | ✅ |
| Python | ✅ | ✅ | ✅ |
| Rust | ✅ | ✅ | ✅ |
| Go | ✅ | ✅ | ✅ |
| Java | ✅ | ✅ | ✅ |
| C/C++ | ✅ | ✅ | ✅ |
| Ruby | ✅ | ✅ | ✅ |
## 性能
| 操作 | 速度 | 备注 |
|-----------|-------|-------|
| 索引 | 约 123ms(73 个文件) | 并行 Rust 处理 |
| 搜索 | 约 4ms | 基于 SQLite 的关键字搜索 |
| 复杂度 | 约 2ms | 基于 AST 的 Rust 分析 |
| 重复检测 | O(n) | Rabin-Karp 滚动哈希 |
## 文档
- [**用户指南**](./docs/USER-GUIDE.md) — 详细的设置、用例、故障排除
- [MCP 工具参考](./docs/MCP-TOOLS.md) — 全部 16 个工具的文档
- [REST API 参考](./docs/API.md) — HTTP 端点
- [Rust FFI 桥接](./docs/rust-ffi-bridge.md) — 原生模块架构
- [性能基准测试](./docs/PERFORMANCE-BENCHMARKING.md) — 详细的指标
## 许可证
MIT — 详见 [LICENSE](LICENSE)。
## 致谢
- [Tree-sitter](https://tree-sitter.github.io/) — 语言解析
- [NAPI-RS](https://napi.rs/) — Rust/Node.js 桥接
- [Model Context Protocol](https://modelcontextprotocol.io/) — AI 集成标准
- [fastembed](https://github.com/Anush008/fastembed) — ONNX embeddings
标签:Claude, Cursor, CVE检测, GNU通用公共许可证, IDE插件, IPv6支持, MCP服务器, MITM代理, Node.js, Rust, TypeScript, VS Code, 人工智能, 代码复杂度检查, 代码审查, 代码智能, 代码索引, 代码静态分析, 企业级, 函数分析, 可视化界面, 多语言支持, 威胁情报, 安全插件, 安全测试框架, 开发者工具, 弱口令爆破, 搜索引擎查询, 数据流追踪, 测试用例, 漏洞预测, 用户模式Hook绕过, 网络流量审计, 自动化攻击, 语义搜索, 请求拦截, 重复代码检测