Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

feat: harden MCP add_resource + cc-memory-plugin claude wrapper (#1846)

t0saki36a281a5bea7
diff --git a/examples/claude-code-memory-plugin/README.md b/examples/claude-code-memory-plugin/README.md
index 534e7865c..38260e9a6 100644
--- a/examples/claude-code-memory-plugin/README.md
+++ b/examples/claude-code-memory-plugin/README.md
@@ -51,11 +51,13 @@ If `ov.conf` is what you already maintain, the plugin reads it too — see [Conf
The repo's `examples/.claude-plugin/marketplace.json` exposes the plugin as a local marketplace entry. From the OpenViking repo root:
```bash
-claude plugin marketplace add "$(pwd)/examples" --scope local
-claude plugin install claude-code-memory-plugin@openviking-plugins-local --scope local
+claude plugin marketplace add "$(pwd)/examples" --scope user
+claude plugin install claude-code-memory-plugin@openviking-plugins-local --scope user
```
-> Local install points Claude Code at the source directory. Edits to `scripts/`, `hooks/`, and config files take effect on the next hook invocation — no reinstall. But moving / renaming / deleting the source dir, or `git checkout`-ing to a branch without these files, breaks the plugin. A public marketplace listing for one-click install will follow.
+> `--scope user` makes the plugin active from any directory. Using `--scope local` ties enablement to the current dir and the plugin shows up disabled the moment you `cd` elsewhere.
+>
+> The marketplace entry points Claude Code at the source directory. Edits to `scripts/`, `hooks/`, and config files take effect on the next hook invocation — no reinstall. But moving / renaming / deleting the source dir, or `git checkout`-ing to a branch without these files, breaks the plugin. A public marketplace listing for one-click install will follow.
#### 4. Start Claude Code
@@ -84,10 +86,14 @@ Where is your OpenViking server?
```bash
# ~/.zshrc or ~/.bashrc
claude() {
- if [ -f ~/.openviking/ovcli.conf ]; then
- OPENVIKING_URL=$(jq -r '.url' ~/.openviking/ovcli.conf) \
- OPENVIKING_API_KEY=$(jq -r '.api_key' ~/.openviking/ovcli.conf) \
- command claude "$@"
+ local _ov_conf="${OPENVIKING_CLI_CONFIG_FILE:-$HOME/.openviking/ovcli.conf}"
+ if [ -f "$_ov_conf" ] && command -v jq >/dev/null 2>&1; then
+ local _ov_url _ov_key
+ _ov_url=$(jq -r '.url // empty' "$_ov_conf" 2>/dev/null)
+ _ov_key=$(jq -r '.api_key // empty' "$_ov_conf" 2>/dev/null)
+ OPENVIKING_URL="${OPENVIKING_URL:-$_ov_url}" \
+ OPENVIKING_API_KEY="${OPENVIKING_API_KEY:-$_ov_key}" \
+ command claude "$@"
else
command claude "$@"
fi
diff --git a/examples/claude-code-memory-plugin/README_CN.md b/examples/claude-code-memory-plugin/README_CN.md
index a8362b301..a86565260 100644
--- a/examples/claude-code-memory-plugin/README_CN.md
+++ b/examples/claude-code-memory-plugin/README_CN.md
@@ -51,11 +51,13 @@ curl http://localhost:1933/health # 或者你的远程 URL
仓库的 `examples/.claude-plugin/marketplace.json` 把本插件暴露为一个本地 marketplace 条目。在 OpenViking 仓库根目录:
```bash
-claude plugin marketplace add "$(pwd)/examples" --scope local
-claude plugin install claude-code-memory-plugin@openviking-plugins-local --scope local
+claude plugin marketplace add "$(pwd)/examples" --scope user
+claude plugin install claude-code-memory-plugin@openviking-plugins-local --scope user
```
-> 本地安装让 Claude Code 直接引用源码目录,对 `scripts/`、`hooks/`、配置文件的修改下次 hook 触发即生效,无需重装。但移动 / 重命名 / 删除源码目录,或 `git checkout` 到不含这些文件的分支,会立刻让插件失效。后续会发布公开 marketplace 以支持一键安装。
+> `--scope user` 让插件在任意目录下都启用。用 `--scope local` 会把启用状态绑死在当前目录,一旦 `cd` 到别处插件就显示 disabled,需要手动 enable。
+>
+> marketplace 条目让 Claude Code 直接引用源码目录,对 `scripts/`、`hooks/`、配置文件的修改下次 hook 触发即生效,无需重装。但移动 / 重命名 / 删除源码目录,或 `git checkout` 到不含这些文件的分支,会立刻让插件失效。后续会发布公开 marketplace 以支持一键安装。
#### 4. 启动 Claude Code
@@ -84,10 +86,14 @@ claude
```bash
# ~/.zshrc 或 ~/.bashrc
claude() {
- if [ -f ~/.openviking/ovcli.conf ]; then
- OPENVIKING_URL=$(jq -r '.url' ~/.openviking/ovcli.conf) \
- OPENVIKING_API_KEY=$(jq -r '.api_key' ~/.openviking/ovcli.conf) \
- command claude "$@"
+ local _ov_conf="${OPENVIKING_CLI_CONFIG_FILE:-$HOME/.openviking/ovcli.conf}"
+ if [ -f "$_ov_conf" ] && command -v jq >/dev/null 2>&1; then
+ local _ov_url _ov_key
+ _ov_url=$(jq -r '.url // empty' "$_ov_conf" 2>/dev/null)
+ _ov_key=$(jq -r '.api_key // empty' "$_ov_conf" 2>/dev/null)
+ OPENVIKING_URL="${OPENVIKING_URL:-$_ov_url}" \
+ OPENVIKING_API_KEY="${OPENVIKING_API_KEY:-$_ov_key}" \
+ command claude "$@"
else
command claude "$@"
fi
diff --git a/examples/claude-code-memory-plugin/setup-helper/install.sh b/examples/claude-code-memory-plugin/setup-helper/install.sh
index 1dababeac..6b255aace 100755
--- a/examples/claude-code-memory-plugin/setup-helper/install.sh
+++ b/examples/claude-code-memory-plugin/setup-helper/install.sh
@@ -26,7 +26,9 @@ OV_HOME="${OPENVIKING_HOME:-$HOME/.openviking}"
REPO_DIR="${OPENVIKING_REPO_DIR:-$OV_HOME/openviking-repo}"
REPO_URL="${OPENVIKING_REPO_URL:-https://github.com/volcengine/OpenViking.git}"
REPO_BRANCH="${OPENVIKING_REPO_BRANCH:-main}"
-OVCLI_CONF="$OV_HOME/ovcli.conf"
+# Honor OPENVIKING_CLI_CONFIG_FILE (the env var the `ov` CLI itself reads —
+# crates/ov_cli/src/config.rs:6) so this installer matches CLI behavior.
+OVCLI_CONF="${OPENVIKING_CLI_CONFIG_FILE:-$OV_HOME/ovcli.conf}"
MARKER_BEGIN='# >>> openviking claude-code memory plugin >>>'
MARKER_END='# <<< openviking claude-code memory plugin <<<'
@@ -186,10 +188,14 @@ else
$MARKER_BEGIN
claude() {
- if [ -f ~/.openviking/ovcli.conf ]; then
- OPENVIKING_URL=\$(jq -r '.url' ~/.openviking/ovcli.conf) \\
- OPENVIKING_API_KEY=\$(jq -r '.api_key' ~/.openviking/ovcli.conf) \\
- command claude "\$@"
+ local _ov_conf="\${OPENVIKING_CLI_CONFIG_FILE:-\$HOME/.openviking/ovcli.conf}"
+ if [ -f "\$_ov_conf" ] && command -v jq >/dev/null 2>&1; then
+ local _ov_url _ov_key
+ _ov_url=\$(jq -r '.url // empty' "\$_ov_conf" 2>/dev/null)
+ _ov_key=\$(jq -r '.api_key // empty' "\$_ov_conf" 2>/dev/null)
+ OPENVIKING_URL="\${OPENVIKING_URL:-\$_ov_url}" \\
+ OPENVIKING_API_KEY="\${OPENVIKING_API_KEY:-\$_ov_key}" \\
+ command claude "\$@"
else
command claude "\$@"
fi
@@ -203,16 +209,23 @@ fi
heading '5. Plugin install'
if [ "$CLAUDE_AVAILABLE" -eq 1 ]; then
+ # Use --scope user so the plugin is active from any directory, not just $REPO_DIR.
+ # `local` scope binds enablement to $REPO_DIR's .claude/settings.local.json, which
+ # surfaces as "disabled" the moment the user `cd`s elsewhere and forces a manual
+ # `claude plugin enable` post-install.
info 'claude plugin marketplace add'
- ( cd "$REPO_DIR" && claude plugin marketplace add "$REPO_DIR/examples" --scope local ) || \
+ ( cd "$REPO_DIR" && claude plugin marketplace add "$REPO_DIR/examples" --scope user ) || \
warn 'marketplace add returned non-zero (likely already added) — continuing'
info 'claude plugin install'
- ( cd "$REPO_DIR" && claude plugin install claude-code-memory-plugin@openviking-plugins-local --scope local )
+ ( cd "$REPO_DIR" && claude plugin install claude-code-memory-plugin@openviking-plugins-local --scope user )
+ # Belt-and-suspenders: make sure it ends up enabled even if `install` left it
+ # in a disabled state (observed on some Claude Code versions).
+ claude plugin enable claude-code-memory-plugin@openviking-plugins-local --scope user >/dev/null 2>&1 || true
else
warn "Run these manually after installing Claude Code:"
warn " cd \"$REPO_DIR\""
- warn ' claude plugin marketplace add "$(pwd)/examples" --scope local'
- warn ' claude plugin install claude-code-memory-plugin@openviking-plugins-local --scope local'
+ warn ' claude plugin marketplace add "$(pwd)/examples" --scope user'
+ warn ' claude plugin install claude-code-memory-plugin@openviking-plugins-local --scope user'
fi
# ----- Done -----
diff --git a/openviking/server/mcp_endpoint.py b/openviking/server/mcp_endpoint.py
index 5dfc1cb24..4599576a7 100644
--- a/openviking/server/mcp_endpoint.py
+++ b/openviking/server/mcp_endpoint.py
@@ -242,17 +242,37 @@ async def store(messages: list[StoreMessage]) -> str:
# -- add_resource ----------------------------------------------------------
+_LOCAL_FILE_HINT = (
+ "MCP add_resource only accepts remote URLs (http(s)://, git@, ssh://, git://). "
+ "For local files or directories, use the `ov` CLI:\n"
+ " 1. Try first: ov add-resource <path>\n"
+ " (if `ov` is already on PATH, this is all you need)\n"
+ " 2. If `ov` is not installed, run:\n"
+ " curl -fsSL https://raw.githubusercontent.com/volcengine/OpenViking/main/crates/ov_cli/install.sh | bash\n"
+ " 3. Only if connecting to a remote / multi-tenant OpenViking server, "
+ "configure ~/.openviking/ovcli.conf:\n"
+ ' {"url": "https://your-host", "api_key": "your-key"}'
+)
+
+
@mcp.tool()
async def add_resource(path: str, description: str = "") -> str:
- """Add a resource (local file path or URL) to OpenViking. This is an asynchronous operation — the resource will be processed in the background."""
+ """Add a remote resource (HTTP/HTTPS URL or git URL) to OpenViking. Asynchronous — processed in the background. Local file paths are not supported here; use the `ov add-resource` CLI for local files."""
+ from openviking.server.local_input_guard import require_remote_resource_source
+
service = get_service()
ctx = _get_ctx()
+ try:
+ path = require_remote_resource_source(path)
+ except PermissionDeniedError:
+ return f"Error: {_LOCAL_FILE_HINT}"
try:
result = await service.resources.add_resource(
path=path,
ctx=ctx,
reason=description,
wait=False,
+ enforce_public_remote_targets=True,
)
root_uri = result.get("root_uri", "")
return (
diff --git a/tests/server/test_mcp_endpoint.py b/tests/server/test_mcp_endpoint.py
index 45a71feb6..dd72febcf 100644
--- a/tests/server/test_mcp_endpoint.py
+++ b/tests/server/test_mcp_endpoint.py
@@ -175,11 +175,17 @@ async def test_store_batch_messages(service):
# ---------------------------------------------------------------------------
-async def test_add_resource_nonexistent_path(service):
+async def test_add_resource_rejects_local_path_with_cli_hint(service):
result = await add_resource(path="/tmp/definitely_does_not_exist_xyz.md")
- assert (
- "error" in result.lower() or "not found" in result.lower() or "resource" in result.lower()
- )
+ assert "error" in result.lower()
+ assert "ov add-resource" in result
+ assert "ovcli.conf" in result
+
+
+async def test_add_resource_rejects_bare_filename_with_cli_hint(service):
+ result = await add_resource(path="some_local_file.md")
+ assert "error" in result.lower()
+ assert "ov add-resource" in result
# ---------------------------------------------------------------------------