feat: add pagination support to search_objects MCP tool

Add page_num parameter to the search_objects tool to enable pagination
control for users. This provides full pagination functionality while
maintaining backward compatibility.

Changes:
- Add page_num parameter with default value of 0 (0-based pagination)
- Update tool description to document pagination parameters
- Enhance docstring to explain page_num and clarify limit as page_size
- Add comprehensive tests for pagination scenarios
- All existing functionality remains unchanged

Users can now paginate through search results:
- search_objects("query") - first page, 20 results
- search_objects("query", limit=50) - first page, 50 results
- search_objects("query", page_num=1) - second page, 20 results
- search_objects("query", limit=10, page_num=5) - sixth page, 10 results

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Daniel Bauer
2025-07-05 12:32:43 +02:00
parent 56e1a85d5e
commit dec0b7702a
2 changed files with 53 additions and 10 deletions

View File

@@ -35,14 +35,20 @@ Examples:
- /author:smith - Find objects by author Smith
- /name:John AND type:Person - Complex queries
Pagination:
- Results are paginated with 0-based page numbering
- Use 'limit' to control page size (default: 20)
- Use 'page_num' to specify which page to retrieve (default: 0)
Returns a JSON list of matching objects with their full metadata."""
)
async def search_objects(
query: str,
type: str | None = None,
limit: int | None = None,
page_num: int = 0,
) -> str:
"""Search for digital objects in the Cordra repository.
"""Search for digital objects in the Cordra repository with pagination support.
Args:
query: The search query string (Lucene/Solr compatible). Examples:
@@ -50,7 +56,8 @@ async def search_objects(
- "/author:smith" - Find objects by author Smith
- "/name:John AND type:Person" - Complex queries
type: Optional filter by object type (e.g., "Person", "Document", "Project")
limit: Optional limit on number of results (default: config max_search_results)
limit: Optional page size - number of results per page (default: 20)
page_num: Page number to retrieve, 0-based (default: 0 for first page)
Returns:
JSON string containing list of matching objects with their full metadata
@@ -58,7 +65,7 @@ async def search_objects(
try:
# Use provided limit or default page size of 20
page_size = limit if limit is not None else 20
search_result = await cordra_client.find(query, object_type=type, page_size=page_size)
search_result = await cordra_client.find(query, object_type=type, page_size=page_size, page_num=page_num)
results = search_result["results"]
return json.dumps(results, indent=2)