mirror of
https://github.com/dnlbauer/cordra-mcp.git
synced 2026-09-10 21:55:30 +00:00
refactor(search): change default limit from None to 1
Change the default limit parameter for search_objects from None to 1 to optimize for single object searches. This makes the API more intuitive for common use cases where users want to find a specific object without specifying pagination parameters. Changes: - Update limit parameter type from `int | None = None` to `int = 1` - Remove conditional logic handling None values - Update documentation to reflect new default - Update all tests to expect new default behavior This improves usability for exploratory searches while maintaining full pagination functionality when larger limits are specified. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -37,7 +37,7 @@ Examples:
|
||||
|
||||
Pagination:
|
||||
- Results are paginated with 0-based page numbering
|
||||
- Use 'limit' to control page size (default: 20)
|
||||
- Use 'limit' to control page size (default: 1)
|
||||
- Use 'page_num' to specify which page to retrieve (default: 0)
|
||||
|
||||
Returns a JSON list of matching objects with their full metadata."""
|
||||
@@ -45,7 +45,7 @@ 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,
|
||||
limit: int = 1,
|
||||
page_num: int = 0,
|
||||
) -> str:
|
||||
"""Search for digital objects in the Cordra repository with pagination support.
|
||||
@@ -56,16 +56,14 @@ 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 page size - number of results per page (default: 20)
|
||||
limit: Page size - number of results per page (default: 1)
|
||||
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
|
||||
"""
|
||||
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, page_num=page_num)
|
||||
search_result = await cordra_client.find(query, object_type=type, page_size=limit, page_num=page_num)
|
||||
results = search_result["results"]
|
||||
return json.dumps(results, indent=2)
|
||||
|
||||
|
||||
@@ -311,7 +311,7 @@ class TestSearchObjects:
|
||||
assert parsed_result[1]["id"] == "people/jane-smith"
|
||||
|
||||
# Verify the client was called with correct parameters
|
||||
mock_client.find.assert_called_once_with("name:John", object_type=None, page_size=20, page_num=0)
|
||||
mock_client.find.assert_called_once_with("name:John", object_type=None, page_size=1, page_num=0)
|
||||
|
||||
@patch('cordra_mcp.server.cordra_client')
|
||||
async def test_search_objects_with_type_filter(self, mock_client):
|
||||
@@ -334,7 +334,7 @@ class TestSearchObjects:
|
||||
assert parsed_result[0]["type"] == "Person"
|
||||
|
||||
# Verify the client was called with type filter
|
||||
mock_client.find.assert_called_once_with("name:John", object_type="Person", page_size=20, page_num=0)
|
||||
mock_client.find.assert_called_once_with("name:John", object_type="Person", page_size=1, page_num=0)
|
||||
|
||||
@patch('cordra_mcp.server.cordra_client')
|
||||
async def test_search_objects_with_limit(self, mock_client):
|
||||
@@ -398,7 +398,7 @@ class TestSearchObjects:
|
||||
parsed_result = json.loads(result)
|
||||
assert parsed_result == []
|
||||
|
||||
mock_client.find.assert_called_once_with("nonexistent:data", object_type=None, page_size=20, page_num=0)
|
||||
mock_client.find.assert_called_once_with("nonexistent:data", object_type=None, page_size=1, page_num=0)
|
||||
|
||||
@patch('cordra_mcp.server.cordra_client')
|
||||
async def test_search_objects_client_error(self, mock_client):
|
||||
@@ -409,7 +409,7 @@ class TestSearchObjects:
|
||||
await search_objects("test:query")
|
||||
|
||||
assert "Search failed:" in str(exc_info.value)
|
||||
mock_client.find.assert_called_once_with("test:query", object_type=None, page_size=20, page_num=0)
|
||||
mock_client.find.assert_called_once_with("test:query", object_type=None, page_size=1, page_num=0)
|
||||
|
||||
@patch('cordra_mcp.server.cordra_client')
|
||||
async def test_search_objects_value_error(self, mock_client):
|
||||
@@ -420,7 +420,7 @@ class TestSearchObjects:
|
||||
await search_objects("invalid:query")
|
||||
|
||||
assert "Invalid search parameters:" in str(exc_info.value)
|
||||
mock_client.find.assert_called_once_with("invalid:query", object_type=None, page_size=20, page_num=0)
|
||||
mock_client.find.assert_called_once_with("invalid:query", object_type=None, page_size=1, page_num=0)
|
||||
|
||||
@patch('cordra_mcp.server.cordra_client')
|
||||
async def test_search_objects_json_formatting(self, mock_client):
|
||||
@@ -463,9 +463,9 @@ class TestSearchObjects:
|
||||
mock_client.find = AsyncMock(return_value=mock_search_result)
|
||||
|
||||
await search_objects("type:Document", page_num=1)
|
||||
|
||||
|
||||
# Verify the client was called with correct page number
|
||||
mock_client.find.assert_called_once_with("type:Document", object_type=None, page_size=20, page_num=1)
|
||||
mock_client.find.assert_called_once_with("type:Document", object_type=None, page_size=1, page_num=1)
|
||||
|
||||
@patch('cordra_mcp.server.cordra_client')
|
||||
async def test_search_objects_with_all_pagination_params(self, mock_client):
|
||||
|
||||
Reference in New Issue
Block a user