使用说明
后见之明MCP服务器
一个模型上下文协议(MCP)服务器,维护一个可搜索的开发学习、常见错误、编码模式和最佳实践知识库。专为与Claude Desktop和其他MCP兼容客户端一起使用而构建。
特性
- 全文检索:基于SQLite FTS5的快速搜索,涵盖所有知识类型
- 课程数据库:存储模式、实践、陷阱和架构决策
- 错误跟踪:记录常见错误及其解决方案,并跟踪其发生频率
- Swift模式:具有版本约束的iOS/Swift特定模式
- 会话上下文:将知识与发展会议联系起来
- 多技术:按技术组织(Swift、Python、Xcode等)
- 标签系统:带标签的灵活分类
- 导出/导入:用于备份和迁移的JSON导出
需求
- Python 3.10+
- macOS、Linux或Windows
- Claude Desktop(或其他MCP客户端)
安装
Homebrew(推荐用于macOS)
在macOS上安装的最简单方法:
# Add the tap (one-time)
brew tap foscomputerservices/tap
# Install hindsight-mcp
brew install hindsight-mcp
# Initialize and auto-configure Claude Desktop/Code
hindsight-init
这 hindsight-init 命令将:
- 创建
~/.hindsight/运行时目录 - 初始化数据库
- 自动配置Claude Desktop(如果已安装)
- 自动配置克劳德代码(如果已安装)
初始化后,重新启动Claude Desktop以激活。
快速安装(替代方案)
如果您不想使用Homebrew:
# Clone the repository
git clone https://github.com/foscomputerservices/hindsight-mcp.git
cd hindsight-mcp
# Run the installer
./install.sh
安装程序:
- 创建
~/.hindsight/运行时目录 - 复制服务器文件
- 设置Python虚拟环境
- 初始化数据库
然后配置MCP客户端(见下文)并重新启动。
手动安装
如果您更喜欢手动设置:
# Clone anywhere
git clone https://github.com/foscomputerservices/hindsight-mcp.git ~/hindsight-mcp
# Create runtime directory
mkdir -p ~/.hindsight
# Copy server files
cp ~/hindsight-mcp/server.py ~/.hindsight/
cp ~/hindsight-mcp/schema.sql ~/.hindsight/
cp ~/hindsight-mcp/config.json ~/.hindsight/
# Set up Python environment
python3 -m venv ~/.hindsight/.venv
~/.hindsight/.venv/bin/pip install mcp pydantic
# Initialize database
sqlite3 ~/.hindsight/knowledge.db < ~/.hindsight/schema.sql
更新中
自制:
brew upgrade hindsight-mcp
手动安装:
cd /path/to/hindsight-mcp
git pull
./install.sh
您的数据库和配置将在更新期间保留。
Claude桌面配置
注: 如果你是通过Homebrew安装的,
hindsight-init自动配置。
添加到您的 claude_desktop_config.json:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
窗户: %APPDATA%\Claude\claude_desktop_config.json
自制咖啡安装:
{
"mcpServers": {
"hindsight": {
"command": "hindsight-server"
}
}
}
手动安装:
{
"mcpServers": {
"hindsight": {
"command": "/Users/YOUR_USERNAME/.hindsight/.venv/bin/python",
"args": ["/Users/YOUR_USERNAME/.hindsight/server.py"]
}
}
}
替换 YOUR_USERNAME 使用您的实际用户名。
配置后重新启动Claude Desktop。
Claude代码(CLI)配置
注: 如果你是通过Homebrew安装的,
hindsight-init自动配置。
自制咖啡安装:
claude mcp add hindsight -- hindsight-server
手动安装:
claude mcp add hindsight -- ~/.hindsight/.venv/bin/python ~/.hindsight/server.py
或者,添加到 ~/.claude/settings.json:
{
"mcpServers": {
"hindsight": {
"command": "hindsight-server"
}
}
}
通过以下方式进行验证: claude mcp list
可用工具
查询工具
| 工具 | 说明 |
|---|---|
query_knowledge |
使用FTS搜索所有知识类型 |
search_errors |
按模式或技术查找错误 |
get_swift_patterns |
使用版本过滤检索Swift模式 |
list_technologies |
列出具有条目计数的技术 |
list_tags |
列出带有使用次数的标签 |
get_statistics |
仪表板风格分析 |
添加/更新工具
| 工具 | 说明 |
|---|---|
add_lesson |
添加新课程(模式、练习、gotcha、决策) |
add_common_error |
记录错误和解决方案 |
add_swift_pattern |
用代码示例添加Swift模式 |
add_session_context |
链接开发会话 |
update_lesson |
更新现有课程 |
increment_error_count |
轨道误差发生 |
导出工具
| 工具 | 说明 |
|---|---|
export_knowledge |
导出为JSON并进行过滤 |
使用示例
添加课程
Add a lesson about SwiftUI state management:
- Title: "SwiftUI State Management"
- Content: "Use @State for local view state, @Binding for child views..."
- Category: pattern
- Technology: swift
- Tags: swiftui, state-management
搜索知识
Search for "memory leak" in the knowledge base
Find Swift errors related to "actor isolation"
记录错误
Add a common error:
- Technology: swift
- Error: "Publishing changes from background threads is not allowed"
- Solution: "Use MainActor.run or @MainActor annotation"
查询模式
Show Swift patterns for iOS 17+ that relate to observation
配置
config.json
{
"database": {
"path": "~/.hindsight/knowledge.db",
"connection_timeout": 30,
"busy_timeout": 5000
},
"search": {
"default_limit": 10,
"max_limit": 100
},
"logging": {
"level": "INFO",
"file": "~/.hindsight/logs/hindsight.log"
}
}
环境变量
| 变量 | 描述 |
|---|---|
HINDSIGHT_DB_PATH |
覆盖数据库路径 |
HINDSIGHT_LOG_LEVEL |
覆盖日志级别(调试、信息、警告、错误) |
HINDSIGHT_LOG_FILE |
覆盖日志文件路径 |
备份
手动备份
~/.hindsight/backup.sh
定时备份(macOS)
# Install daily backup at 3:00 AM
~/.hindsight/setup-backup-schedule.sh install
# Check status
~/.hindsight/setup-backup-schedule.sh status
# Uninstall
~/.hindsight/setup-backup-schedule.sh uninstall
备份存储在 ~/.hindsight/backups/ 30天轮换。
数据库模式
表格
- 课程 -分类发展学习
- 常见错误 -错误模式及其解决方案
- 快捷模式 -带有版本约束的Swift/iOS模式
- 会话 -发展会议背景
- 标签 -分类标签
- lesson_tags -标签关联
全文检索
FTS5虚拟表提供快速搜索:
lessons_fts-按标题、内容、技术搜索课程errors_fts-按模式、解决方案、原因搜索错误patterns_fts-按名称、描述搜索模式
发展
开发发生在克隆的存储库中。运行时(~/.hindsight/)仅包含运行服务器所需的内容。
存储库结构
hindsight-mcp/ # Source repository
├── server.py # MCP server implementation
├── schema.sql # Database schema
├── config.json # Default configuration
├── install.sh # Installation script
├── backup.sh # Backup script
├── setup-backup-schedule.sh
├── test-data.sql # Sample seed data
├── requirements.txt # Python dependencies
├── tests/ # Test suite
│ ├── conftest.py
│ ├── test_database.py
│ ├── test_tools.py
│ ├── test_fts.py
│ └── test_performance.py
├── docs/ # Documentation
└── .claude/ # Development session history
运行时结构
~/.hindsight/ # Runtime (created by install.sh)
├── server.py # Copied from repo
├── schema.sql # Copied from repo
├── config.json # Local config (preserved on update)
├── knowledge.db # SQLite database
├── .venv/ # Python virtual environment
├── logs/ # Log files
└── backups/ # Database backups
运行测试
cd /path/to/hindsight-mcp
# Set up test environment
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install pytest pytest-asyncio pytest-cov
# Run all tests
pytest tests/ -v
# Run fast tests only
pytest tests/ -v -m "not slow"
# Run with coverage
pytest tests/ --cov=server --cov-report=html
代码检查
# Install ruff
pip install ruff
# Check for issues
ruff check .
# Auto-fix issues
ruff check . --fix
# Check formatting
ruff format --check .
# Apply formatting
ruff format .
加载种子数据
sqlite3 ~/.hindsight/knowledge.db < test-data.sql
释放
当您推送版本标签时,发布将通过GitHub Actions自动进行。
创建发布
# Ensure you're on main with everything committed
git checkout main
git pull
# Create an annotated tag
git tag -a v1.0.0 -m "Release description"
# Push the tag (triggers the release workflow)
git push origin v1.0.0
标记格式
v1.0.0-稳定发布v1.1.0-beta.1-预发布(自动标记为预发布)
发生了什么
- 发布工作流运行完整的测试套件(包括慢速测试)
- 使用所有服务器文件创建tarball
- 根据自上次标记以来的提交生成更改日志
- 发布带有存档的GitHub版本
管理标签
# List existing tags
git tag -l
# Delete a tag (if needed)
git tag -d v1.0.0 # Delete locally
git push origin :v1.0.0 # Delete from remote
故障排除
看 故障排除.md 常见问题和解决方案。
贡献
看 贡献.md 关于贡献指南。
许可证
MIT许可证-请参阅 许可证 了解详情。
致谢
- 建立在 模型上下文协议 通过Anthropic
- 使用SQLite FTS5进行全文搜索
