OPC内存MCP服务器

提供OPC内存系统的MCP接口,支持语义记忆存储和检索,适用于Claude代码和Claude桌面环境。

  • by stephenfeather
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 stephenfeather/opc-memory-mcp

使用说明

OPC内存MCP服务器

MCP服务器,将OPC内存脚本作为Claude Code和Claude Desktop的工具公开。

该项目提供了一个MCP接口 OPC(Opinionated持久上下文) 存储系统从 OPC项目OPC支持语义记忆存储和检索,使Claude能够从过去的会话中学习,并在对话中保持上下文。

注: 此服务器最初是针对Continuous-Claude-v3构建的。从v0.7.2开始,它针对的是单机版 OPC存储库 它包含内存脚本、数据库模式和模式检测基础架构。

工具

工具 说明
store_learning 将会话学习与语义回忆的嵌入一起存储
recall_learnings 基于存储学习的语义搜索
query_documents 对摄入的文档集合进行范围语义搜索(RAG)
list_document_collections 列出文档集合和摄取统计信息
scan_document_collection 摄入一个或全部集合(管理员/摄入)
create_document_collection 注册新的文档集合(管理员/摄取)
query_artifacts 在上下文图中搜索过去会话的先例
index_artifacts 索引交接、计划和连续性分类账
mark_handoff 标记切换结果以进行跟踪
start_daemon 启动内存提取守护进程
stop_daemon 停止内存提取守护进程
daemon_status 检查守护进程状态并查看最近的日志
detect_patterns 跨存储的学习运行按需模式检测

先决条件

此MCP服务器需要:

  1. OPC项目 -内存脚本和PostgreSQL数据库模式 OPC存储库
  2. PostgreSQL数据库 -使用OPC模式运行(会话、file_claims、archival_memory表)
  3. 环境变量 - DATABASE_URL 指向您的PostgreSQL实例

请参阅 OPC存储库 有关设置说明。

OPC目录配置

OPC目录路径可以通过两种方式配置(按优先级顺序):

1.环境变量(覆盖)

export CLAUDE_OPC_DIR="/path/to/your/opc"

将其用于临时覆盖或CI/CD环境。

2.配置文件(持久)

创建 ~/.claude/opc.json:

{
  "opc_dir": "/path/to/your/opc"
}

这是持久用户配置的推荐方法。

解析顺序

钩子和脚本按以下顺序解析OPC_DIR:

优先级 来源 用例
1 CLAUDE_OPC_DIR env var 显式重写,CI/CD
2 ~/.claude/opc.json 持久用户偏好
3 ${CLAUDE_PROJECT_DIR}/opc 项目本地设置
4 ~/.claude 全球安装

挂钩集成

如果您正在构建需要引用OPC基础架构的钩子,请使用共享 opc-path.ts 模块。请参阅 examples/hooks/ 您可以将完整示例的目录复制到 ~/.claude/hooks/src/shared/ 目录。

MCP服务器分辨率

这 main.py MCP服务器使用相同的解析逻辑:

def get_opc_dir() -> str:
    # 1. CLAUDE_OPC_DIR env var
    # 2. ~/.claude/opc.json config file
    # 3. Fallback default

这意味着MCP服务器将自动使用您配置的OPC路径。

技能说明

如果你有引用OPC内存工具的Claude Code技能(例如。, /recall, /remember),您可能需要更新它们以使用MCP工具名称:

技能参考 MCP工具名称
store_learning mcp__opc-memory__store_learning
recall_learnings mcp__opc-memory__recall_learnings
query_artifacts mcp__opc-memory__query_artifacts
index_artifacts mcp__opc-memory__index_artifacts
mark_handoff mcp__opc-memory__mark_handoff
start_daemon mcp__opc-memory__start_daemon
stop_daemon mcp__opc-memory__stop_daemon
daemon_status mcp__opc-memory__daemon_status
detect_patterns mcp__opc-memory__detect_patterns

安装

cd /Users/stephenfeather/Tools/opc-memory-mcp
uv sync

用法

直接运行

uv run opc-memory-server

Claude桌面配置

添加 ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "opc-memory": {
      "command": "uv",
      "args": ["--directory", "/Users/stephenfeather/Tools/opc-memory-mcp", "run", "opc-memory-server"]
    }
  }
}

Claude代码配置

添加 .claude/settings.json 或全局设置:

{
  "mcpServers": {
    "opc-memory": {
      "command": "uv",
      "args": ["--directory", "/Users/stephenfeather/Tools/opc-memory-mcp", "run", "opc-memory-server"]
    }
  }
}

工具示例

店铺学习

Store a learning about hook development patterns.

Parameters:
- content: "TypeScript hooks require npm install before they work"
- learning_type: "WORKING_SOLUTION"
- context: "hook development"
- tags: "hooks,typescript"
- confidence: "high"

回顾_收益

Search for past learnings about authentication.

Parameters:
- query: "authentication patterns"
- k: 5
- text_only: false (use embeddings)

可观察性: MCP召回记录到OPC recall_log 桌子与 source = "mcp" (自v0.7.5以来),将它们与 hook-以及 cli-驱动召回以进行跨项目范围分析。

查询文档

对摄入的文件集(包装)进行范围广泛的RAG搜索 opc-docs query).

Search the documents for a topic.

Parameters:
- text: "what does the contract say about termination"
- collection: "" (default; searches global-scope collections only)
- limit: 8 (max 100)

作用域是一个安全边界: 默认搜索是 仅限全球A. restricted 收集(如医疗/法律文件)表面 仅 当其名称通过传递时 collection。没有“所有作用域”选项——仅当调用者明确指向集合名称时才传递集合名称 list_document_collections 是只读的; scan_document_collection 和 create_document_collection 是管理/摄取操作。

索引_事实

Index all artifacts:
- mode: "all"

Index specific file:
- mode: "file"
- file_path: "/path/to/handoff.md"

mark_handoff

Mark the latest handoff as successful:
- outcome: "SUCCEEDED"
- notes: "All tasks completed"

检测模式

Dry run to preview patterns:
- dry_run: true

Run detection and write to database:
- min_confidence: 0.3
- use_llm: false

View last run's report:
- report: true

守护进程管理

Check daemon status:
daemon_status()
# Returns: running status, PID, recent log entries

Start the daemon:
start_daemon()
# Starts memory extraction daemon if not running

Stop the daemon:
stop_daemon()
# Stops the running daemon

发展

测试服务器:

# Check it starts without errors
uv run opc-memory-server &
PID=$!
sleep 2
kill $PID

# Test individual tools via subprocess
uv run python -c "
from main import store_learning, recall_learnings
result = recall_learnings(query='test', k=1)
print(result)
"