🧠 myBrAIn——MCP生态系统
谷歌反重力的确定性、概念性、情境感知的第二大脑。
介绍
myBrAIn 是一个MCP(模型上下文协议)服务器,旨在为语言模型(如谷歌反重力)提供持久和上下文记忆。它充当开发环境的“第二大脑”,允许人工智能在不同的聊天会话中记住项目规则、架构决策和技术见解。
系统架构
该系统分为三个主要部分:
- 核心:管理持久性(
db.py)以及分析智能(analyzer.py)用于从代码中提取见解。 - 服务器:标准MCP接口(
server.py)这允许反重力与大脑相互作用。 - 管理用户界面:高级仪表板(
admin.py)基于Streamlit,通过以下高级功能可视化、管理和调试存储的内存 知识图谱, 内存导出,以及 沉默的观察者 仪表板。 - 观察者:后台守护进程线程(
observer.py)实时监控代码库漂移。
🏗 安装
A.Docker部署(推荐)
最简单的跑步方式 myBrAIn 正在使用Docker Compose。```bash
Clone & Prepare
git clone https://github.com/lilium360/myBrAIn.git
cd myBrAIn
cp .env.example .env
Spin up
docker compose up -d
管理UI将在以下位置提供: **http://localhost:8501**
### B.本地安装(原生Python)
1. **克隆并输入**:```bash
git clone https://github.com/lilium360/myBrAIn.git
cd myBrAIn
- 设置环境:
- 窗户:python -m venv venv && .\venv\Scripts\activate
- Unix:python3 -m venv venv && source venv/bin/activate - 安装:
pip install -r requirements.txt
🚀 使用指南
1.启动管理仪表板
要以图形方式管理数据库并可视化见解:
- 通过Docker:已在运行
docker compose up.打开 http://localhost:8501. - 通过Python:运行
streamlit run admin.py(或python -m streamlit run admin.py).
2.集成在IDE中(光标、VS代码+反重力)
将此添加到您的 mcpServers 配置JSON:
选项A:通过Docker```json
{
"mcpServers": {
"mybrain": {
"command": "docker",
"args": ["exec", "-i", "mybrain-admin", "python", "server.py"],
"env": {
"MYBRAIN_DATA_DIR": "/data/mybrain"
}
}
}
}
#### 选项B:通过Python(本地)```json
{
"mcpServers": {
"mybrain": {
"command": "python",
"args": ["/ABSOLUTE/PATH/TO/mybrain/server.py"]
}
}
}
> [!重要]
> 更改路径 args 到 绝对的 您机器上的路径。
🧠 项目入职和背景
myBrAIn 是专门为处理“项目入职”而设计的,这是一个人工智能分析您当前代码库并存储其架构DNA的过程。
如何启动一个新项目
配置MCP服务器后,只需使用以下提示:
> “我想把这个项目完整地载入你的长期记忆中。按顺序执行:结构链接、堆栈分析、架构分析、样式分析和排除分析。”
📝 集成协议(AI代理必须遵守)
确保AI使用 myBrAIn 正确且一致地将以下说明复制并粘贴到项目的自定义说明中,或 .cursorrules 文件:```markdown
myBrAIn Integration Protocol (MANDATORY)
You are connected to myBrAIn, an MCP server that acts as your Long-Term Memory and "Single Source of Truth" for this project.
You MUST NEVER rely solely on the current chat context or your general knowledge when project-specific rules are saved.
Strictly follow this operational cycle for EVERY interaction:
1. RECALL PHASE (Before Reasoning)
BEFORE generating any code or technical response, you MUST consult the memory:
- Action: Run recall_context using relevant keywords (e.g., "auth logic", "styling conventions", "api patterns").
- Goal: Retrieve the tech stack, architectural rules, and standard components already defined.
- Constraint: If you find an existing rule or component (e.g., "Always use CustomButton"), you MUST use it. Creating duplicates or unauthorized variations is FORBIDDEN.
2. CONSISTENCY PHASE (During Reasoning)
While generating the response:
- Strictly adhere to retrieved Constraints.
- If the user requests something that violates a saved rule (e.g., "Use jQuery" in a React project saved as "No jQuery"), warn the user of the conflict before proceeding.
- Use the code style (naming, comments, structure) retrieved from memory to maintain uniformity.
3. MEMORIZATION PHASE (During/After Action)
Your task is to keep the memory alive and updated. DO NOT wait for the user to ask.
Use store_insight proactively in the following cases:
- New Decisions: If a new architectural rule is established (e.g., "From now on, use only Tailwind").
- New Patterns: If you write a reusable generic component, save it as a "Standard Component".
- Corrections: If the user corrects your error, save the correction (e.g., "Do not use library X because it's buggy").
- Onboarding: If you detect a new empty project, propose or run initialize_workbase.
4. CONFLICT MANAGEMENT
- myBrAIn Priority: If your general knowledge suggests "X" but myBrAIn says "Y", the correct answer is "Y".
- Updates: If an old memory is obsolete, use
store_insightto overwrite it (the system handles semantic collision automatically viareplace_id).
Correct Workflow Example:
User: "Create a login page."
AI (Internal Thought): "Check myBrAIn for 'login', 'auth', 'ui components'."
AI Action: recall_context("login auth ui style")
AI (Found): "The project uses NextAuth and Shadcn components."
AI Response: Generates code using EXACTLY NextAuth and Shadcn, without inventing custom CSS unless necessary.
AI Action (Post): Since a new useful auth hook was created, run store_insight to save it.
```
可用工具
initialize_workbase:将目录链接到大脑。store_insight:手动保存规则或上下文。recall_context:检索当前任务的相关记忆。critique_code:根据存储的体系结构规则验证代码。audit_codebase:扫描整个代码库,查看架构漂移和矛盾。
高级配置
您可以通过环境变量(在Docker中)或修改来定制系统行为 core/config.py.
🗂️ 管理员仪表板功能(v1.1)
重构后的管理仪表板包括:
- 基于卡的浏览器:在带有规则、上下文和约束的彩色标签的现代化网格中浏览记忆。
- 知识图谱:交互式可视化大脑的语义关系和分类集群。
- 批量操作:选择多条记录进行同时删除或快速编辑。
- 无声观察者仪表板:背景漂移检测引擎的实时状态监测。
- 内存管理:导出完整的大脑转储或特定于工作库的JSON;在项目之间导入和重新分配知识包。
- 工作基地管理:通过受确认保护的销毁机制安全管理项目数据。
🔮 路线图
- [ ] 语义路线图: 内部任务规划师,负责维护长期目标和特征进度的背景。
- [x] 内存导入/导出: 与你的团队分享你的“大脑”(粒度和目标)。
- [x] 沉默的观察者: 扫描代码并检测架构漂移的后台守护进程。
- [x] Docker支持
- [x] 带知识图谱的管理UI
