# 技术文档摘要
<div align="center">
<img src="https://raw.githubusercontent.com/Sunwood-ai-labs/source-sage-mcp-server/refs/heads/master/assets/sourcesage-magical.svg" width="100%">
# 🌟 SourceSage MCP
<p align="center">
<img alt="GitHub" src="https://img.shields.io/github/license/sunwood-ai-labs/source-sage-mcp-server">
<img alt="GitHub package.json version" src="https://img.shields.io/github/package-json/v/sunwood-ai-labs/source-sage-mcp-server">
<img alt="GitHub issues" src="https://img.shields.io/github/issues/sunwood-ai-labs/source-sage-mcp-server">
<img alt="GitHub pull requests" src="https://img.shields.io/github/issues-pr/sunwood-ai-labs/source-sage-mcp-server">
<img alt="npm" src="https://img.shields.io/npm/v/@sunwood-ai-labs/source-sage-mcp-server">
<img alt="npm" src="https://img.shields.io/npm/dt/@sunwood-ai-labs/source-sage-mcp-server">
</p>
## 📖 概要
SourceSage 是一个 MCP 服务器,它以美观的 Markdown 格式可视化项目的目录结构。使用 TypeScript 实现,提供了高级定制性和灵活的排除模式功能。此外,它还能自动文档化每个文件的内容,使项目整体概貌更加清晰。
</div>
## 🎯 主要特点
- 📁 目录结构的 Markdown 输出
- 🎨 美观的树形结构显示(ASCII艺术)
- 📝 文件内容的自动文档化(带有语言特定的语法高亮)
- 🔍 灵活的排除模式(.SourceSageignore)
- 🚀 使用 ES2022 和 Node16 模块系统实现最新版本
- 💫 通过严格的类型检查确保高可靠性
## 🛠️ 技术栈
- 🔷 TypeScript (目标 ES2022)
- 📦 Model Context Protocol SDK (v0.6.0)
- 🌐 Node.js (Node16 模块系统)
- 📚 glob (v11.0.0) - 文件模式匹配
- 🎭 ignore (v6.0.2) - 灵活的文件排除功能
## 📂 项目结构
```plaintext
source-sage/
├── assets/
│ └── header.svg # 项目头部图像
├── src/
│ └── index.ts # 主服务器实现
├── build/ # 编译后的 JavaScript 文件
├── .gitignore # Git 排除设置
├── .SourceSageignore # SourceSage 特有的排除设置
├── package.json # 项目配置及依赖关系
├── README.md # 项目文档
└── tsconfig.json # TypeScript 配置
{
"compilerOptions": {
"target": "ES2022", // 利用最新的 ECMAScript 功能
"module": "Node16", // 使用 Node.js 16 的最新模块系统
"moduleResolution": "Node16",
"outDir": "./build", // 编译后文件的输出位置
"rootDir": "./src", // 源文件的根目录
"strict": true, // 启用严格的类型检查
"esModuleInterop": true, // 确保与 CommonJS 模块的互操作性
"skipLibCheck": true, // 跳过类型定义文件的检查
"forceConsistentCasingInFileNames": true // 严格管理文件名的大小写
}
}
npm install -g @sunwood-ai-labs/source-sage-mcp-server
git clone https://github.com/sunwood-ai-labs/source-sage-mcp-server.git
cd source-sage-mcp-server
npm install
npm run build
{
"mcpServers": {
"source-sage": {
"command": "node",
"args": ["C:/path/to/source-sage/build/index.js"]
}
}
}
生成项目的目录结构,并创建包含文件内容的详细文档。
interface GenerateStructureArgs {
// 要生成结构的目录路径(必需)
// 请务必使用绝对路径
path: string;
// .SourceSageignore 文件的路径(可选)
// 如果指定了,请使用绝对路径
ignorePath?: string;
}
// 使用绝对路径(推荐)
const result = await mcpClient.callTool('source-sage', 'generate_structure', {
path: 'C:/Users/your-name/path/to/your-project',
ignorePath: 'C:/Users/your-name/path/to/your-project/.SourceSageignore'
});
实际项目结构的输出示例:
# 📁 项目:source-sage
## 🌳 目录结构
操作系统:win32
目录:C:\Users\your-name\source-sage
└─ source-sage/
├─ src/
│ └─ index.ts # MCP 服务器的主要实现
├─ package.json # 项目的依赖关系和配置
├─ README.md # 项目的详细说明
└─ tsconfig.json # TypeScript 编译配置
此输出包括以下信息:
在项目的根目录下创建 .SourceSageignore 文件,并描述要排除的模式。默认情况下,包含以下排除模式:
# 版本控制系统相关
.git
.gitignore
# 缓存文件
__pycache__
.pytest_cache
**/__pycache__/**
*.pyc
# 构建和分发相关
build
dist
*.egg-info
# 临时文件和输出
output
output.md
test_output
.SourceSageAssets
.SourceSageAssetsDemo
# 资产
*.png
*.svg
assets
# 其他
LICENSE
example
folder
package-lock.json
# 📁 项目:my-project
## 🌳 目录结构
操作系统:win32
目录:C:\path\to\my-project
└─ my-project/
├─ src/
│ ├─ index.ts
│ └─ utils/
│ └─ helper.ts
└─ package.json
## 📄 文件内容
### 📝 `src/index.ts`
**类型**:TypeScript 源文件
SourceSageServer 类提供 MCP 服务器的核心功能buildTree 方法递归解析目录结构ignore 包实现灵活的文件排除glob 包进行高效的文件扫描# 克隆仓库
git clone https://github.com/sunwood-ai-labs/source-sage-mcp-server.git
# 安装依赖
npm install
# 开发构建
npm run build
# 启动开发服务器
npm run inspector
npm run build: 编译 TypeScript 并设置执行权限npm run prepare: 安装时自动构建npm run watch: 开发时自动编译npm run inspector: 启动 MCP 检查器git checkout -b feature/amazing-feature)git commit -m '✨ feat: 添加了令人惊叹的功能')git push origin feature/amazing-feature)MIT 许可证 - 详情请参阅 LICENSE 文件。