Skip to content

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

fix(mcp): default list to viking:// and flag line-ending mismatches in edit (#5344)

Zayn Jarvise6cb80e49872
diff --git a/openviking/server/mcp_endpoint.py b/openviking/server/mcp_endpoint.py
index 6c6041ca2..1f848b567 100644
--- a/openviking/server/mcp_endpoint.py
+++ b/openviking/server/mcp_endpoint.py
@@ -777,7 +777,7 @@ async def read(
@mcp.tool(name="list")
async def ls(
- uri: str,
+ uri: str = "viking://",
recursive: bool = False,
offset: int = 0,
limit: int | None = None,
@@ -787,7 +787,7 @@ async def ls(
"""List one sorted page under a viking:// directory URI.
Args:
- uri: Directory URI to list.
+ uri: Directory URI to list; defaults to "viking://" like tree and glob.
recursive: Whether to recursively list descendants.
offset: Number of visible entries to skip.
limit: Optional maximum number of entries.
@@ -1024,8 +1024,11 @@ async def edit(
raise NotFoundError(uri, "file") from exc
occurrences = current.count(old_string)
if occurrences == 0:
+ hint = ""
+ if current.replace("\r\n", "\n").count(old_string.replace("\r\n", "\n")):
+ hint = " old_string matches only after normalizing CRLF/LF line endings."
raise InvalidArgumentError(
- f"old_string not found in {uri}. "
+ f"old_string not found in {uri}.{hint} "
"Re-read the file with the read tool to get its current content."
)
if occurrences > 1 and not replace_all:
diff --git a/tests/server/test_mcp_endpoint.py b/tests/server/test_mcp_endpoint.py
index 45e76fce9..6ceec7df3 100644
--- a/tests/server/test_mcp_endpoint.py
+++ b/tests/server/test_mcp_endpoint.py
@@ -1257,6 +1257,10 @@ async def test_list_root(service):
assert isinstance(result, str)
+async def test_list_defaults_to_viking_root(service):
+ assert await list_tool() == await list_tool("viking://")
+
+
async def test_list_empty_dir(service):
ctx = DEFAULT_CTX
await service.viking_fs.mkdir(
@@ -2037,6 +2041,15 @@ async def test_edit_missing_old_string_fails(service):
await edit(uri=uri, old_string="zzz", new_string="x")
+async def test_edit_line_ending_mismatch_says_so(service):
+ uri = "viking://resources/test_edit_crlf.md"
+ await write(uri=uri, content="line 1\r\nline 2\r\n")
+ with pytest.raises(InvalidArgumentError, match="CRLF/LF"):
+ await edit(uri=uri, old_string="line 1\nline 2\n", new_string="x")
+ with pytest.raises(InvalidArgumentError, match=r"not found in \S+\. Re-read"):
+ await edit(uri=uri, old_string="zzz", new_string="x")
+
+
async def test_edit_empty_old_string_fails(service):
uri = "viking://resources/test_edit_empty.md"
await write(uri=uri, content="alpha\n")