Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
feat: add limit/offset to read mcp (#4817)
chenxiaobin-monkeya26d9f169935
diff --git a/openviking/server/mcp_endpoint.py b/openviking/server/mcp_endpoint.pyindex a6edcaa45..c790bb6c5 100644--- a/openviking/server/mcp_endpoint.py+++ b/openviking/server/mcp_endpoint.py@@ -498,8 +498,12 @@ def _mcp_media_download_hint(uri: str) -> str:@mcp.tool(structured_output=False)-async def read(uris: str | list[str]) -> str | list[ContentBlock]:- """Read one or more viking:// file URIs. Raster images and supported audio return native MCP content blocks. For directory listing, use the list tool instead."""+async def read(+ uris: str | list[str],+ offset: int = 0,+ limit: int = -1,+) -> str | list[ContentBlock]:+ """Read one or more viking:// file URIs. Text reads accept line-based offset/limit. Raster images and supported audio return native MCP content blocks. For directory listing, use the list tool instead."""import asyncioservice = get_service()@@ -596,7 +600,12 @@ async def read(uris: str | list[str]) -> str | list[ContentBlock]:if is_image:return _mcp_image_content(data, mime_type)return _mcp_audio_content(data, mime_type)- content = await service.fs.read_visible(resolved_uri, ctx=ctx)+ content = await service.fs.read_visible(+ resolved_uri,+ ctx=ctx,+ offset=offset,+ limit=limit,+ )return contentexcept OpenVikingError as exc:return str(exc)diff --git a/tests/server/test_mcp_endpoint.py b/tests/server/test_mcp_endpoint.pyindex 1dd8e7087..20977edf2 100644--- a/tests/server/test_mcp_endpoint.py+++ b/tests/server/test_mcp_endpoint.py@@ -622,6 +622,38 @@ async def test_read_delegates_to_visible_read(monkeypatch):read_visible.assert_awaited_once_with("viking://user/test_user/project/private.md",ctx=DEFAULT_CTX,+ offset=0,+ limit=-1,+ )+++async def test_read_passes_offset_limit_to_visible_read(monkeypatch):+ read_visible = AsyncMock(return_value="line 3\nline 4\n")+ monkeypatch.setattr(+ mcp_endpoint,+ "get_service",+ lambda: SimpleNamespace(fs=SimpleNamespace(read_visible=read_visible)),+ )+ uri = "viking://resources/notes.md"++ result = await mcp_endpoint.mcp.call_tool(+ "read",+ {+ "uris": uri,+ "offset": 2,+ "limit": 2,+ },+ )++ assert isinstance(result, list)+ assert len(result) == 1+ assert isinstance(result[0], TextContent)+ assert result[0].text == "line 3\nline 4\n"+ read_visible.assert_awaited_once_with(+ uri,+ ctx=DEFAULT_CTX,+ offset=2,+ limit=2,)@@ -892,7 +924,7 @@ async def test_read_svg_remains_text(monkeypatch):uri = "viking://resources/diagram.svg"assert await read(uri) == "<svg></svg>"- read_visible.assert_awaited_once_with(uri, ctx=DEFAULT_CTX)+ read_visible.assert_awaited_once_with(uri, ctx=DEFAULT_CTX, offset=0, limit=-1)read_file_bytes.assert_not_awaited()