内容
# MCP Brain Manager
大脑知识管理系统的智能上下文管理层,实现语义路由和人机协作工作流程。
## Overview
MCP Brain Manager 提供:
- **Enhanced Session Management** - 自动上下文加载和模式选择
- **Semantic Routing** - 用户意图的智能分类
- **Human-in-the-Loop Updates** - 建议的更改需要确认
- **Project Stack** - 在多个项目之间无缝切换
- **Project Templates** - 不同项目类型的结构化起点
- **Analytics & Insights** - 模式分析和生产力指标
## Installation
```bash
cd mcp-brain-manager
npm install
npm run build
```
## Configuration
添加到您的 MCP 设置:
```json
{
"mcpServers": {
"brain-manager": {
"command": "node",
"args": ["/path/to/mcp-brain-manager/dist/index.js"],
"description": "智能大脑系统管理"
}
}
}
```
## Available Tools
### Core Management
#### `manager_init`
使用上下文加载初始化增强的大脑会话。
```typescript
manager_init({ message: "Let's continue working on the API" })
// Returns: mode, confidence, last session info, current project
```
#### `propose_update`
创建一个可审查的更新提案。
```typescript
propose_update({
updateType: "progress",
updates: {
completedTasks: ["Setup auth"],
newTasks: ["Add tests"],
currentFocus: "Testing"
}
})
// Returns: proposal ID, confirmation prompt, proposed changes
```
#### `confirm_update`
审查后应用建议的更新。
```typescript
confirm_update({
updateId: "uuid-here",
modifications: { /* optional changes */ }
})
```
### Project Management
#### `switch_project`
切换到不同的项目,同时保留上下文。
```typescript
switch_project({
projectName: "new-project",
createIfNotExists: true,
template: "software"
})
```
#### `return_to_previous`
从堆栈中弹出上一个项目。
```typescript
return_to_previous()
```
#### `generate_dashboard`
创建与 Obsidian 兼容的项目仪表板。
```typescript
generate_dashboard({
projectName: "my-project",
includeAnalytics: true
})
```
### Intelligence Features
#### `semantic_classify`
通过推理对用户意图进行分类。
```typescript
semantic_classify({
message: "I want to analyze the performance metrics",
context: { lastProject: "api-project" }
})
// Returns: mode, confidence, reasoning
```
#### `analyze_patterns`
分析工作模式以获得见解。
```typescript
analyze_patterns({
timeframe: "week",
focusArea: "productivity"
})
```
## Usage Examples
### Starting a Session
```javascript
// First message of the day
await manager_init({
message: "Let's continue with the chat app"
})
// Response:
{
"mode": "project_continuation",
"confidence": 0.85,
"reasoning": "Continuation signal detected with active project",
"lastSession": {
"project": "chat-app",
"lastActivity": "Implemented websocket server"
}
}
```
### Recording Progress
```javascript
// Propose an update
const proposal = await propose_update({
updateType: "progress",
updates: {
completedTasks: ["Implement websockets"],
newTasks: ["Add reconnection logic"],
currentFocus: "Connection stability"
}
})
// Review and confirm
await confirm_update({ updateId: proposal.id })
```
### Making Decisions
```javascript
await propose_update({
updateType: "decision",
updates: {
decision: "Use Socket.IO instead of raw WebSockets",
rationale: "Better browser compatibility and reconnection",
impact: "Need to refactor existing code"
}
})
```
## Project Templates
可用模板:
- `software` - 软件开发项目
- `research` - 研究和调查
- `ml` - 机器学习项目
- `writing` - 写作和文档
- `custom` - 空白状态
## Security Guidelines
### Data Storage Restrictions
**切勿在状态表中存储以下内容:**
- API 密钥 (OpenAI, Anthropic, etc.)
- 密码或身份验证令牌
- OAuth 令牌或刷新令牌
- 私有 SSH 密钥或证书
- 包含凭据的数据库连接字符串
- 任何形式的身份验证凭据
- 个人身份信息(SSN、信用卡等)
### Sensitive Data Handling
如果您需要处理敏感数据:
1. **Environment Variables** - 将 API 密钥保存在环境变量中
2. **External Config** - 使用单独的配置文件(不在 git 中跟踪)
3. **Monitex Integration** - 对于未来加密存储需求:
```javascript
// Future implementation
await manager_init({
message: "Start work",
encrypted: true // Triggers Monitex password prompt
})
```
### Validation Rules
brain-manager 包括自动验证,以防止意外存储敏感数据:
- 检测常见的 API 密钥模式 (sk-, pk-, api-, key-, token-)
- 阻止存储与凭据模式匹配的字符串
- 尝试存储潜在敏感数据时发出警告
### Safe Data for State Table
✅ **安全存储:**
- 项目元数据和描述
- 任务列表和进度跟踪
- 决策记录和理由
- 文件路径和项目结构
- 时间戳和活动日志
- 非敏感配置选项
- 公共 URL 和文档链接
❌ **切勿存储:**
- 任何形式的凭据或密钥
- 私有/敏感项目数据
- 客户数据或 PII
- 专有算法或商业机密
## Architecture
```
mcp-brain-manager/
├── src/
│ ├── index.ts # MCP server entry point
│ ├── brain-manager.ts # Core management logic
│ ├── semantic-router.ts # Intent classification
│ └── template-manager.ts # Project templates
├── dist/ # Compiled output
└── package.json
```
## Integration with Brain Tools
此管理器与现有的大脑工具协调:
- 使用 `brain:brain_init` 进行初始化
- 使用 `brain:state_set/get` 存储上下文
- 使用 `brain:brain_remember/recall` 保存叙述
- 使用 `brain:obsidian_note` 创建仪表板
## Development
```bash
# Watch mode
npm run watch
# Run tests
npm test
# Build for production
npm run build
```
## Future Enhancements
1. **True Semantic Routing** - 调用 Claude 进行分类,而不是模式
2. **Context Compression** - 大型项目的自动摘要
3. **Collaboration Mode** - 在用户之间共享上下文
4. **Voice Integration** - 自然语言项目更新
5. **Auto-categorization** - 智能任务和决策分组
## Troubleshooting
**Q: Semantic classification seems wrong?**
A: 您可以提供反馈以改进:
```javascript
await semantic_classify({
message: "your message",
context: { /* ... */ }
})
// If wrong, explicitly state: "switch to research mode"
```
**Q: How to see all projects?**
A: 直接使用大脑工具:
```javascript
brain:state_list({ category: "project" })
```
**Q: Update proposal expired?**
A: 提案在 5 分钟后过期。创建一个新的。
## License
MIT