nothingworry's picture
Update the backend
e44e5dd
raw
history blame
981 Bytes
from __future__ import annotations
from typing import Mapping
from backend.mcp_server.common.database import list_all_documents
from backend.mcp_server.common.tenant import TenantContext
from backend.mcp_server.common.utils import ToolValidationError, tool_handler
@tool_handler("rag.list")
async def rag_list(context: TenantContext, payload: Mapping[str, object]) -> dict[str, object]:
"""
List stored RAG documents for the tenant with pagination.
"""
limit = payload.get("limit", 1000)
offset = payload.get("offset", 0)
try:
limit_value = max(1, min(int(limit), 5000))
except (TypeError, ValueError):
raise ToolValidationError("limit must be an integer between 1 and 5000")
try:
offset_value = max(0, int(offset))
except (TypeError, ValueError):
raise ToolValidationError("offset must be a non-negative integer")
return list_all_documents(context.tenant_id, limit=limit_value, offset=offset_value)