opencode-session-context-mcp
opencode-session-context-mcp
osc-mcp
演示
https://github.com/user-attachments/assets/d41fb2b8-96ca-4a03-9bcd-afede68212e2
Related MCP server: agent-mem0
目录
描述
opencode-session-context-mcp (又名 osc-mcp) 是一个 MCP 服务器,它为同一项目中的新会话提供来自先前会话的上下文,以便您的 OpenCode 实例可以从上次中断的地方继续,并更好地符合您项目持续的需求。
⚠️ 注意:此工具处于活跃开发阶段,特别是在优化获取上下文时的 Token 消耗方面。欢迎贡献代码。
工作原理
在会话开始时,服务器会将先前会话的过滤摘要存储到
mcp.db中。当新会话请求上下文时,它会查找当前项目的近期摘要。
客户端 (OpenCode) 使用这些摘要为您的新会话注入相关上下文。
工具
store_previous_session_content: 将最近一次先前会话的过滤内容存储到mcp.db中。get_relevant_sessions: 返回当前项目近期会话摘要的轻量级列表。
要求
bungitOpenCode (已安装并配置)
安装
快速开始 (最佳用户体验)
Linux/mac
curl -fsSL https://github.com/vohs-1980/osc-mcp/blob/main/scripts/install.sh?raw=1 | bashWindows (PowerShell):
irm https://github.com/vohs-1980/osc-mcp/blob/main/scripts/install.ps1?raw=1 | iex安全说明:在运行前请查看 scripts/install.sh 或使用下方的手动步骤。对于 Windows,请在运行前查看 scripts/install.ps1。
安装程序执行的操作 (Linux/mac):
查找您的
opencode.json(遵循XDG_CONFIG_HOME)。验证是否安装了
bun和git。验证 OpenCode 数据目录是否存在 (遵循
XDG_DATA_HOME)。在
~/.local/share/opencode/osc-mcp中克隆或更新仓库。运行
bun install并构建服务器。更新
opencode.json以添加"osc-mcp"MCP 条目。如果配置编辑失败或设置了
--no-config,则打印手动步骤。
如果您的配置不是有效的 JSON 或您传递了 --no-config,请按照下方的手动步骤操作。
手动安装
git clone https://github.com/vohs-1980/osc-mcp.git \
~/.local/share/opencode/osc-mcp
cd ~/.local/share/opencode/osc-mcp
bun install
bun run buildOpenCode 配置 (~/.config/opencode/opencode.json):
如果您还没有列出指令文件,请添加它们:
"instructions": [
"~/.local/share/opencode/osc-mcp/instructions/session-start.md",
"~/.local/share/opencode/osc-mcp/instructions/context-lookup.md"
]然后添加本地 MCP 条目 (如果不存在):
"osc-mcp": {
"type": "local",
"enabled": true,
"command": ["bun", "~/.local/share/opencode/osc-mcp/src/index.ts"]
}运行
# Run the MCP server
bun src/index.ts提示
从项目根目录启动 OpenCode,以便 MCP 可以将会话映射到正确的项目。
将您的项目保持在 git 中,以便会话可以与稳定的仓库上下文相关联。
环境
OPENCODE_DB: OpenCode 数据库路径 (默认~/.local/share/opencode/opencode.db)
如果默认路径不适用于您的设置,请在启动 OpenCode/MCP 之前显式设置它。
示例:
export OPENCODE_DB="$HOME/.local/share/opencode/opencode.db"
opencode安装程序覆盖 (可选):
OSC_MCP_REPO_URL: 要克隆的 Git 仓库 URL (默认https://github.com/vohs-1980/osc-mcp.git)。OSC_MCP_INSTALL_DIR: 安装目录 (默认~/.local/share/opencode/osc-mcp)。OSC_MCP_REF: 要检出的 Git 引用 (标签/分支/提交,默认main)。XDG_CONFIG_HOME: 基础配置目录 (默认~/.config)。XDG_DATA_HOME: 基础数据目录 (默认~/.local/share)。
覆盖示例:
export OSC_MCP_REPO_URL="https://github.com/vohs-1980/osc-mcp.git"
export OSC_MCP_INSTALL_DIR="$HOME/.local/share/opencode/osc-mcp"
export OSC_MCP_REF="v0.1.0"
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share"操作系统说明
macOS/Linux: 使用
scripts/install.sh(需要bash,git,bun)Windows: 在 PowerShell 中使用
scripts/install.ps1。
配置路径检测 (安装程序按此顺序搜索):
macOS/Linux:
$XDG_CONFIG_HOME/opencode/opencode.json~/.config/opencode/opencode.json~/Library/Application Support/opencode/opencode.json
Windows:
%XDG_CONFIG_HOME%\opencode\opencode.json%APPDATA%\opencode\opencode.json%LOCALAPPDATA%\opencode\opencode.json~\.config\opencode\opencode.json~\Library\Application Support\opencode\opencode.json
默认数据位置 (数据库):
macOS/Linux:
~/.local/share/opencode/opencode.db~/.local/share/opencode/osc-mcp/mcp.db
Windows:
%USERPROFILE%\.local\share\opencode\opencode.db%USERPROFILE%\.local\share\opencode\osc-mcp\mcp.db
许可证
MIT。请参阅 LICENSE。
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
Related MCP Connectors
Sync coding-agent sessions and resume them in any other agent: Claude Code, Codex, Cursor, more.
Bring your saved preferences, project decisions, and useful context into your next AI conversation.
Persistent memory for Claude Code and Cursor. Stop re-explaining your project every session.
Shared memory for coding agents. Stop re-explaining your codebase every session.
Related MCP Servers
- AlicenseNot gradedqualityNot gradedmaintenanceEnables AI coding assistants like Claude Code, Cursor, and Codex to share chat logs, terminal history, and session context with each other. Eliminates the need to re-explain context when switching between different AI coding tools.2MIT
- AlicenseNot gradedqualityDmaintenanceProvides persistent cross-session memory for Claude Code, enabling it to remember user preferences, decisions, and project context across new sessions.Apache 2.0
- AlicenseNot gradedqualityDmaintenanceProvides persistent memory for Claude Code, automatically extracting and surfacing relevant context from past sessions to avoid re-explaining issues and decisions.MIT
- AlicenseAqualityDmaintenanceProvides cross-session memory for Claude Code by extracting structured handoffs at session end and retrieving relevant past context at session start.27MIT