mirror of
https://github.com/dnlbauer/cordra-mcp.git
synced 2026-09-10 21:55:30 +00:00
refactor: remove unused max_search_results config parameter
The max_search_results configuration parameter was only used in one location and added unnecessary complexity. Search operations now use a consistent default page size of 20, which aligns with the pagination implementation and provides better user experience. Changes: - Remove max_search_results from CordraConfig - Update search_objects to use default page size of 20 - Simplify tests by removing config mocking - Maintain backward compatibility through limit parameter 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -22,9 +22,6 @@ class CordraConfig(BaseSettings):
|
|||||||
password: str | None = Field(
|
password: str | None = Field(
|
||||||
default=None, description="Password for Cordra authentication"
|
default=None, description="Password for Cordra authentication"
|
||||||
)
|
)
|
||||||
max_search_results: int = Field(
|
|
||||||
default=1000, description="Maximum number of search results to return"
|
|
||||||
)
|
|
||||||
verify_ssl: bool = Field(
|
verify_ssl: bool = Field(
|
||||||
default=True, description="Whether to verify SSL certificates"
|
default=True, description="Whether to verify SSL certificates"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -56,8 +56,9 @@ async def search_objects(
|
|||||||
JSON string containing list of matching objects with their full metadata
|
JSON string containing list of matching objects with their full metadata
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
effective_limit = limit if limit is not None else config.max_search_results
|
# Use provided limit or default page size of 20
|
||||||
search_result = await cordra_client.find(query, object_type=type, page_size=effective_limit)
|
page_size = limit if limit is not None else 20
|
||||||
|
search_result = await cordra_client.find(query, object_type=type, page_size=page_size)
|
||||||
results = search_result["results"]
|
results = search_result["results"]
|
||||||
return json.dumps(results, indent=2)
|
return json.dumps(results, indent=2)
|
||||||
|
|
||||||
|
|||||||
@@ -413,6 +413,5 @@ class TestCordraConfig:
|
|||||||
assert config.base_url == "https://localhost:8443"
|
assert config.base_url == "https://localhost:8443"
|
||||||
assert config.username is None
|
assert config.username is None
|
||||||
assert config.password is None
|
assert config.password is None
|
||||||
assert config.max_search_results == 1000
|
|
||||||
assert config.verify_ssl is True
|
assert config.verify_ssl is True
|
||||||
assert config.timeout == 30
|
assert config.timeout == 30
|
||||||
|
|||||||
@@ -289,10 +289,8 @@ class TestSearchObjects:
|
|||||||
"""Test the search_objects tool."""
|
"""Test the search_objects tool."""
|
||||||
|
|
||||||
@patch('cordra_mcp.server.cordra_client')
|
@patch('cordra_mcp.server.cordra_client')
|
||||||
@patch('cordra_mcp.server.config')
|
async def test_search_objects_success(self, mock_client):
|
||||||
async def test_search_objects_success(self, mock_config, mock_client):
|
|
||||||
"""Test successful object search."""
|
"""Test successful object search."""
|
||||||
mock_config.max_search_results = 1000
|
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [
|
"results": [
|
||||||
{"id": "people/john-doe", "type": "Person", "content": {"name": "John Doe"}},
|
{"id": "people/john-doe", "type": "Person", "content": {"name": "John Doe"}},
|
||||||
@@ -313,13 +311,11 @@ class TestSearchObjects:
|
|||||||
assert parsed_result[1]["id"] == "people/jane-smith"
|
assert parsed_result[1]["id"] == "people/jane-smith"
|
||||||
|
|
||||||
# Verify the client was called with correct parameters
|
# Verify the client was called with correct parameters
|
||||||
mock_client.find.assert_called_once_with("name:John", object_type=None, page_size=1000)
|
mock_client.find.assert_called_once_with("name:John", object_type=None, page_size=20)
|
||||||
|
|
||||||
@patch('cordra_mcp.server.cordra_client')
|
@patch('cordra_mcp.server.cordra_client')
|
||||||
@patch('cordra_mcp.server.config')
|
async def test_search_objects_with_type_filter(self, mock_client):
|
||||||
async def test_search_objects_with_type_filter(self, mock_config, mock_client):
|
|
||||||
"""Test object search with type filter."""
|
"""Test object search with type filter."""
|
||||||
mock_config.max_search_results = 1000
|
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [
|
"results": [
|
||||||
{"id": "people/john-doe", "type": "Person", "content": {"name": "John Doe"}},
|
{"id": "people/john-doe", "type": "Person", "content": {"name": "John Doe"}},
|
||||||
@@ -338,13 +334,11 @@ class TestSearchObjects:
|
|||||||
assert parsed_result[0]["type"] == "Person"
|
assert parsed_result[0]["type"] == "Person"
|
||||||
|
|
||||||
# Verify the client was called with type filter
|
# Verify the client was called with type filter
|
||||||
mock_client.find.assert_called_once_with("name:John", object_type="Person", page_size=1000)
|
mock_client.find.assert_called_once_with("name:John", object_type="Person", page_size=20)
|
||||||
|
|
||||||
@patch('cordra_mcp.server.cordra_client')
|
@patch('cordra_mcp.server.cordra_client')
|
||||||
@patch('cordra_mcp.server.config')
|
async def test_search_objects_with_limit(self, mock_client):
|
||||||
async def test_search_objects_with_limit(self, mock_config, mock_client):
|
|
||||||
"""Test object search with custom limit."""
|
"""Test object search with custom limit."""
|
||||||
mock_config.max_search_results = 1000
|
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [
|
"results": [
|
||||||
{"id": "people/john-doe", "type": "Person", "content": {"name": "John Doe"}},
|
{"id": "people/john-doe", "type": "Person", "content": {"name": "John Doe"}},
|
||||||
@@ -365,10 +359,8 @@ class TestSearchObjects:
|
|||||||
mock_client.find.assert_called_once_with("name:John", object_type=None, page_size=50)
|
mock_client.find.assert_called_once_with("name:John", object_type=None, page_size=50)
|
||||||
|
|
||||||
@patch('cordra_mcp.server.cordra_client')
|
@patch('cordra_mcp.server.cordra_client')
|
||||||
@patch('cordra_mcp.server.config')
|
async def test_search_objects_with_all_parameters(self, mock_client):
|
||||||
async def test_search_objects_with_all_parameters(self, mock_config, mock_client):
|
|
||||||
"""Test object search with all parameters."""
|
"""Test object search with all parameters."""
|
||||||
mock_config.max_search_results = 1000
|
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [
|
"results": [
|
||||||
{"id": "documents/report-123", "type": "Document", "content": {"title": "Report"}},
|
{"id": "documents/report-123", "type": "Document", "content": {"title": "Report"}},
|
||||||
@@ -390,10 +382,8 @@ class TestSearchObjects:
|
|||||||
mock_client.find.assert_called_once_with("title:Report", object_type="Document", page_size=25)
|
mock_client.find.assert_called_once_with("title:Report", object_type="Document", page_size=25)
|
||||||
|
|
||||||
@patch('cordra_mcp.server.cordra_client')
|
@patch('cordra_mcp.server.cordra_client')
|
||||||
@patch('cordra_mcp.server.config')
|
async def test_search_objects_empty_results(self, mock_client):
|
||||||
async def test_search_objects_empty_results(self, mock_config, mock_client):
|
|
||||||
"""Test object search with no results."""
|
"""Test object search with no results."""
|
||||||
mock_config.max_search_results = 1000
|
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [],
|
"results": [],
|
||||||
"total_size": 0,
|
"total_size": 0,
|
||||||
@@ -408,39 +398,33 @@ class TestSearchObjects:
|
|||||||
parsed_result = json.loads(result)
|
parsed_result = json.loads(result)
|
||||||
assert parsed_result == []
|
assert parsed_result == []
|
||||||
|
|
||||||
mock_client.find.assert_called_once_with("nonexistent:data", object_type=None, page_size=1000)
|
mock_client.find.assert_called_once_with("nonexistent:data", object_type=None, page_size=20)
|
||||||
|
|
||||||
@patch('cordra_mcp.server.cordra_client')
|
@patch('cordra_mcp.server.cordra_client')
|
||||||
@patch('cordra_mcp.server.config')
|
async def test_search_objects_client_error(self, mock_client):
|
||||||
async def test_search_objects_client_error(self, mock_config, mock_client):
|
|
||||||
"""Test object search with client error."""
|
"""Test object search with client error."""
|
||||||
mock_config.max_search_results = 1000
|
|
||||||
mock_client.find = AsyncMock(side_effect=CordraClientError("Search failed"))
|
mock_client.find = AsyncMock(side_effect=CordraClientError("Search failed"))
|
||||||
|
|
||||||
with pytest.raises(RuntimeError) as exc_info:
|
with pytest.raises(RuntimeError) as exc_info:
|
||||||
await search_objects("test:query")
|
await search_objects("test:query")
|
||||||
|
|
||||||
assert "Search failed:" in str(exc_info.value)
|
assert "Search failed:" in str(exc_info.value)
|
||||||
mock_client.find.assert_called_once_with("test:query", object_type=None, page_size=1000)
|
mock_client.find.assert_called_once_with("test:query", object_type=None, page_size=20)
|
||||||
|
|
||||||
@patch('cordra_mcp.server.cordra_client')
|
@patch('cordra_mcp.server.cordra_client')
|
||||||
@patch('cordra_mcp.server.config')
|
async def test_search_objects_value_error(self, mock_client):
|
||||||
async def test_search_objects_value_error(self, mock_config, mock_client):
|
|
||||||
"""Test object search with value error."""
|
"""Test object search with value error."""
|
||||||
mock_config.max_search_results = 1000
|
|
||||||
mock_client.find = AsyncMock(side_effect=ValueError("Invalid query"))
|
mock_client.find = AsyncMock(side_effect=ValueError("Invalid query"))
|
||||||
|
|
||||||
with pytest.raises(RuntimeError) as exc_info:
|
with pytest.raises(RuntimeError) as exc_info:
|
||||||
await search_objects("invalid:query")
|
await search_objects("invalid:query")
|
||||||
|
|
||||||
assert "Invalid search parameters:" in str(exc_info.value)
|
assert "Invalid search parameters:" in str(exc_info.value)
|
||||||
mock_client.find.assert_called_once_with("invalid:query", object_type=None, page_size=1000)
|
mock_client.find.assert_called_once_with("invalid:query", object_type=None, page_size=20)
|
||||||
|
|
||||||
@patch('cordra_mcp.server.cordra_client')
|
@patch('cordra_mcp.server.cordra_client')
|
||||||
@patch('cordra_mcp.server.config')
|
async def test_search_objects_json_formatting(self, mock_client):
|
||||||
async def test_search_objects_json_formatting(self, mock_config, mock_client):
|
|
||||||
"""Test that search results are properly formatted as JSON."""
|
"""Test that search results are properly formatted as JSON."""
|
||||||
mock_config.max_search_results = 1000
|
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [
|
"results": [
|
||||||
{"id": "test/object", "type": "Test", "content": {"data": "value"}},
|
{"id": "test/object", "type": "Test", "content": {"data": "value"}},
|
||||||
|
|||||||
Reference in New Issue
Block a user