对话历史搜索服务

一个本地化的MCP服务器,用于索引和搜索Claude Code的对话历史,支持关键词和语义搜索。

  • by SDillon001
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 SDillon001/conversation-history-mcp

使用说明

会话历史MCP服务器

本地MCP服务器,使用关键字和语义搜索对Claude Code对话历史进行索引和搜索。

特性

  • 关键词搜索 -使用SQLite FTS5进行快速全文搜索
  • 语义搜索 -使用本地嵌入查找概念上相似的对话
  • 会话列表 -浏览最近的会话及其摘要
  • 上下文检索 -从过去的对话中获取完整的上下文
  • 完全私人 -所有数据都保持本地,没有外部API调用

安装

先决条件

  • Python 3.10+
  • Claude 代码命令行界面

快速安装

# Clone the repo
git clone https://github.com/SDillon001/conversation-history-mcp.git
cd conversation-history-mcp

# Install dependencies
pip install -r requirements.txt

# Create symlink to Claude's MCP directory
mkdir -p ~/.claude/mcp-servers
ln -s "$(pwd)" ~/.claude/mcp-servers/conversation-history

# Add to Claude Code settings
# See Configuration section below

配置

添加到您的 ~/.claude.json 在...之下 mcpServers 按键:

{
  "mcpServers": {
    "conversation-history": {
      "type": "stdio",
      "command": "python3",
      "args": ["server.py"],
      "cwd": "/path/to/conversation-history-mcp"
    }
  }
}

替换 /path/to/conversation-history-mcp 安装的实际路径。

用法

配置后,以下工具在任何Claude Code会话中都可用:

搜索会话

在所有对话历史中搜索关键字。

"Search for conversations about authentication"
→ Claude calls search_sessions(query="authentication")

搜索_语义

语义搜索,查找概念上相似的对话。

"Find conversations similar to database optimization"
→ Claude calls search_semantic(query="database optimization")

list_sessions

列出最近的会议及其摘要。

"What did I work on last week?"
→ Claude calls list_sessions(days=7)

get_session

从特定会话中获取完整上下文。

"Show me the full conversation from session abc123"
→ Claude calls get_session(session_id="abc123")

rebuild_index

强制重建搜索索引(通常不需要)。

"Rebuild the conversation index"
→ Claude calls rebuild_index()

运作原理

  1. 索引 -启动时,服务器扫描 ~/.claude/projects/ 用于JSONL会话文件
  2. FTS5 -邮件在SQLite中通过全文搜索进行索引
  3. 嵌入 -使用 sentence-transformers/all-MiniLM-L6-v2 (在本地运行)
  4. 增量 -只有新会话在首次运行后才会被索引

数据存储

~/.claude/mcp-servers/conversation-history/
└── data/
    ├── index.db      # SQLite with FTS5 (keyword search)
    └── chroma/       # ChromaDB (semantic search embeddings)

您的对话历史记录将保留在 ~/.claude/projects/ -此服务器仅创建搜索索引。

隐私

  • 没有外部API调用 -本地生成的嵌入
  • 没有数据离开您的机器 -一切都在里面 ~/.claude/
  • 只读访问 -服务器只读取会话文件,从不修改它们

发展

# Run server directly for testing
python server.py

# Run tests
pytest tests/

许可证

麻省理工学院