Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(mcp): tighten VS Code Copilot install docs
AkitaOnRailsdf078ee48f48
diff --git a/crates/ai-memory-cli/src/commands/install_mcp.rs b/crates/ai-memory-cli/src/commands/install_mcp.rsindex 028f7cc1..bc0586cc 100644--- a/crates/ai-memory-cli/src/commands/install_mcp.rs+++ b/crates/ai-memory-cli/src/commands/install_mcp.rs@@ -97,7 +97,7 @@ fn mcp_server_url_from_base(server_url: &str) -> String {/// unsupported OSes, or when `$HOME` can't be resolved.pub(crate) fn mcp_config_path(client: crate::cli::McpClient) -> Result<PathBuf> {use crate::cli::McpClient;- let home = dirs::home_dir().context("could not locate $HOME for config-file auto-detect")?;+ let home = || dirs::home_dir().context("could not locate $HOME for config-file auto-detect");Ok(match client {// Claude Code reads MCP-server registrations from `~/.claude.json`// (the same file `claude mcp add`/`claude mcp list` operate on).@@ -107,14 +107,18 @@ pub(crate) fn mcp_config_path(client: crate::cli::McpClient) -> Result<PathBuf>// observing that `mcpServers` in settings.json is silently// ignored while the same entry under `~/.claude.json` shows up// in `claude mcp list`.)- McpClient::ClaudeCode => home.join(".claude.json"),- McpClient::Codex => home.join(".codex").join("config.toml"),- McpClient::OpenCode => home.join(".config").join("opencode").join("opencode.json"),- McpClient::Cursor => home.join(".cursor").join("mcp.json"),+ McpClient::ClaudeCode => home()?.join(".claude.json"),+ McpClient::Codex => home()?.join(".codex").join("config.toml"),+ McpClient::OpenCode => home()?+ .join(".config")+ .join("opencode")+ .join("opencode.json"),+ McpClient::Cursor => home()?.join(".cursor").join("mcp.json"),McpClient::ClaudeDesktop => {#[cfg(target_os = "macos")]{- home.join("Library")+ home()?+ .join("Library").join("Application Support").join("Claude").join("claude_desktop_config.json")@@ -122,7 +126,8 @@ pub(crate) fn mcp_config_path(client: crate::cli::McpClient) -> Result<PathBuf>#[cfg(target_os = "windows")]{// %APPDATA% is roughly ~/AppData/Roaming.- home.join("AppData")+ home()?+ .join("AppData").join("Roaming").join("Claude").join("claude_desktop_config.json")@@ -135,19 +140,18 @@ pub(crate) fn mcp_config_path(client: crate::cli::McpClient) -> Result<PathBuf>);}}- McpClient::GeminiCli => home.join(".gemini").join("settings.json"),- McpClient::Openclaw => home.join(".openclaw").join("config.json"),- McpClient::Pi => home.join(".omp").join("agent").join("mcp.json"),- McpClient::AntigravityCli => home+ McpClient::GeminiCli => home()?.join(".gemini").join("settings.json"),+ McpClient::Openclaw => home()?.join(".openclaw").join("config.json"),+ McpClient::Pi => home()?.join(".omp").join("agent").join("mcp.json"),+ McpClient::AntigravityCli => home()?.join(".gemini").join("antigravity-cli").join("mcp_config.json"),// VS Code MCP is workspace-scoped by default: `.vscode/mcp.json`- // at the current workspace root. The user-level alternative is- // managed through VS Code's `MCP: Add server` palette and not- // a single canonical file path, so we don't try to detect it- // here — `--config-file` is the escape hatch for users who- // want to target a non-standard location.+ // at the current workspace root. The user-profile alternative+ // lives under VS Code's profile-specific data dir; use VS+ // Code's `MCP: Open User Configuration` command to open it,+ // then pass that concrete path via `--config-file`.McpClient::VsCodeCopilot => std::env::current_dir().context("could not resolve current dir for .vscode/mcp.json default")?.join(".vscode")@@ -630,7 +634,8 @@ fn render_vscode_copilot(args: &InstallMcpArgs) -> Result<String> {"# VS Code GitHub Copilot (agent mode) — write to one of:\n\# - .vscode/mcp.json (workspace, recommended — matches\n\# ai-memory's per-cwd auto-scoping)\n\- # - ~/.vscode/mcp.json (user-level, all workspaces)\n\+ # - the user-profile mcp.json opened by VS Code's\n\+ # `MCP: Open User Configuration` command\n\#\n\# VS Code's MCP framework uses `servers` (NOT `mcpServers`) as the\n\# top-level key, `type: \"http\"` for streamable-HTTP endpoints, and\n\diff --git a/crates/ai-memory-cli/src/commands/uninstall.rs b/crates/ai-memory-cli/src/commands/uninstall.rsindex 760789b3..6de89cc2 100644--- a/crates/ai-memory-cli/src/commands/uninstall.rs+++ b/crates/ai-memory-cli/src/commands/uninstall.rs@@ -1124,6 +1124,23 @@ mod tests {assert!(v["mcp"].get("servers").is_none());}+ #[test]+ fn strip_mcp_vscode_copilot_root_servers() {+ let content = r#"{"servers":{"ai-memory":{"type":"http","url":"http://127.0.0.1:49374/mcp"},"other":{"type":"http","url":"http://x"}}}"#;+ let (out, removed) = strip_mcp_json(+ content,+ McpClient::VsCodeCopilot,+ Some("ai-memory"),+ "http://127.0.0.1:49374/mcp",+ )+ .unwrap();++ assert_eq!(removed, vec!["ai-memory".to_string()]);+ let v: serde_json::Value = serde_json::from_str(&out).unwrap();+ assert!(v["servers"].get("ai-memory").is_none());+ assert!(v["servers"].get("other").is_some());+ }+#[test]fn strip_mcp_no_match_is_noop() {let content = r#"{"mcpServers":{"other":{"url":"http://x"}}}"#;diff --git a/docs/mcp-install.md b/docs/mcp-install.mdindex b2c12db0..3a0775c1 100644--- a/docs/mcp-install.md+++ b/docs/mcp-install.md@@ -27,10 +27,11 @@ files for OpenClaw / OpenCode / OMP) and are covered in theGit Bash `.sh` hooks rather than the PowerShell default used by otherscript-hook agents.-Claude Desktop is **MCP-only** here: it exposes long-term memory to its-LLM via ai-memory's MCP tools (`memory_query`, `memory_recent`,-`memory_handoff_accept`, etc.), but it does not auto-capture session-events into ai-memory's `/hook` endpoint. The trade-off:+Claude Desktop and VS Code Copilot are **MCP-only** here: they expose+long-term memory to their LLMs via ai-memory's MCP tools+(`memory_query`, `memory_recent`, `memory_handoff_accept`, etc.), but+they do not auto-capture session events into ai-memory's `/hook`+endpoint. The trade-off:| | What you get | What you don't get ||---|---|---|@@ -76,7 +77,7 @@ metadata.> **One-shot tip:** every snippet below is also reachable from the> CLI:> ```bash-> ai-memory install-mcp --client gemini-cli # or cursor / claude-desktop / openclaw / pi|omp / antigravity-cli+> ai-memory install-mcp --client gemini-cli # or cursor / claude-desktop / openclaw / pi|omp / antigravity-cli / vscode-copilot> ```---@@ -123,8 +124,10 @@ VS Code — call `memory_query`, `memory_write_page`, etc. from chat).**Config file:**- Workspace (recommended): `.vscode/mcp.json` in the repo root. Matchesai-memory's per-cwd auto-scoping.-- User-level: `~/.vscode/mcp.json`, or managed through the **MCP: Add- server** palette command.+- User profile: run **MCP: Open User Configuration** in VS Code and use+ the `mcp.json` file it opens. The exact path is platform- and+ profile-specific; pass it to `--config-file` if you want ai-memory to+ write that file directly.**Schema (verified against VS Code's MCP reference):** top-level key is`servers` (NOT `mcpServers`). HTTP endpoints use `type: "http"` and the@@ -165,6 +168,10 @@ ai-memory install-mcp --client vscode-copilot# Or write .vscode/mcp.json in the current workspace directly:ai-memory install-mcp --client vscode-copilot --apply++# Or write the user-profile mcp.json opened by VS Code directly:+ai-memory install-mcp --client vscode-copilot \+ --config-file /path/to/vscode-profile/mcp.json --apply```Aliases: `copilot`, `github-copilot`.