MCP项目上下文服务器
人工智能工具(Claude Code、Roovodev 等)的自动项目文档。
扫描您的代码结构并将其作为 MCP 资源提供:
- API路线(Express/Fastify Endpunkte)
- 数据库模式(SQLite Tabellen实时)
- 服务函数(导出函数)
- 文件结构(Ordnerstruktur)
- 体系结构概述(aus CLAUDE.md/README.md)
特性
- 实时扫描每次请求都会重新扫描文件
- SQLite支持直接从数据库中读取方案
- JSDoc解析从评论中提取描述
- Raspberry Pi 优化没有严重的依赖性
- PM2就绪可持续运行的生态系统配置
安装
cd ~/projects/mcp-project-context
# Dependencies installieren
npm install
# Test-Start
npm start重要:MCP服务器如何工作
使用STDIO传输运行MCP服务器 不 作为 Daemon(如 Web 服务器)。 而是由Claude Code / Roovodev制作 根据需要启动 通过 stdin/stdout 进行通信。
这意味着:
- 不需要PM2 MCP 服务器本身
- Claude Code 自动生成进程
- 这个过程只要你的Claude代码会话就会运行
(可选) PM2 用于开发/测试
如果要手动测试服务器:
# Manueller Test (gibt JSON auf stdout aus)
echo '{"jsonrpc":"2.0","id":1,"method":"resources/list"}' | node src/index.js配置
config.json
通过死亡 config.json 您的项目:
{
"projects": [
{
"name": "my-project",
"path": "~/projects/my-project",
"database": {
"type": "sqlite",
"path": "~/projects/my-project/database.db"
},
"scan": {
"routes": ["routes/**/*.js"],
"services": ["services/**/*.js"],
"models": ["database/**/*.js"],
"views": ["views/**/*.hbs"],
"config": ["config/**/*.js"]
},
"ignore": ["node_modules", ".git", "public"]
}
]
}⚠️ 重要 :config.json包含您的本地路径,并且应该 不 登录到repository。而是利用config.example.json艾尔斯·沃拉格。
添加更多项目
{
"projects": [
{ "...": "erstes Projekt" },
{
"name": "another-project",
"path": "~/projects/another-project",
"database": null,
"scan": {
"routes": ["src/routes/**/*.ts"],
"services": ["src/services/**/*.ts"]
},
"ignore": ["node_modules", "dist"]
}
]
}Claude 代码配置
将服务器添加到您的 Claude Code 配置:
选项 1: 全局配置
编辑 ~/.claude/settings.json:
{
"mcpServers": {
"project-context": {
"command": "node",
"args": ["~/projects/mcp-project-context/src/index.js"],
"env": {
"MCP_CONFIG_PATH": "~/projects/mcp-project-context/config.json"
}
}
}
}选项2:项目特定
创建 .mcp.json 项目根:
{
"mcpServers": {
"project-context": {
"command": "node",
"args": ["~/projects/mcp-project-context/src/index.js"]
}
}
}可用资源
配置后,您可以在 Claude Code 中访问这些资源:
| 资源 URI | 描述 |
|---|---|
context://my-project/routes 所有API终端,包括方法,路径,文件 | |
context://my-project/database-schema | SQLite 表和列 (live) |
context://my-project/services JSDoc的服务功能 | |
context://my-project/file-structure 作为树的文件夹结构 | |
context://my-project/architecture 高层建筑。 |
可用工具
| 工具 | 描述 |
|---|---|
find_function 按名称查找函数 | |
search_routes 按路径/方法查找路线 | |
search_tables 查找表格/列 | |
refresh_cache 强制重新加载(没有缓存,只有Compact) |
使用范例
在Claude Code中,你可以说:
"Zeig mir alle API Routes vom my-project"
→ Claude liest context://my-project/routes
"Welche Tabellen hat die Datenbank?"
→ Claude liest context://my-project/database-schema
"Wo ist die Funktion processOrder definiert?"
→ Claude nutzt das find_function Tool故障排除
服务器未启动
# Logs prüfen
pm2 logs mcp-project-context --lines 50
# Manuell testen
node ~/projects/mcp-project-context/src/index.js数据库错误
确保路径在 config.json 正确:
# Prüfen ob DB existiert
ls -la ~/projects/my-project/database.db资源未找到
- 检查项目名称是否包含在URI中
config.json匹配 - 检查扫描模式是否找到文件
许可费勒
# Logs-Ordner erstellen
mkdir -p ~/projects/mcp-project-context/logs
chmod 755 ~/projects/mcp-project-context/logs发展
# Mit Auto-Reload entwickeln
npm run dev
# Oder mit nodemon
npx nodemon src/index.js许可证
麻省理工学院
